diff options
author | Matt Sarett <msarett@google.com> | 2016-11-22 15:48:50 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-22 21:27:42 +0000 |
commit | 030cbd5f3cc60255b887fb88920fb655c8a2a9be (patch) | |
tree | 5e1d050baec746da7f2fd2a83a128ab4e9d9cd1b /gm/overdrawcolorfilter.cpp | |
parent | a2b4bdce8cfd1a91407595a25683ecff982af22e (diff) |
Add SkOverdrawColorFilter
Uses the value in the src alpha channel to choose how
to set the dst pixel.
This is a part of a multi-part change to detect and
display gpu overdraw on Android.
CQ_INCLUDE_TRYBOTS=master.client.skia.compile:Build-Ubuntu-GCC-x86_64-Debug-NoGPU-Trybot
BUG:32370375
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5113
Change-Id: I07040929d8a46bbadd499dccec75eebef0e11d11
Reviewed-on: https://skia-review.googlesource.com/5113
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm/overdrawcolorfilter.cpp')
-rw-r--r-- | gm/overdrawcolorfilter.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/gm/overdrawcolorfilter.cpp b/gm/overdrawcolorfilter.cpp new file mode 100644 index 0000000000..2eba228045 --- /dev/null +++ b/gm/overdrawcolorfilter.cpp @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkCanvas.h" +#include "SkOverdrawColorFilter.h" + +static inline void set_bitmap(SkBitmap* bitmap, uint8_t alpha) { + for (int y = 0; y < bitmap->height(); y++) { + for (int x = 0; x < bitmap->width(); x++) { + uint8_t* addr = bitmap->getAddr8(x, y); + *addr = alpha; + } + } + + bitmap->notifyPixelsChanged(); +} + +class OverdrawColorFilter : public skiagm::GM { +public: + OverdrawColorFilter() {} + +protected: + virtual SkString onShortName() override { + return SkString("overdrawcolorfilter");; + } + + virtual SkISize onISize() override { + return SkISize::Make(200, 400); + } + + void onDraw(SkCanvas* canvas) override { + static const SkPMColor colors[SkOverdrawColorFilter::kNumColors] = { + 0x80800000, 0x80008000, 0x80000080, 0x80808000, 0x80008080, 0x80800080, + }; + + SkPaint paint; + sk_sp<SkColorFilter> colorFilter = SkOverdrawColorFilter::Make(colors); + paint.setColorFilter(colorFilter); + + SkImageInfo info = SkImageInfo::MakeA8(100, 100); + SkBitmap bitmap; + bitmap.allocPixels(info); + set_bitmap(&bitmap, 0); + canvas->drawBitmap(bitmap, 0, 0, &paint); + set_bitmap(&bitmap, 1); + canvas->drawBitmap(bitmap, 0, 100, &paint); + set_bitmap(&bitmap, 2); + canvas->drawBitmap(bitmap, 0, 200, &paint); + set_bitmap(&bitmap, 3); + canvas->drawBitmap(bitmap, 0, 300, &paint); + set_bitmap(&bitmap, 4); + canvas->drawBitmap(bitmap, 100, 0, &paint); + set_bitmap(&bitmap, 5); + canvas->drawBitmap(bitmap, 100, 100, &paint); + set_bitmap(&bitmap, 6); + canvas->drawBitmap(bitmap, 100, 200, &paint); + } + +private: + typedef GM INHERITED; +}; + +DEF_GM(return new OverdrawColorFilter;) |