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=c717491f9251604724c9cbde7088ec20 5cb93a386Sopenharmony_ciREG_FIDDLE(Bitmap_allocN32Pixels, 256, 256, false, 0) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci SkRandom random; 8cb93a386Sopenharmony_ci SkBitmap bitmap; 9cb93a386Sopenharmony_ci bitmap.allocN32Pixels(64, 64); 10cb93a386Sopenharmony_ci bitmap.eraseColor(SK_ColorTRANSPARENT); 11cb93a386Sopenharmony_ci for (int y = 0; y < 256; y += 64) { 12cb93a386Sopenharmony_ci for (int x = 0; x < 256; x += 64) { 13cb93a386Sopenharmony_ci SkColor color = random.nextU(); 14cb93a386Sopenharmony_ci uint32_t w = random.nextRangeU(4, 32); 15cb93a386Sopenharmony_ci uint32_t cx = random.nextRangeU(0, 64 - w); 16cb93a386Sopenharmony_ci uint32_t h = random.nextRangeU(4, 32); 17cb93a386Sopenharmony_ci uint32_t cy = random.nextRangeU(0, 64 - h); 18cb93a386Sopenharmony_ci bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h)); 19cb93a386Sopenharmony_ci canvas->drawImage(bitmap.asImage(), x, y); 20cb93a386Sopenharmony_ci } 21cb93a386Sopenharmony_ci } 22cb93a386Sopenharmony_ci} 23cb93a386Sopenharmony_ci} // END FIDDLE 24