Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkSurface_Raster Class Reference

#include <SkSurface_Raster.h>

Inheritance diagram for SkSurface_Raster:
SkSurface_Base SkSurface SkRefCnt SkRefCntBase

Public Member Functions

 SkSurface_Raster (const SkImageInfo &, void *, size_t rb, void(*releaseProc)(void *pixels, void *context), void *context, const SkSurfaceProps *)
 
 SkSurface_Raster (const SkImageInfo &info, sk_sp< SkPixelRef >, const SkSurfaceProps *)
 
SkImageInfo imageInfo () const override
 
SkSurface_Base::Type type () const override
 
SkCanvasonNewCanvas () override
 
sk_sp< SkSurfaceonNewSurface (const SkImageInfo &) override
 
sk_sp< SkImageonNewImageSnapshot (const SkIRect *subset) override
 
void onWritePixels (const SkPixmap &, int x, int y) override
 
void onDraw (SkCanvas *, SkScalar, SkScalar, const SkSamplingOptions &, const SkPaint *) override
 
bool onCopyOnWrite (ContentChangeMode) override
 
void onRestoreBackingMutability () override
 
sk_sp< const SkCapabilitiesonCapabilities () override
 
- Public Member Functions inherited from SkSurface_Base
 SkSurface_Base (int width, int height, const SkSurfaceProps *)
 
 SkSurface_Base (const SkImageInfo &, const SkSurfaceProps *)
 
 ~SkSurface_Base () override
 
bool replaceBackendTexture (const GrBackendTexture &, GrSurfaceOrigin, ContentChangeMode, TextureReleaseProc, ReleaseContext) override
 
virtual Type type () const
 
bool isRasterBacked () const
 
bool isGaneshBacked () const
 
bool isGraphiteBacked () const
 
virtual GrRecordingContextonGetRecordingContext () const
 
virtual skgpu::graphite::RecorderonGetRecorder () const
 
virtual SkCanvasonNewCanvas ()=0
 
virtual sk_sp< SkSurfaceonNewSurface (const SkImageInfo &)=0
 
virtual sk_sp< SkImageonNewImageSnapshot (const SkIRect *subset=nullptr)
 
virtual void onWritePixels (const SkPixmap &, int x, int y)=0
 
virtual void onAsyncRescaleAndReadPixels (const SkImageInfo &, const SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext)
 
virtual void onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext)
 
virtual void onDraw (SkCanvas *, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *)
 
virtual void onDiscard ()
 
virtual bool onCopyOnWrite (ContentChangeMode)=0
 
virtual void onRestoreBackingMutability ()
 
virtual bool onWait (int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)
 
virtual bool onCharacterize (GrSurfaceCharacterization *) const
 
virtual bool onIsCompatible (const GrSurfaceCharacterization &) const
 
virtual sk_sp< const SkCapabilitiesonCapabilities ()
 
SkCanvasgetCachedCanvas ()
 
sk_sp< SkImagerefCachedImage ()
 
bool hasCachedImage () const
 
uint32_t newGenerationID ()
 
- Public Member Functions inherited from SkSurface
bool isCompatible (const GrSurfaceCharacterization &characterization) const
 
int width () const
 
int height () const
 
virtual SkImageInfo imageInfo () const
 
uint32_t generationID ()
 
void notifyContentWillChange (ContentChangeMode mode)
 
GrRecordingContextrecordingContext () const
 
skgpu::graphite::Recorderrecorder () const
 
virtual bool replaceBackendTexture (const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, ContentChangeMode mode=kRetain_ContentChangeMode, TextureReleaseProc=nullptr, ReleaseContext=nullptr)=0
 
SkCanvasgetCanvas ()
 
sk_sp< const SkCapabilitiescapabilities ()
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &imageInfo)
 
sk_sp< SkSurfacemakeSurface (int width, int height)
 
sk_sp< SkImagemakeImageSnapshot ()
 
sk_sp< SkImagemakeImageSnapshot (const SkIRect &bounds)
 
void draw (SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint)
 
void draw (SkCanvas *canvas, SkScalar x, SkScalar y, const SkPaint *paint=nullptr)
 
bool peekPixels (SkPixmap *pixmap)
 
bool readPixels (const SkPixmap &dst, int srcX, int srcY)
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
 
bool readPixels (const SkBitmap &dst, int srcX, int srcY)
 
void asyncRescaleAndReadPixels (const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUVA420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
void writePixels (const SkPixmap &src, int dstX, int dstY)
 
void writePixels (const SkBitmap &src, int dstX, int dstY)
 
const SkSurfacePropsprops () const
 
bool wait (int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait=true)
 
bool characterize (GrSurfaceCharacterization *characterization) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Public Types inherited from SkSurface_Base
enum class  Type { kNull , kGanesh , kGraphite , kRaster }
 
- Public Types inherited from SkSurface
enum  ContentChangeMode { kDiscard_ContentChangeMode , kRetain_ContentChangeMode }
 
enum class  BackendHandleAccess {
  kFlushRead , kFlushWrite , kDiscardWrite , kFlushRead_BackendHandleAccess = kFlushRead ,
  kFlushWrite_BackendHandleAccess = kFlushWrite , kDiscardWrite_BackendHandleAccess = kDiscardWrite
}
 
using ReleaseContext = void *
 
using TextureReleaseProc = void(*)(ReleaseContext)
 
using AsyncReadResult = SkImage::AsyncReadResult
 
using ReadPixelsContext = void *
 
using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >)
 
using RescaleGamma = SkImage::RescaleGamma
 
using RescaleMode = SkImage::RescaleMode
 
- Static Public Attributes inherited from SkSurface
static constexpr BackendHandleAccess kFlushRead_BackendHandleAccess
 
static constexpr BackendHandleAccess kFlushWrite_BackendHandleAccess
 
static constexpr BackendHandleAccess kDiscardWrite_BackendHandleAccess
 
- Protected Member Functions inherited from SkSurface
 SkSurface (int width, int height, const SkSurfaceProps *surfaceProps)
 
 SkSurface (const SkImageInfo &imageInfo, const SkSurfaceProps *surfaceProps)
 
void dirtyGenerationID ()
 

Detailed Description

Definition at line 30 of file SkSurface_Raster.h.

Constructor & Destructor Documentation

◆ SkSurface_Raster() [1/2]

SkSurface_Raster::SkSurface_Raster ( const SkImageInfo info,
void *  pixels,
size_t  rb,
void(*)(void *pixels, void *context)  releaseProc,
void *  context,
const SkSurfaceProps props 
)

Definition at line 58 of file SkSurface_Raster.cpp.

61 : INHERITED(info, props)
62{
63 fBitmap.installPixels(info, pixels, rb, releaseProc, context);
64 fWeOwnThePixels = false; // We are "Direct"
65}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static void releaseProc(const void *ptr, void *context)
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition: SkBitmap.cpp:323
const SkSurfaceProps & props() const
Definition: SkSurface.h:604

◆ SkSurface_Raster() [2/2]

SkSurface_Raster::SkSurface_Raster ( const SkImageInfo info,
sk_sp< SkPixelRef pr,
const SkSurfaceProps props 
)

Definition at line 67 of file SkSurface_Raster.cpp.

69 : INHERITED(pr->width(), pr->height(), props)
70{
71 fBitmap.setInfo(info, pr->rowBytes());
72 fBitmap.setPixelRef(std::move(pr), 0, 0);
73 fWeOwnThePixels = true;
74}
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition: SkBitmap.cpp:114
void setPixelRef(sk_sp< SkPixelRef > pixelRef, int dx, int dy)
Definition: SkBitmap.cpp:182
int width() const
Definition: SkPixelRef.h:34
int height() const
Definition: SkPixelRef.h:35
size_t rowBytes() const
Definition: SkPixelRef.h:37

Member Function Documentation

◆ imageInfo()

SkImageInfo SkSurface_Raster::imageInfo ( ) const
inlineoverridevirtual

Returns an ImageInfo describing the surface.

Reimplemented from SkSurface.

Definition at line 38 of file SkSurface_Raster.h.

38{ return fBitmap.info(); }
const SkImageInfo & info() const
Definition: SkBitmap.h:139

◆ onCapabilities()

sk_sp< const SkCapabilities > SkSurface_Raster::onCapabilities ( )
overridevirtual

Reimplemented from SkSurface_Base.

Definition at line 154 of file SkSurface_Raster.cpp.

154 {
156}
static sk_sp< const SkCapabilities > RasterBackend()

◆ onCopyOnWrite()

bool SkSurface_Raster::onCopyOnWrite ( ContentChangeMode  )
overridevirtual

If the surface is about to change, we call this so that our subclass can optionally fork their backend (copy-on-write) in case it was being shared with the cachedImage.

Returns false if the backing cannot be un-shared.

Implements SkSurface_Base.

Definition at line 124 of file SkSurface_Raster.cpp.

124 {
125 // are we sharing pixelrefs with the image?
126 sk_sp<SkImage> cached(this->refCachedImage());
127 SkASSERT(cached);
128 if (SkBitmapImageGetPixelRef(cached.get()) == fBitmap.pixelRef()) {
129 SkASSERT(fWeOwnThePixels);
131 if (!fBitmap.tryAllocPixels()) {
132 return false;
133 }
134 } else {
135 SkBitmap prev(fBitmap);
136 if (!fBitmap.tryAllocPixels()) {
137 return false;
138 }
139 SkASSERT(prev.info() == fBitmap.info());
140 SkASSERT(prev.rowBytes() == fBitmap.rowBytes());
141 memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.computeByteSize());
142 }
143
144 // Now fBitmap is a deep copy of itself (and therefore different from
145 // what is being used by the image. Next we update the canvas to use
146 // this as its backend, so we can't modify the image's pixels anymore.
147 SkASSERT(this->getCachedCanvas());
148 SkBitmapDevice* bmDev = static_cast<SkBitmapDevice*>(this->getCachedCanvas()->rootDevice());
149 bmDev->replaceBitmapBackendForRasterSurface(fBitmap);
150 }
151 return true;
152}
static float prev(float f)
#define SkASSERT(cond)
Definition: SkAssert.h:116
const SkPixelRef * SkBitmapImageGetPixelRef(const SkImage *rasterImage)
SkPixelRef * pixelRef() const
Definition: SkBitmap.h:720
size_t computeByteSize() const
Definition: SkBitmap.h:293
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:271
sk_sp< SkImage > refCachedImage()
SkCanvas * getCachedCanvas()
@ kDiscard_ContentChangeMode
discards surface on change
Definition: SkSurface.h:204
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

◆ onDraw()

void SkSurface_Raster::onDraw ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling,
const SkPaint paint 
)
overridevirtual

Default implementation:

image = this->newImageSnapshot(); if (image) { image->draw(canvas, ...); image->unref(); }

Reimplemented from SkSurface_Base.

Definition at line 82 of file SkSurface_Raster.cpp.

83 {
84 canvas->drawImage(fBitmap.asImage().get(), x, y, sampling, paint);
85}
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
double y
double x
SkSamplingOptions sampling
Definition: SkRecords.h:337

◆ onNewCanvas()

SkCanvas * SkSurface_Raster::onNewCanvas ( )
overridevirtual

Allocate a canvas that will draw into this surface. We will cache this canvas, to return the same object to the caller multiple times. We take ownership, and will call unref() on the canvas when we go out of scope.

Implements SkSurface_Base.

Definition at line 76 of file SkSurface_Raster.cpp.

76{ return new SkCanvas(fBitmap, this->props()); }
friend class SkCanvas

◆ onNewImageSnapshot()

sk_sp< SkImage > SkSurface_Raster::onNewImageSnapshot ( const SkIRect subset)
overridevirtual

Allocate an SkImage that represents the current contents of the surface. This needs to be able to outlive the surface itself (if need be), and must faithfully represent the current contents, even if the surface is changed after this called (e.g. it is drawn to via its canvas).

If a subset is specified, the the impl must make a copy, rather than try to wait on copy-on-write.

Reimplemented from SkSurface_Base.

Definition at line 87 of file SkSurface_Raster.cpp.

87 {
88 if (subset) {
89 SkASSERT(SkIRect::MakeWH(fBitmap.width(), fBitmap.height()).contains(*subset));
91 dst.allocPixels(fBitmap.info().makeDimensions(subset->size()));
92 SkAssertResult(fBitmap.readPixels(dst.pixmap(), subset->left(), subset->top()));
93 dst.setImmutable(); // key, so MakeFromBitmap doesn't make a copy of the buffer
94 return dst.asImage();
95 }
96
98 if (fWeOwnThePixels) {
99 // SkImage_raster requires these pixels are immutable for its full lifetime.
100 // We'll undo this via onRestoreBackingMutability() if we can avoid the COW.
101 if (SkPixelRef* pr = fBitmap.pixelRef()) {
102 pr->setTemporarilyImmutable();
103 }
104 } else {
106 }
107
108 // Our pixels are in memory, so read access on the snapshot SkImage could be cheap.
109 // Lock the shared pixel ref to ensure peekPixels() is usable.
110 return SkMakeImageFromRasterBitmap(fBitmap, cpm);
111}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap(const SkBitmap &, SkCopyPixelsMode)
SkCopyPixelsMode
Definition: SkImagePriv.h:17
@ kIfMutable_SkCopyPixelsMode
only copy src pixels if they are marked mutable
Definition: SkImagePriv.h:18
@ kAlways_SkCopyPixelsMode
always copy src pixels (even if they are marked immutable)
Definition: SkImagePriv.h:19
int width() const
Definition: SkBitmap.h:149
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY) const
Definition: SkBitmap.cpp:488
int height() const
Definition: SkBitmap.h:158
dst
Definition: cp.py:12
constexpr int32_t top() const
Definition: SkRect.h:120
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
constexpr int32_t left() const
Definition: SkRect.h:113
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454

◆ onNewSurface()

sk_sp< SkSurface > SkSurface_Raster::onNewSurface ( const SkImageInfo info)
overridevirtual

Implements SkSurface_Base.

Definition at line 78 of file SkSurface_Raster.cpp.

78 {
79 return SkSurfaces::Raster(info, &this->props());
80}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ onRestoreBackingMutability()

void SkSurface_Raster::onRestoreBackingMutability ( )
overridevirtual

Signal the surface to remind its backing store that it's mutable again. Called only when we didn't copy-on-write; we assume the copies start mutable.

Reimplemented from SkSurface_Base.

Definition at line 117 of file SkSurface_Raster.cpp.

117 {
118 SkASSERT(!this->hasCachedImage()); // Shouldn't be any snapshots out there.
119 if (SkPixelRef* pr = fBitmap.pixelRef()) {
120 pr->restoreMutability();
121 }
122}
bool hasCachedImage() const

◆ onWritePixels()

void SkSurface_Raster::onWritePixels ( const SkPixmap src,
int  x,
int  y 
)
overridevirtual

Implements SkSurface_Base.

Definition at line 113 of file SkSurface_Raster.cpp.

113 {
114 fBitmap.writePixels(src, x, y);
115}
bool writePixels(const SkPixmap &src, int dstX, int dstY)
Definition: SkBitmap.cpp:501

◆ type()

SkSurface_Base::Type SkSurface_Raster::type ( ) const
inlineoverridevirtual

Reimplemented from SkSurface_Base.

Definition at line 41 of file SkSurface_Raster.h.


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