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() {
|
2013-10-10 14:44:56 +00:00
|
|
|
const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
|
|
|
|
SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
|
2013-10-09 16:49:45 +00:00
|
|
|
|
2013-10-10 14:44:56 +00:00
|
|
|
SkBitmap bm;
|
2014-02-17 21:21:46 +00:00
|
|
|
bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, ctable);
|
2011-07-18 21:19:31 +00:00
|
|
|
ctable->unref();
|
|
|
|
|
|
|
|
bm.lockPixels();
|
|
|
|
*bm.getAddr8(0, 0) = 0;
|
|
|
|
bm.unlockPixels();
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TinyBitmapGM : public GM {
|
|
|
|
public:
|
|
|
|
TinyBitmapGM() {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(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");
|
|
|
|
}
|
|
|
|
|
2014-06-10 06:59:03 +00:00
|
|
|
virtual SkISize onISize() { return SkISize::Make(100, 100); }
|
2011-07-18 21:19:31 +00:00
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2012-11-27 15:15:58 +00:00
|
|
|
SkBitmap bm = make_bitmap();
|
2011-07-18 21:19:31 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAlpha(0x80);
|
2016-03-13 21:13:58 +00:00
|
|
|
paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
|
|
|
|
SkShader::kMirror_TileMode));
|
2011-07-18 21:19:31 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|