| 1 |
/* |
| 2 |
* Copyright 2021 Google LLC. |
| 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/gm.h" |
| 9 |
#include "include/core/SkCanvas.h" |
| 10 |
#include "include/core/SkRect.h" |
| 11 |
#include "include/effects/SkRuntimeEffect.h" |
| 12 |
#include "tools/DecodeUtils.h" |
| 13 |
#include "tools/Resources.h" |
| 14 |
|
| 15 |
namespace skiagm { |
| 16 |
|
| 17 |
DEF_SIMPLE_GM(destcolor, canvas, 640, 640) { |
| 18 |
// Draw the mandrill. |
| 19 |
canvas->drawImage(ToolUtils::GetResourceAsImage("images/mandrill_512.png"), 0, 0); |
| 20 |
|
| 21 |
// Now let's add our test effect on top. It reads back the original image and inverts it. |
| 22 |
auto [effect, error] = SkRuntimeEffect::MakeForBlender(SkString(R"( |
| 23 |
half4 main(half4 src, half4 dst) { |
| 24 |
return (half4(1) - dst).rgb1; |
| 25 |
} |
| 26 |
)")); |
| 27 |
SkASSERT(effect); |
| 28 |
SkPaint invertPaint; |
| 29 |
invertPaint.setAntiAlias(true); |
| 30 |
invertPaint.setBlender(effect->makeBlender(nullptr)); |
| 31 |
canvas->drawOval(SkRect::MakeLTRB(128, 128, 640, 640), invertPaint); |
| 32 |
} |
| 33 |
|
| 34 |
} // namespace skiagm |