Herb Derby | 2273c90 | 2019-04-03 14:04:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkColorFilter.h" |
| 12 | #include "include/core/SkFont.h" |
| 13 | #include "include/core/SkFontTypes.h" |
| 14 | #include "include/core/SkImage.h" |
| 15 | #include "include/core/SkImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/core/SkOverdrawCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 17 | #include "include/core/SkPaint.h" |
| 18 | #include "include/core/SkRect.h" |
| 19 | #include "include/core/SkRefCnt.h" |
| 20 | #include "include/core/SkSurface.h" |
| 21 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #include "include/effects/SkOverdrawColorFilter.h" |
Herb Derby | 2273c90 | 2019-04-03 14:04:08 -0400 | [diff] [blame] | 23 | |
| 24 | #define WIDTH 500 |
| 25 | #define HEIGHT 500 |
| 26 | |
Mike Reed | 2c5ee18 | 2020-02-15 09:56:07 -0500 | [diff] [blame] | 27 | static const SkColor kOverdrawColors[6] = { |
| 28 | 0x00000000, 0x5fff0000, 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000, |
Herb Derby | 2273c90 | 2019-04-03 14:04:08 -0400 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | |
| 32 | DEF_SIMPLE_GM_BG(overdraw_canvas, canvas, WIDTH, HEIGHT, SK_ColorWHITE) { |
| 33 | // Set up the overdraw canvas. |
| 34 | SkImageInfo offscreenInfo = SkImageInfo::MakeA8(WIDTH, HEIGHT); |
| 35 | sk_sp<SkSurface> offscreen = SkSurface::MakeRaster(offscreenInfo); |
| 36 | auto c = offscreen->getCanvas(); |
| 37 | |
| 38 | SkOverdrawCanvas overdrawCanvas(c); |
| 39 | |
| 40 | overdrawCanvas.drawRect(SkRect::MakeLTRB(10, 10, 200, 200), SkPaint()); |
| 41 | overdrawCanvas.drawRect(SkRect::MakeLTRB(20, 20, 190, 190), SkPaint()); |
| 42 | overdrawCanvas.drawRect(SkRect::MakeLTRB(30, 30, 180, 180), SkPaint()); |
| 43 | overdrawCanvas.drawRect(SkRect::MakeLTRB(40, 40, 170, 170), SkPaint()); |
| 44 | overdrawCanvas.drawRect(SkRect::MakeLTRB(50, 50, 160, 160), SkPaint()); |
| 45 | overdrawCanvas.drawRect(SkRect::MakeLTRB(60, 60, 150, 150), SkPaint()); |
| 46 | |
| 47 | char text[] = "Ae_p"; |
| 48 | overdrawCanvas.drawSimpleText(text, 4, SkTextEncoding::kUTF8, 300, 300, SkFont(), SkPaint()); |
| 49 | |
| 50 | sk_sp<SkImage> counts = offscreen->makeImageSnapshot(); |
| 51 | |
| 52 | // Draw overdraw colors to the canvas. The color filter will convert counts to colors. |
| 53 | SkPaint paint; |
Mike Reed | 2c5ee18 | 2020-02-15 09:56:07 -0500 | [diff] [blame] | 54 | paint.setColorFilter(SkOverdrawColorFilter::MakeWithSkColors(kOverdrawColors)); |
Mike Reed | 8d29ab6 | 2021-01-23 18:10:39 -0500 | [diff] [blame] | 55 | canvas->drawImage(counts.get(), 0.0f, 0.0f, SkSamplingOptions(), &paint); |
Herb Derby | 2273c90 | 2019-04-03 14:04:08 -0400 | [diff] [blame] | 56 | canvas->drawString("This is some text:", 180, 300, SkFont(), SkPaint()); |
| 57 | } |
| 58 | |