1 // Copyright 2019 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 // HASH=720e4c053fae9e929ab6518b47e49370
5 REG_FIDDLE(Bitmap_tryAllocPixels_3, 256, 50, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7     uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 };
8     SkBitmap bitmap;
9     bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5);
10     canvas->scale(10, 50);
11     canvas->drawImage(bitmap.asImage(), 0, 0);
12     if (bitmap.tryAllocPixels()) {
13         bitmap.eraseColor(SK_ColorBLACK);
14         canvas->drawImage(bitmap.asImage(), 8, 0);
15         bitmap.setPixels(set1);
16         canvas->drawImage(bitmap.asImage(), 16, 0);
17     }
18 }
19 }  // END FIDDLE
20