Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Bitmap_allocN32Pixels.cpp
Go to the documentation of this file.
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.
4
5#include <climits>
6#include <random>
7
8REG_FIDDLE(Bitmap_allocN32Pixels, 256, 256, false, 0) {
9void draw(SkCanvas* canvas) {
11 bitmap.allocN32Pixels(64, 64);
12 bitmap.eraseColor(SK_ColorTRANSPARENT);
13 std::default_random_engine rng;
14 const auto randUint = [&rng](uint32_t min, uint32_t max) -> uint32_t {
15 return std::uniform_int_distribution<uint32_t>(min, max)(rng);
16 };
17
18 for (int y = 0; y < 256; y += 64) {
19 for (int x = 0; x < 256; x += 64) {
20 SkColor color = randUint(0, UINT_MAX);
21 uint32_t w = randUint(4, 32);
22 uint32_t cx = randUint(0, 64 - w);
23 uint32_t h = randUint(4, 32);
24 uint32_t cy = randUint(0, 64 - h);
25 bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h));
26 canvas->drawImage(bitmap.asImage(), x, y);
27 }
28 }
29}
30} // END FIDDLE
SkColor4f color
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
double y
double x
SkScalar w
SkScalar h
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104