2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-07-18 21:19:31 +00:00
|
|
|
#include "gm.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
static SkBitmap make_bitmap() {
|
|
|
|
SkBitmap bm;
|
|
|
|
|
|
|
|
SkColorTable* ctable = new SkColorTable(1);
|
|
|
|
SkPMColor* c = ctable->lockColors();
|
|
|
|
c[0] = SkPackARGB32(0x80, 0x80, 0, 0);
|
|
|
|
ctable->unlockColors(true);
|
|
|
|
|
|
|
|
bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
|
|
|
|
bm.allocPixels(ctable);
|
|
|
|
ctable->unref();
|
|
|
|
|
|
|
|
bm.lockPixels();
|
|
|
|
*bm.getAddr8(0, 0) = 0;
|
|
|
|
bm.unlockPixels();
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TinyBitmapGM : public GM {
|
|
|
|
public:
|
|
|
|
TinyBitmapGM() {
|
2011-10-31 14:18:20 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2011-07-18 21:19:31 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-18 21:19:31 +00:00
|
|
|
protected:
|
|
|
|
SkString onShortName() {
|
|
|
|
return SkString("tinybitmap");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() { return make_isize(100, 100); }
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2012-11-27 15:15:58 +00:00
|
|
|
SkBitmap bm = make_bitmap();
|
2012-08-23 18:19:56 +00:00
|
|
|
SkShader* s =
|
2012-11-27 15:15:58 +00:00
|
|
|
SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
|
2011-07-18 21:19:31 +00:00
|
|
|
SkShader::kMirror_TileMode);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAlpha(0x80);
|
|
|
|
paint.setShader(s)->unref();
|
|
|
|
canvas->drawPaint(paint);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-07-18 21:19:31 +00:00
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new TinyBitmapGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|