Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
fpcoordinateoverride.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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"
15#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
26#include "src/gpu/ganesh/SkGr.h"
31#include "tools/DecodeUtils.h"
32#include "tools/Resources.h"
33#include "tools/ToolUtils.h"
34
36public:
37 inline static constexpr GrProcessor::ClassID CLASS_ID = (GrProcessor::ClassID) 0;
38
39 SampleCoordEffect(std::unique_ptr<GrFragmentProcessor> child)
41 this->registerChild(std::move(child), SkSL::SampleUsage::Explicit());
42 }
43
44 const char* name() const override { return "SampleCoordEffect"; }
45
46 std::unique_ptr<GrFragmentProcessor> clone() const override {
47 SkASSERT(false);
48 return nullptr;
49 }
50
51 void onAddToKey(const GrShaderCaps&, skgpu::KeyBuilder*) const override {}
52
53 bool onIsEqual(const GrFragmentProcessor&) const override {
54 SkASSERT(false);
55 return true;
56 }
57
58private:
59 std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override;
60 using INHERITED = GrFragmentProcessor;
61};
62
63std::unique_ptr<GrFragmentProcessor::ProgramImpl> SampleCoordEffect::onMakeProgramImpl() const {
64 class Impl : public ProgramImpl {
65 public:
66 void emitCode(EmitArgs& args) override {
67 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
68 SkString s1 = this->invokeChild(0, args, "float2(sk_FragCoord.x, sk_FragCoord.y)");
69 SkString s2 = this->invokeChild(0, args, "float2(sk_FragCoord.x, 512-sk_FragCoord.y)");
70 fragBuilder->codeAppendf("return (%s + %s) / 2;\n", s1.c_str(), s2.c_str());
71 }
72 };
73
74 return std::make_unique<Impl>();
75}
76
77DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, rContext, canvas, 512, 512,
78 ToolUtils::color_to_565(0xFF66AA99)) {
79
81 if (!sfc) {
82 return;
83 }
84
85 SkBitmap bmp;
86 ToolUtils::GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp);
87 auto view = std::get<0>(GrMakeCachedBitmapProxyView(
88 rContext, bmp, /*label=*/"FpCoordinateOverride", skgpu::Mipmapped::kNo));
89 if (!view) {
90 return;
91 }
92 std::unique_ptr<GrFragmentProcessor> imgFP =
93 GrTextureEffect::Make(std::move(view), bmp.alphaType(), SkMatrix());
94 auto fp = std::unique_ptr<GrFragmentProcessor>(new SampleCoordEffect(std::move(imgFP)));
95
96 sfc->fillWithFP(std::move(fp));
97}
#define SkASSERT(cond)
Definition SkAssert.h:116
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeCachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, std::string_view label, skgpu::Mipmapped mipmapped)
Definition SkGr.cpp:188
void registerChild(std::unique_ptr< GrFragmentProcessor > child, SkSL::SampleUsage sampleUsage=SkSL::SampleUsage::PassThrough())
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
std::unique_ptr< GrFragmentProcessor > clone() const override
void onAddToKey(const GrShaderCaps &, skgpu::KeyBuilder *) const override
SampleCoordEffect(std::unique_ptr< GrFragmentProcessor > child)
std::unique_ptr< ProgramImpl > onMakeProgramImpl() const override
bool onIsEqual(const GrFragmentProcessor &) const override
const char * name() const override
static constexpr GrProcessor::ClassID CLASS_ID
SkAlphaType alphaType() const
Definition SkBitmap.h:162
static SampleUsage Explicit()
const char * c_str() const
Definition SkString.h:133
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, rContext, canvas, 512, 512, ToolUtils::color_to_565(0xFF66AA99))
bool GetResourceAsBitmap(const char *resource, SkBitmap *dst)
Definition DecodeUtils.h:21
SkColor color_to_565(SkColor color)
SurfaceFillContext * TopDeviceSurfaceFillContext(const SkCanvas *canvas)
Definition GrCanvas.cpp:27