skia2/gm/tinybitmap.cpp
Mike Klein 33d2055e59 GM: some header cleanup
gm.h includes sk_tool_utils.h but does not use it.

The bulk of this CL makes each gm that uses sk_tool_utils include it.

sk_tool_utils.h also provided SkRandom and SkTDArray,
so a couple GMs add those headers too.

Change-Id: Ieb2a7c542f0ca89c3223f744fc11b0ff37af36c1
Reviewed-on: https://skia-review.googlesource.com/10014
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Herb Derby <herb@google.com>
2017-03-22 18:11:49 +00:00

64 lines
1.6 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "sk_tool_utils.h"
#include "SkColorPriv.h"
#include "SkShader.h"
#include "SkCanvas.h"
#include "SkUtils.h"
namespace skiagm {
static SkBitmap make_bitmap() {
const SkPMColor c[] = { SkPackARGB32(0x80, 0x80, 0, 0) };
SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
SkBitmap bm;
bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
kPremul_SkAlphaType),
nullptr, ctable);
ctable->unref();
bm.lockPixels();
*bm.getAddr8(0, 0) = 0;
bm.unlockPixels();
return bm;
}
class TinyBitmapGM : public GM {
public:
TinyBitmapGM() {
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
}
protected:
SkString onShortName() {
return SkString("tinybitmap");
}
virtual SkISize onISize() { return SkISize::Make(100, 100); }
virtual void onDraw(SkCanvas* canvas) {
SkBitmap bm = make_bitmap();
SkPaint paint;
paint.setAlpha(0x80);
paint.setShader(SkShader::MakeBitmapShader(bm, SkShader::kRepeat_TileMode,
SkShader::kMirror_TileMode));
canvas->drawPaint(paint);
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new TinyBitmapGM; }
static GMRegistry reg(MyFactory);
}