blob: 0f7a5b4812d76925bf258ae3adc2fe9a97cef0a7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Ben Wagner7fde8e12019-05-01 17:28:53 -04007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBitmap.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
11#include "include/core/SkColorPriv.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040012#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkShader.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkSize.h"
15#include "include/core/SkString.h"
16#include "include/core/SkTileMode.h"
bsalomon@google.com1936f262011-07-18 21:19:31 +000017
18namespace skiagm {
19
20static SkBitmap make_bitmap() {
21 SkBitmap bm;
Mike Reed304a07c2017-07-12 15:10:28 -040022 bm.allocN32Pixels(1, 1);
23 *bm.getAddr32(0, 0) = SkPackARGB32(0x80, 0x80, 0, 0);
bsalomon@google.com1936f262011-07-18 21:19:31 +000024 return bm;
25}
26
27class TinyBitmapGM : public GM {
bsalomon@google.com1936f262011-07-18 21:19:31 +000028public:
29 TinyBitmapGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040030 this->setBGColor(0xFFDDDDDD);
bsalomon@google.com1936f262011-07-18 21:19:31 +000031 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000032
bsalomon@google.com1936f262011-07-18 21:19:31 +000033protected:
34 SkString onShortName() {
35 return SkString("tinybitmap");
36 }
37
tfarinaf5393182014-06-09 23:59:03 -070038 virtual SkISize onISize() { return SkISize::Make(100, 100); }
bsalomon@google.com1936f262011-07-18 21:19:31 +000039
40 virtual void onDraw(SkCanvas* canvas) {
reed@google.com7775d662012-11-27 15:15:58 +000041 SkBitmap bm = make_bitmap();
bsalomon@google.com1936f262011-07-18 21:19:31 +000042 SkPaint paint;
Mike Reed9407e242019-02-15 16:13:57 -050043 paint.setAlphaf(0.5f);
Mike Reed50acf8f2019-04-08 13:20:23 -040044 paint.setShader(bm.makeShader(SkTileMode::kRepeat, SkTileMode::kMirror));
bsalomon@google.com1936f262011-07-18 21:19:31 +000045 canvas->drawPaint(paint);
46 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000047
bsalomon@google.com1936f262011-07-18 21:19:31 +000048private:
49 typedef GM INHERITED;
50};
51
52//////////////////////////////////////////////////////////////////////////////
53
Hal Canarye964c182019-01-23 10:22:01 -050054DEF_GM( return new TinyBitmapGM; )
bsalomon@google.com1936f262011-07-18 21:19:31 +000055
56}