blob: 499a04786a3a7cbf6324b5a3281b613df616a169 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkBitmap.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040011#include "include/core/SkColor.h"
12#include "include/core/SkColorFilter.h"
13#include "include/core/SkImageInfo.h"
14#include "include/core/SkPaint.h"
15#include "include/core/SkRefCnt.h"
16#include "include/core/SkSize.h"
17#include "include/core/SkString.h"
18#include "include/core/SkTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "include/effects/SkOverdrawColorFilter.h"
Matt Sarett030cbd52016-11-22 15:48:50 -050020
21static inline void set_bitmap(SkBitmap* bitmap, uint8_t alpha) {
22 for (int y = 0; y < bitmap->height(); y++) {
23 for (int x = 0; x < bitmap->width(); x++) {
24 uint8_t* addr = bitmap->getAddr8(x, y);
25 *addr = alpha;
26 }
27 }
28
29 bitmap->notifyPixelsChanged();
30}
31
32class OverdrawColorFilter : public skiagm::GM {
Hal Canarybd865e22019-07-18 11:51:19 -040033 SkString onShortName() override { return SkString("overdrawcolorfilter"); }
Matt Sarett030cbd52016-11-22 15:48:50 -050034
Hal Canarybd865e22019-07-18 11:51:19 -040035 SkISize onISize() override { return {200, 400}; }
Matt Sarett030cbd52016-11-22 15:48:50 -050036
37 void onDraw(SkCanvas* canvas) override {
38 static const SkPMColor colors[SkOverdrawColorFilter::kNumColors] = {
39 0x80800000, 0x80008000, 0x80000080, 0x80808000, 0x80008080, 0x80800080,
40 };
41
42 SkPaint paint;
43 sk_sp<SkColorFilter> colorFilter = SkOverdrawColorFilter::Make(colors);
44 paint.setColorFilter(colorFilter);
45
46 SkImageInfo info = SkImageInfo::MakeA8(100, 100);
47 SkBitmap bitmap;
48 bitmap.allocPixels(info);
49 set_bitmap(&bitmap, 0);
50 canvas->drawBitmap(bitmap, 0, 0, &paint);
51 set_bitmap(&bitmap, 1);
52 canvas->drawBitmap(bitmap, 0, 100, &paint);
53 set_bitmap(&bitmap, 2);
54 canvas->drawBitmap(bitmap, 0, 200, &paint);
55 set_bitmap(&bitmap, 3);
56 canvas->drawBitmap(bitmap, 0, 300, &paint);
57 set_bitmap(&bitmap, 4);
58 canvas->drawBitmap(bitmap, 100, 0, &paint);
59 set_bitmap(&bitmap, 5);
60 canvas->drawBitmap(bitmap, 100, 100, &paint);
61 set_bitmap(&bitmap, 6);
62 canvas->drawBitmap(bitmap, 100, 200, &paint);
63 }
Matt Sarett030cbd52016-11-22 15:48:50 -050064};
65
66DEF_GM(return new OverdrawColorFilter;)