blob: e953f159e8a6edff295d3fcdf10416afd85d9501 [file] [log] [blame]
Herb Derby2273c902019-04-03 14:04:08 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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 Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/core/SkOverdrawCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040017#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 Kleinc0bd9f92019-04-23 12:05:21 -050022#include "include/effects/SkOverdrawColorFilter.h"
Herb Derby2273c902019-04-03 14:04:08 -040023
24#define WIDTH 500
25#define HEIGHT 500
26
27
28static const uint32_t kOverdrawColors[6] = {
29 0x00000000, 0x5f00005f, 0x2f2f0000, 0x2f002f00, 0x3f00003f, 0x7f00007f,
30};
31
32
33DEF_SIMPLE_GM_BG(overdraw_canvas, canvas, WIDTH, HEIGHT, SK_ColorWHITE) {
34 // Set up the overdraw canvas.
35 SkImageInfo offscreenInfo = SkImageInfo::MakeA8(WIDTH, HEIGHT);
36 sk_sp<SkSurface> offscreen = SkSurface::MakeRaster(offscreenInfo);
37 auto c = offscreen->getCanvas();
38
39 SkOverdrawCanvas overdrawCanvas(c);
40
41 overdrawCanvas.drawRect(SkRect::MakeLTRB(10, 10, 200, 200), SkPaint());
42 overdrawCanvas.drawRect(SkRect::MakeLTRB(20, 20, 190, 190), SkPaint());
43 overdrawCanvas.drawRect(SkRect::MakeLTRB(30, 30, 180, 180), SkPaint());
44 overdrawCanvas.drawRect(SkRect::MakeLTRB(40, 40, 170, 170), SkPaint());
45 overdrawCanvas.drawRect(SkRect::MakeLTRB(50, 50, 160, 160), SkPaint());
46 overdrawCanvas.drawRect(SkRect::MakeLTRB(60, 60, 150, 150), SkPaint());
47
48 char text[] = "Ae_p";
49 overdrawCanvas.drawSimpleText(text, 4, SkTextEncoding::kUTF8, 300, 300, SkFont(), SkPaint());
50
51 sk_sp<SkImage> counts = offscreen->makeImageSnapshot();
52
53 // Draw overdraw colors to the canvas. The color filter will convert counts to colors.
54 SkPaint paint;
55 paint.setColorFilter(SkOverdrawColorFilter::Make(kOverdrawColors));
56 canvas->drawImage(counts.get(), 0.0f, 0.0f, &paint);
57 canvas->drawString("This is some text:", 180, 300, SkFont(), SkPaint());
58}
59