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

Public Member Functions

 LinearGradientRT ()
 
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
 

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 593 of file runtimeshader.cpp.

Constructor & Destructor Documentation

◆ LinearGradientRT()

LinearGradientRT::LinearGradientRT ( )
inline

Definition at line 595 of file runtimeshader.cpp.

595 : RuntimeShaderGM("linear_gradient_rt", {256 + 10, 128 + 15}, R"(
596 layout(color) uniform vec4 in_colors0;
597 layout(color) uniform vec4 in_colors1;
598
599 vec4 main(vec2 p) {
600 float t = p.x / 256;
601 if (p.y < 32) {
602 return mix(in_colors0, in_colors1, t);
603 } else {
604 vec3 linColor0 = toLinearSrgb(in_colors0.rgb);
605 vec3 linColor1 = toLinearSrgb(in_colors1.rgb);
606 vec3 linColor = mix(linColor0, linColor1, t);
607 return fromLinearSrgb(linColor).rgb1;
608 }
609 }
610 )") {}
RuntimeShaderGM(const char *name, SkISize size, const char *sksl, uint32_t flags=0)

Member Function Documentation

◆ onDraw()

void LinearGradientRT::onDraw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 612 of file runtimeshader.cpp.

612 {
613 // Colors chosen to use values other than 0 and 1 - so that it's obvious if the conversion
614 // intrinsics are doing anything. (Most transfer functions map 0 -> 0 and 1 -> 1).
616 builder.uniform("in_colors0") = SkColor4f{0.75f, 0.25f, 0.0f, 1.0f};
617 builder.uniform("in_colors1") = SkColor4f{0.0f, 0.75f, 0.25f, 1.0f};
619 paint.setShader(builder.makeShader());
620
621 canvas->save();
622 canvas->clear(SK_ColorWHITE);
623 canvas->translate(5, 5);
624
625 // We draw everything twice. First to a surface with no color management, where the
626 // intrinsics should do nothing (eg, the top bar should look the same in the top and bottom
627 // halves). Then to an sRGB surface, where they should produce linearly interpolated
628 // gradients (the bottom half of the second bar should be brighter than the top half).
629 for (auto cs : {static_cast<SkColorSpace*>(nullptr), sk_srgb_singleton()}) {
631 256, 64, kN32_SkColorType, kPremul_SkAlphaType, sk_ref_sp(cs));
632 auto surface = canvas->makeSurface(info);
633 if (!surface) {
635 }
636
637 surface->getCanvas()->drawRect({0, 0, 256, 64}, paint);
638 canvas->drawImage(surface->makeImageSnapshot(), 0, 0);
639 canvas->translate(0, 64 + 5);
640 }
641
642 canvas->restore();
643 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorSpace * sk_srgb_singleton()
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
sk_sp< SkRuntimeEffect > fEffect
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

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