Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
overdrawcolorfilter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
17#include "include/core/SkSize.h"
21
22static inline void set_bitmap(SkBitmap* bitmap, uint8_t alpha) {
23 for (int y = 0; y < bitmap->height(); y++) {
24 for (int x = 0; x < bitmap->width(); x++) {
25 uint8_t* addr = bitmap->getAddr8(x, y);
26 *addr = alpha;
27 }
28 }
29
30 bitmap->notifyPixelsChanged();
31}
32
34 SkString getName() const override { return SkString{"overdrawcolorfilter"}; }
35
36 SkISize getISize() override { return {200, 400}; }
37
38 void onDraw(SkCanvas* canvas) override {
39 static const SkColor colors[SkOverdrawColorFilter::kNumColors] = {
40 0x80FF0000, 0x8000FF00, 0x800000FF, 0x80FFFF00, 0x8000FFFF, 0x80FF00FF,
41 };
42
44 paint.setColorFilter(SkOverdrawColorFilter::MakeWithSkColors(colors));
45 SkSamplingOptions sampling;
46
49 bitmap.allocPixels(info);
50 set_bitmap(&bitmap, 0);
51 canvas->drawImage(bitmap.asImage(), 0, 0, sampling, &paint);
52 set_bitmap(&bitmap, 1);
53 canvas->drawImage(bitmap.asImage(), 0, 100, sampling, &paint);
54 set_bitmap(&bitmap, 2);
55 canvas->drawImage(bitmap.asImage(), 0, 200, sampling, &paint);
56 set_bitmap(&bitmap, 3);
57 canvas->drawImage(bitmap.asImage(), 0, 300, sampling, &paint);
58 set_bitmap(&bitmap, 4);
59 canvas->drawImage(bitmap.asImage(), 100, 0, sampling, &paint);
60 set_bitmap(&bitmap, 5);
61 canvas->drawImage(bitmap.asImage(), 100, 100, sampling, &paint);
62 set_bitmap(&bitmap, 6);
63 canvas->drawImage(bitmap.asImage(), 100, 200, sampling, &paint);
64 }
65};
66
67DEF_GM(return new OverdrawColorFilter;)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
uint32_t SkColor
Definition SkColor.h:37
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
static sk_sp< SkColorFilter > MakeWithSkColors(const SkColor[kNumColors])
static constexpr int kNumColors
const Paint & paint
#define DEF_GM(CODE)
Definition gm.h:40
double y
double x
static void set_bitmap(SkBitmap *bitmap, uint8_t alpha)
void onDraw(SkCanvas *canvas) override
SkISize getISize() override
SkString getName() const override
static SkImageInfo MakeA8(int width, int height)