blob: 2eba2280450ccba9968cb3a011d1c95a9e059b32 [file] [log] [blame]
Matt Sarett030cbd52016-11-22 15:48:50 -05001/*
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.h"
9#include "SkCanvas.h"
10#include "SkOverdrawColorFilter.h"
11
12static inline void set_bitmap(SkBitmap* bitmap, uint8_t alpha) {
13 for (int y = 0; y < bitmap->height(); y++) {
14 for (int x = 0; x < bitmap->width(); x++) {
15 uint8_t* addr = bitmap->getAddr8(x, y);
16 *addr = alpha;
17 }
18 }
19
20 bitmap->notifyPixelsChanged();
21}
22
23class OverdrawColorFilter : public skiagm::GM {
24public:
25 OverdrawColorFilter() {}
26
27protected:
28 virtual SkString onShortName() override {
29 return SkString("overdrawcolorfilter");;
30 }
31
32 virtual SkISize onISize() override {
33 return SkISize::Make(200, 400);
34 }
35
36 void onDraw(SkCanvas* canvas) override {
37 static const SkPMColor colors[SkOverdrawColorFilter::kNumColors] = {
38 0x80800000, 0x80008000, 0x80000080, 0x80808000, 0x80008080, 0x80800080,
39 };
40
41 SkPaint paint;
42 sk_sp<SkColorFilter> colorFilter = SkOverdrawColorFilter::Make(colors);
43 paint.setColorFilter(colorFilter);
44
45 SkImageInfo info = SkImageInfo::MakeA8(100, 100);
46 SkBitmap bitmap;
47 bitmap.allocPixels(info);
48 set_bitmap(&bitmap, 0);
49 canvas->drawBitmap(bitmap, 0, 0, &paint);
50 set_bitmap(&bitmap, 1);
51 canvas->drawBitmap(bitmap, 0, 100, &paint);
52 set_bitmap(&bitmap, 2);
53 canvas->drawBitmap(bitmap, 0, 200, &paint);
54 set_bitmap(&bitmap, 3);
55 canvas->drawBitmap(bitmap, 0, 300, &paint);
56 set_bitmap(&bitmap, 4);
57 canvas->drawBitmap(bitmap, 100, 0, &paint);
58 set_bitmap(&bitmap, 5);
59 canvas->drawBitmap(bitmap, 100, 100, &paint);
60 set_bitmap(&bitmap, 6);
61 canvas->drawBitmap(bitmap, 100, 200, &paint);
62 }
63
64private:
65 typedef GM INHERITED;
66};
67
68DEF_GM(return new OverdrawColorFilter;)