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

Public Member Functions

 ComposeShaderBitmapGM (bool use_lm)
 
- 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
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void onDraw (SkCanvas *canvas) override
 
- 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
 

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 []
 

Detailed Description

Definition at line 161 of file composeshader.cpp.

Constructor & Destructor Documentation

◆ ComposeShaderBitmapGM()

ComposeShaderBitmapGM::ComposeShaderBitmapGM ( bool  use_lm)
inline

Definition at line 163 of file composeshader.cpp.

163: fUseLocalMatrix(use_lm) {}

Member Function Documentation

◆ getISize()

SkISize ComposeShaderBitmapGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 170 of file composeshader.cpp.

170 {
171 return SkISize::Make(7 * (squareLength + 5), 2 * (squareLength + 5));
172 }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString ComposeShaderBitmapGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 166 of file composeshader.cpp.

166 {
167 return SkStringPrintf("composeshader_bitmap%s", fUseLocalMatrix ? "_lm" : "");
168 }
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.

◆ onDraw()

void ComposeShaderBitmapGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 174 of file composeshader.cpp.

174 {
175 if (!fInitialized) {
176 draw_color_bm(&fColorBitmap, squareLength);
177 sk_sp<SkImage> img = SkImages::RasterFromBitmap(fColorBitmap);
178 img = ToolUtils::MakeTextureImage(canvas, std::move(img));
179 if (img) {
180 fColorBitmapShader = img->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
182 }
183 draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
184 img = SkImages::RasterFromBitmap(fAlpha8Bitmap);
185 img = ToolUtils::MakeTextureImage(canvas, std::move(img));
186 if (img) {
187 fAlpha8BitmapShader = fAlpha8Bitmap.makeShader(SkTileMode::kRepeat,
190 SkMatrix::I());
191 }
192 fLinearGradientShader = make_linear_gradient_shader(squareLength);
193 fInitialized = true;
194 }
195
197
198 SkMatrix lm = SkMatrix::Translate(0, squareLength * 0.5f);
199
200 sk_sp<SkShader> shaders[] = {
201 // gradient should appear over color bitmap
202 SkShaders::Blend(mode, fLinearGradientShader, fColorBitmapShader),
203 // gradient should appear over alpha8 bitmap colorized by the paint color
204 SkShaders::Blend(mode, fLinearGradientShader, fAlpha8BitmapShader),
205 };
206 if (fUseLocalMatrix) {
207 for (unsigned i = 0; i < std::size(shaders); ++i) {
208 shaders[i] = shaders[i] ? shaders[i]->makeWithLocalMatrix(lm) : nullptr;
209 }
210 }
211
213 paint.setColor(SK_ColorYELLOW);
214
215 const SkRect r = SkRect::MakeIWH(squareLength, squareLength);
216
217 for (size_t y = 0; y < std::size(shaders); ++y) {
218 canvas->save();
219 for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
220 paint.setAlpha(alpha);
221 paint.setShader(shaders[y]);
222 canvas->drawRect(r, paint);
223
224 canvas->translate(r.width() + 5, 0);
225 }
226 canvas->restore();
227 canvas->translate(0, r.height() + 5);
228 }
229 }
SkBlendMode
Definition: SkBlendMode.h:38
@ kDstOver
r = d + (1-da)*s
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
sk_sp< SkShader > makeWithLocalMatrix(const SkMatrix &) const
Definition: SkShader.cpp:26
const Paint & paint
Definition: color_source.cc:38
static sk_sp< SkShader > make_linear_gradient_shader(int length)
static void draw_color_bm(SkBitmap *bm, int length)
static void draw_alpha8_bm(SkBitmap *bm, int length)
double y
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
SK_API sk_sp< SkShader > Blend(SkBlendMode mode, sk_sp< SkShader > dst, sk_sp< SkShader > src)
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkSamplingOptions(SkFilterMode::kLinear))
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762

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