blob: 90453a52246a2e668208a5898f25452b8b829e6c [file] [log] [blame]
mtklein4afe21e2015-04-17 06:32:13 -07001/*
2 * Copyright 2015 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 "gm.h"
9
10DEF_SIMPLE_GM(blend, canvas, 300, 100) {
11 SkPaint p;
12
13 // All three of these blocks should be the same color.
14 canvas->save();
15 canvas->scale(100,100);
16
17 p.setColor(SK_ColorRED);
18 canvas->drawRect(SkRect::MakeXYWH(0,0,1,1), p);
19 p.setColor(0xFC008000);
20 canvas->drawRect(SkRect::MakeXYWH(0,0,1,1), p);
21
22 p.setColor(SK_ColorRED);
23 canvas->drawRect(SkRect::MakeXYWH(1,0,1,1), p);
24 canvas->saveLayer(NULL, NULL);
25 p.setColor(0xFC008000);
26 canvas->drawRect(SkRect::MakeXYWH(1,0,1,1), p);
27 canvas->restore();
28
29 p.setColor(SK_ColorRED);
30 canvas->drawRect(SkRect::MakeXYWH(2,0,1,1), p);
31 canvas->saveLayerAlpha(NULL, 0xFC);
32 p.setColor(0xFF008000);
33 canvas->drawRect(SkRect::MakeXYWH(2,0,1,1), p);
34 canvas->restore();
35 canvas->restore();
36
37 // Print out the colors in each block (if we're looking at 8888 raster).
38 if (canvas->imageInfo().colorType() == kN32_SkColorType) {
39 if (const SkPMColor* px = (const SkPMColor*)canvas->peekPixels(NULL, NULL)) {
40 p.setColor(SK_ColorWHITE);
41 for (int i = 0; i < 3; i++) {
42 SkPMColor c = px[i * 100];
43 SkString text = SkStringPrintf("0x%08x", c);
44 canvas->drawText(text.c_str(), text.size(), i * 100.0f + 20.0f, 50.0f, p);
45 }
46 }
47 }
48}