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 #include "include/core/SkBitmap.h"
8 #include "include/core/SkCanvas.h"
9 #include "include/core/SkShader.h"
10 #include "include/core/SkTileMode.h"
11 #include "tools/viewer/Slide.h"
12
make_bitmap(SkBitmap * bm)13 static void make_bitmap(SkBitmap* bm) {
14 const int W = 100;
15 const int H = 100;
16 bm->allocN32Pixels(W, H);
17
18 SkPaint paint;
19 SkCanvas canvas(*bm);
20 canvas.drawColor(SK_ColorWHITE);
21
22 const SkColor colors[] = {
23 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
24 };
25
26 for (int ix = 0; ix < W; ix += 1) {
27 SkScalar x = SkIntToScalar(ix) + SK_ScalarHalf;
28 paint.setColor(colors[ix & 3]);
29 canvas.drawLine(x, 0, x, SkIntToScalar(H - 1), paint);
30 }
31 paint.setColor(SK_ColorGRAY);
32 canvas.drawLine(0, 0, SkIntToScalar(W), 0, paint);
33 }
34
make_paint(SkPaint * paint,SkTileMode tm)35 static void make_paint(SkPaint* paint, SkTileMode tm) {
36 SkBitmap bm;
37 make_bitmap(&bm);
38
39 paint->setShader(bm.makeShader(tm, tm, SkSamplingOptions()));
40 }
41
42 class RepeatTileSlide : public Slide {
43 public:
RepeatTileSlide()44 RepeatTileSlide() { fName = "RepeatTile"; }
45
draw(SkCanvas * canvas)46 void draw(SkCanvas* canvas) override {
47 canvas->clear(SK_ColorGRAY);
48 SkPaint paint;
49 make_paint(&paint, SkTileMode::kRepeat);
50
51 // canvas->scale(SK_Scalar1*2, SK_Scalar1);
52 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
53 canvas->drawPaint(paint);
54 }
55
56 };
57
58 //////////////////////////////////////////////////////////////////////////////
59
60 DEF_SLIDE( return new RepeatTileSlide(); )
61