1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h" 4cb93a386Sopenharmony_ci// HASH=34479d5aa23ce9f5e334b0786c9edb22 5cb93a386Sopenharmony_ciREG_FIDDLE(Bitmap_tryAllocPixels, 256, 256, false, 3) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci SkBitmap bitmap; 8cb93a386Sopenharmony_ci SkImageInfo info = SkImageInfo::Make(64, 256, kGray_8_SkColorType, kOpaque_SkAlphaType); 9cb93a386Sopenharmony_ci if (bitmap.tryAllocPixels(info, 0)) { 10cb93a386Sopenharmony_ci SkCanvas offscreen(bitmap); 11cb93a386Sopenharmony_ci offscreen.scale(.5f, .5f); 12cb93a386Sopenharmony_ci for (int x : { 0, 64, 128, 192 } ) { 13cb93a386Sopenharmony_ci offscreen.drawImage(source.asImage(), -x, 0); 14cb93a386Sopenharmony_ci canvas->drawImage(bitmap.asImage(), x, 0); 15cb93a386Sopenharmony_ci } 16cb93a386Sopenharmony_ci } 17cb93a386Sopenharmony_ci} 18cb93a386Sopenharmony_ci} // END FIDDLE 19