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

Public Member Functions

 BitmapImageGM ()
 
- 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
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) 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 26 of file bitmapimage.cpp.

Constructor & Destructor Documentation

◆ BitmapImageGM()

skiagm::BitmapImageGM::BitmapImageGM ( )
inline

Definition at line 28 of file bitmapimage.cpp.

28{}

Member Function Documentation

◆ getISize()

SkISize skiagm::BitmapImageGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 33 of file bitmapimage.cpp.

33{ return SkISize::Make(2 * kSize, 2 * kSize); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::BitmapImageGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 31 of file bitmapimage.cpp.

31{ return SkString("bitmap-image-srgb-legacy"); }

◆ onDraw()

DrawResult skiagm::BitmapImageGM::onDraw ( SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 35 of file bitmapimage.cpp.

35 {
36 // Create image.
37 const char* path = "images/mandrill_512_q075.jpg";
39 if (!image) {
40 *errorMsg = "Couldn't load images/mandrill_512_q075.jpg. "
41 "Did you forget to set the resource path?";
42 return DrawResult::kFail;
43 }
44
45 // Create matching bitmap.
46 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(GetResourceAsStream(path)));
47 auto [codecImage, _] = codec->getImage();
48
49 // The GM will be displayed in a 2x2 grid.
50 // The top two squares show an sRGB image, then bitmap, drawn to a legacy canvas.
51 SkImageInfo linearInfo = SkImageInfo::MakeN32(2*kSize, kSize, kOpaque_SkAlphaType);
52 SkBitmap legacyBMCanvas;
53 legacyBMCanvas.allocPixels(linearInfo);
54 SkCanvas legacyCanvas(legacyBMCanvas);
55 legacyCanvas.drawImage(image, 0.0f, 0.0f);
56 legacyCanvas.translate(SkScalar(kSize), 0.0f);
57 legacyCanvas.drawImage(codecImage, 0.0f, 0.0f);
58 canvas->drawImage(legacyBMCanvas.asImage(), 0.0f, 0.0f);
59 canvas->translate(0.0f, SkScalar(kSize));
60
61 // The bottom two squares show an sRGB image, then bitmap, drawn to a srgb canvas.
62 SkImageInfo srgbInfo = SkImageInfo::MakeS32(2*kSize, kSize, kOpaque_SkAlphaType);
63 SkBitmap srgbBMCanvas;
64 srgbBMCanvas.allocPixels(srgbInfo);
65 SkCanvas srgbCanvas(srgbBMCanvas);
66 srgbCanvas.drawImage(image, 0.0f, 0.0f);
67 srgbCanvas.translate(SkScalar(kSize), 0.0f);
68 srgbCanvas.drawImage(codecImage, 0.0f, 0.0f);
69 canvas->drawImage(srgbBMCanvas.asImage(), 0.0f, 0.0f);
70 return DrawResult::kOk;
71 }
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
Definition: SkCodec.cpp:163
float SkScalar
Definition: extension.cpp:12
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)

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