1 // Copyright 2020 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(gpu8888diff, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     canvas->scale(16, 16);
7     SkBitmap bitmap;
8     SkImageInfo imageInfo =
9             SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
10     bitmap.allocPixels(imageInfo);
11     SkCanvas offscreen(bitmap);
12     offscreen.clear(SK_ColorGREEN);
13     canvas->drawImage(bitmap.asImage(), 0, 0);
14     offscreen.clear(SK_ColorGRAY);
15     canvas->drawImage(bitmap.asImage(), 2, 2);
16     auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t {
17         return (a << 24) | (b << 16) | (g << 8) | (r << 0);
18     };
19     uint32_t red8888[] = {pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0),
20                           pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0)};
21     uint32_t blue8888[] = {pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb),
22                            pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055)};
23     SkPixmap redPixmap(imageInfo, &red8888, 8);
24     if (bitmap.writePixels(redPixmap, 0, 0)) {
25         canvas->drawImage(bitmap.asImage(), 4, 4);
26     }
27     SkPixmap bluePixmap(imageInfo, &blue8888, 8);
28     if (bitmap.writePixels(bluePixmap, 0, 0)) {
29         canvas->drawImage(bitmap.asImage(), 6, 6);
30     }
31 }
32 }  // END FIDDLE
33