Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
ColorCubeRT Class Reference
Inheritance diagram for ColorCubeRT:
RuntimeShaderGM skiagm::GM

Public Member Functions

 ColorCubeRT ()
 
void onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
- Public Member Functions inherited from RuntimeShaderGM
 RuntimeShaderGM (const char *name, SkISize size, const char *sksl, uint32_t flags=0)
 
void onOnceBeforeDraw () override
 
bool runAsBench () const override
 
SkString getName () const override
 
SkISize getISize () override
 
bool onAnimate (double nanos) override
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Public Attributes

sk_sp< SkImagefMandrill
 
sk_sp< SkImagefMandrillSepia
 
sk_sp< SkImagefIdentityCube
 
sk_sp< SkImagefSepiaCube
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 
- Protected Attributes inherited from RuntimeShaderGM
SkString fName
 
SkISize fSize
 
uint32_t fFlags
 
float fSecs = 0.0f
 
SkString fSkSL
 
sk_sp< SkRuntimeEffectfEffect
 

Detailed Description

Definition at line 270 of file runtimeshader.cpp.

Constructor & Destructor Documentation

◆ ColorCubeRT()

ColorCubeRT::ColorCubeRT ( )
inline

Definition at line 272 of file runtimeshader.cpp.

272 : RuntimeShaderGM("color_cube_rt", {512, 512}, R"(
273 uniform shader child;
274 uniform shader color_cube;
275
276 uniform float rg_scale;
277 uniform float rg_bias;
278 uniform float b_scale;
279 uniform float inv_size;
280
281 half4 main(float2 xy) {
282 float4 c = unpremul(child.eval(xy));
283
284 // Map to cube coords:
285 float3 cubeCoords = float3(c.rg * rg_scale + rg_bias, c.b * b_scale);
286
287 // Compute slice coordinate
288 float2 coords1 = float2((floor(cubeCoords.b) + cubeCoords.r) * inv_size, cubeCoords.g);
289 float2 coords2 = float2(( ceil(cubeCoords.b) + cubeCoords.r) * inv_size, cubeCoords.g);
290
291 // Two bilinear fetches, plus a manual lerp for the third axis:
292 half4 color = mix(color_cube.eval(coords1), color_cube.eval(coords2),
293 fract(cubeCoords.b));
294
295 // Premul again
296 color.rgb *= color.a;
297
298 return color;
299 }
300 )") {}
RuntimeShaderGM(const char *name, SkISize size, const char *sksl, uint32_t flags=0)

Member Function Documentation

◆ onDraw()

void ColorCubeRT::onDraw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 313 of file runtimeshader.cpp.

313 {
315
316 // First we draw the unmodified image, and a copy that was sepia-toned in Photoshop:
317 canvas->drawImage(fMandrill, 0, 0);
318 canvas->drawImage(fMandrillSepia, 0, 256);
319
320 // LUT dimensions should be (kSize^2, kSize)
321 constexpr float kSize = 16.0f;
322
324
325 builder.uniform("rg_scale") = (kSize - 1) / kSize;
326 builder.uniform("rg_bias") = 0.5f / kSize;
327 builder.uniform("b_scale") = kSize - 1;
328 builder.uniform("inv_size") = 1.0f / kSize;
329
330 builder.child("child") = fMandrill->makeShader(sampling);
331
333
334 // TODO: Should we add SkImage::makeNormalizedShader() to handle this automatically?
335 SkMatrix normalize = SkMatrix::Scale(1.0f / (kSize * kSize), 1.0f / kSize);
336
337 // Now draw the image with an identity color cube - it should look like the original
338 builder.child("color_cube") = fIdentityCube->makeShader(sampling, normalize);
339 paint.setShader(builder.makeShader());
340 canvas->translate(256, 0);
341 canvas->drawRect({ 0, 0, 256, 256 }, paint);
342
343 // ... and with a sepia-tone color cube. This should match the sepia-toned image.
344 builder.child("color_cube") = fSepiaCube->makeShader(sampling, normalize);
345 paint.setShader(builder.makeShader());
346 canvas->translate(0, 256);
347 canvas->drawRect({ 0, 0, 256, 256 }, paint);
348 }
sk_sp< SkImage > fMandrillSepia
sk_sp< SkImage > fSepiaCube
sk_sp< SkImage > fMandrill
sk_sp< SkImage > fIdentityCube
sk_sp< SkRuntimeEffect > fEffect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
const Paint & paint
Definition: color_source.cc:38
constexpr int kSize
SkSamplingOptions sampling
Definition: SkRecords.h:337
SIN Vec< N, float > normalize(const Vec< N, float > &v)
Definition: SkVx.h:995

◆ onOnceBeforeDraw()

void ColorCubeRT::onOnceBeforeDraw ( )
inlineoverridevirtual

Reimplemented from RuntimeShaderGM.

Definition at line 304 of file runtimeshader.cpp.

304 {
305 fMandrill = ToolUtils::GetResourceAsImage("images/mandrill_256.png");
306 fMandrillSepia = ToolUtils::GetResourceAsImage("images/mandrill_sepia.png");
307 fIdentityCube = ToolUtils::GetResourceAsImage("images/lut_identity.png");
308 fSepiaCube = ToolUtils::GetResourceAsImage("images/lut_sepia.png");
309
311 }
void onOnceBeforeDraw() override
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25

Member Data Documentation

◆ fIdentityCube

sk_sp<SkImage> ColorCubeRT::fIdentityCube

Definition at line 302 of file runtimeshader.cpp.

◆ fMandrill

sk_sp<SkImage> ColorCubeRT::fMandrill

Definition at line 302 of file runtimeshader.cpp.

◆ fMandrillSepia

sk_sp<SkImage> ColorCubeRT::fMandrillSepia

Definition at line 302 of file runtimeshader.cpp.

◆ fSepiaCube

sk_sp<SkImage> ColorCubeRT::fSepiaCube

Definition at line 302 of file runtimeshader.cpp.


The documentation for this class was generated from the following file: