Don't pass uniform arrays in GrGLNonlinearColorSpaceXformEffect
[platform/upstream/libSkiaSharp.git] / samplecode / SampleTinyBitmap.cpp
1 /*
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  */
7
8 #include "SampleCode.h"
9 #include "SkColorPriv.h"
10 #include "SkShader.h"
11 #include "SkView.h"
12 #include "SkCanvas.h"
13 #include "SkUtils.h"
14
15 static SkBitmap make_bitmap() {
16     const int N = 1;
17
18     SkPMColor c[N];
19     for (int i = 0; i < N; i++) {
20         c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
21     }
22
23     SkBitmap bm;
24     bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
25                                      kPremul_SkAlphaType),
26                    SkColorTable::Make(c, N));
27
28     for (int y = 0; y < bm.height(); y++) {
29         uint8_t* p = bm.getAddr8(0, y);
30         for (int x = 0; x < bm.width(); x++) {
31             p[x] = 0;
32         }
33     }
34     return bm;
35 }
36
37 class TinyBitmapView : public SampleView {
38     SkBitmap    fBM;
39 public:
40     TinyBitmapView() {
41         fBM = make_bitmap();
42         this->setBGColor(0xFFDDDDDD);
43     }
44
45 protected:
46     bool onQuery(SkEvent* evt) override {
47         if (SampleCode::TitleQ(*evt)) {
48             SampleCode::TitleR(evt, "TinyBitmap");
49             return true;
50         }
51         return this->INHERITED::onQuery(evt);
52     }
53
54     static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
55         bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
56     }
57
58     void onDrawContent(SkCanvas* canvas) override {
59         SkPaint paint;
60         paint.setShader(SkShader::MakeBitmapShader(fBM, SkShader::kRepeat_TileMode,
61                                                    SkShader::kMirror_TileMode));
62         canvas->drawPaint(paint);
63     }
64
65 private:
66     typedef SkView INHERITED;
67 };
68
69 //////////////////////////////////////////////////////////////////////////////
70
71 static SkView* MyFactory() { return new TinyBitmapView; }
72 static SkViewRegister reg(MyFactory);