Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkSurface_Ganesh Class Reference

#include <SkSurface_Ganesh.h>

Inheritance diagram for SkSurface_Ganesh:
SkSurface_Base SkSurface SkRefCnt SkRefCntBase

Public Member Functions

 SkSurface_Ganesh (sk_sp< skgpu::ganesh::Device >)
 
 ~SkSurface_Ganesh () override
 
SkImageInfo imageInfo () const override
 
bool replaceBackendTexture (const GrBackendTexture &, GrSurfaceOrigin, ContentChangeMode, TextureReleaseProc, ReleaseContext) override
 
SkSurface_Base::Type type () const override
 
GrRecordingContextonGetRecordingContext () 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 onAsyncRescaleAndReadPixels (const SkImageInfo &info, SkIRect srcRect, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
 
void onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
 
bool onCopyOnWrite (ContentChangeMode) override
 
void onDiscard () override
 
bool onWait (int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait) override
 
bool onCharacterize (GrSurfaceCharacterization *) const override
 
bool onIsCompatible (const GrSurfaceCharacterization &) const override
 
void onDraw (SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *paint) override
 
sk_sp< const SkCapabilitiesonCapabilities () override
 
skgpu::ganesh::DevicegetDevice ()
 
GrBackendTexture getBackendTexture (BackendHandleAccess)
 
GrBackendRenderTarget getBackendRenderTarget (BackendHandleAccess)
 
void resolveMSAA ()
 
bool draw (sk_sp< const GrDeferredDisplayList >)
 
- 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 isRasterBacked () const
 
bool isGaneshBacked () const
 
bool isGraphiteBacked () const
 
virtual skgpu::graphite::RecorderonGetRecorder () const
 
virtual void onRestoreBackingMutability ()
 
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
 
uint32_t generationID ()
 
void notifyContentWillChange (ContentChangeMode mode)
 
GrRecordingContextrecordingContext () const
 
skgpu::graphite::Recorderrecorder () const
 
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 40 of file SkSurface_Ganesh.h.

Constructor & Destructor Documentation

◆ SkSurface_Ganesh()

SkSurface_Ganesh::SkSurface_Ganesh ( sk_sp< skgpu::ganesh::Device device)

Definition at line 65 of file SkSurface_Ganesh.cpp.

66 : INHERITED(device->width(), device->height(), &device->surfaceProps())
67 , fDevice(std::move(device)) {
68 SkASSERT(fDevice->targetProxy()->priv().isExact());
69}
#define SkASSERT(cond)
Definition SkAssert.h:116
GrSurfaceProxyPriv priv()
GrRenderTargetProxy * targetProxy()
Definition Device.cpp:1287
VkDevice device
Definition main.cc:53

◆ ~SkSurface_Ganesh()

SkSurface_Ganesh::~SkSurface_Ganesh ( )
override

Definition at line 71 of file SkSurface_Ganesh.cpp.

71 {
72 if (this->hasCachedImage()) {
74 }
75}
static SkImage_Base * as_IB(SkImage *image)
virtual void generatingSurfaceIsDeleted()
sk_sp< SkImage > refCachedImage()
bool hasCachedImage() const

Member Function Documentation

◆ draw()

bool SkSurface_Ganesh::draw ( sk_sp< const GrDeferredDisplayList ddl)

Definition at line 406 of file SkSurface_Ganesh.cpp.

406 {
407 if (!ddl || !this->isCompatible(ddl->characterization())) {
408 return false;
409 }
410
411 auto direct = fDevice->recordingContext()->asDirectContext();
412 if (!direct || direct->abandoned()) {
413 return false;
414 }
415
416 GrSurfaceProxyView view = fDevice->readSurfaceView();
417
418 direct->priv().createDDLTask(std::move(ddl), view.asRenderTargetProxyRef());
419 return true;
420}
virtual GrDirectContext * asDirectContext()
SK_API const GrSurfaceCharacterization & characterization() const
sk_sp< GrRenderTargetProxy > asRenderTargetProxyRef() const
bool isCompatible(const GrSurfaceCharacterization &characterization) const
GrSurfaceProxyView readSurfaceView()
Definition Device.cpp:1283
GrRecordingContext * recordingContext() const override
Definition Device.h:101

◆ getBackendRenderTarget()

GrBackendRenderTarget SkSurface_Ganesh::getBackendRenderTarget ( BackendHandleAccess  access)

Definition at line 123 of file SkSurface_Ganesh.cpp.

123 {
125 if (!rt) {
126 return GrBackendRenderTarget(); // invalid
127 }
128
129 return rt->getBackendRenderTarget();
130}
static GrRenderTarget * prepare_rt_for_external_access(SkSurface_Ganesh *surface, SkSurfaces::BackendHandleAccess access)
virtual GrBackendRenderTarget getBackendRenderTarget() const =0

◆ getBackendTexture()

GrBackendTexture SkSurface_Ganesh::getBackendTexture ( BackendHandleAccess  access)

Definition at line 111 of file SkSurface_Ganesh.cpp.

111 {
113 if (!rt) {
114 return GrBackendTexture(); // invalid
115 }
116 GrTexture* texture = rt->asTexture();
117 if (texture) {
118 return texture->getBackendTexture();
119 }
120 return GrBackendTexture(); // invalid
121}
virtual GrTexture * asTexture()
Definition GrSurface.h:59
virtual GrBackendTexture getBackendTexture() const =0
FlTexture * texture

◆ getDevice()

skgpu::ganesh::Device * SkSurface_Ganesh::getDevice ( )

Definition at line 81 of file SkSurface_Ganesh.cpp.

81{ return fDevice.get(); }
T * get() const
Definition SkRefCnt.h:303

◆ imageInfo()

SkImageInfo SkSurface_Ganesh::imageInfo ( ) const
overridevirtual

Returns an ImageInfo describing the surface.

Reimplemented from SkSurface.

Definition at line 83 of file SkSurface_Ganesh.cpp.

83{ return fDevice->imageInfo(); }
const SkImageInfo & imageInfo() const
Definition SkDevice.h:117

◆ onAsyncRescaleAndReadPixels()

void SkSurface_Ganesh::onAsyncRescaleAndReadPixels ( const SkImageInfo info,
SkIRect  srcRect,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
)
overridevirtual

Default implementation does a rescale/read and then calls the callback.

Reimplemented from SkSurface_Base.

Definition at line 195 of file SkSurface_Ganesh.cpp.

200 {
201 fDevice->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleMode, callback, context);
202}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
void asyncRescaleAndReadPixels(const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
Definition Device.cpp:1373
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ onAsyncRescaleAndReadPixelsYUV420()

void SkSurface_Ganesh::onAsyncRescaleAndReadPixelsYUV420 ( SkYUVColorSpace  yuvColorSpace,
bool  readAlpha,
sk_sp< SkColorSpace dstColorSpace,
SkIRect  srcRect,
SkISize  dstSize,
RescaleGamma  rescaleGamma,
RescaleMode  ,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
)
overridevirtual

Default implementation does a rescale/read/yuv conversion and then calls the callback.

Reimplemented from SkSurface_Base.

Definition at line 204 of file SkSurface_Ganesh.cpp.

212 {
213 fDevice->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
214 readAlpha,
215 std::move(dstColorSpace),
216 srcRect,
217 dstSize,
218 rescaleGamma,
219 rescaleMode,
220 callback,
221 context);
222}
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
Definition Device.cpp:1389

◆ onCapabilities()

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

Reimplemented from SkSurface_Base.

Definition at line 422 of file SkSurface_Ganesh.cpp.

422 {
423 return fDevice->recordingContext()->skCapabilities();
424}
SK_API sk_sp< const SkCapabilities > skCapabilities() const

◆ onCharacterize()

bool SkSurface_Ganesh::onCharacterize ( GrSurfaceCharacterization characterization) const
overridevirtual

Reimplemented from SkSurface_Base.

Definition at line 256 of file SkSurface_Ganesh.cpp.

256 {
257 auto direct = fDevice->recordingContext()->asDirectContext();
258 if (!direct) {
259 return false;
260 }
261
262 SkImageInfo ii = fDevice->imageInfo();
263 if (ii.colorType() == kUnknown_SkColorType) {
264 return false;
265 }
266
267 GrSurfaceProxyView readSurfaceView = fDevice->readSurfaceView();
268 size_t maxResourceBytes = direct->getResourceCacheLimit();
269
270 skgpu::Mipmapped mipmapped = readSurfaceView.asTextureProxy()
271 ? readSurfaceView.asTextureProxy()->mipmapped()
272 : skgpu::Mipmapped::kNo;
273
274 bool usesGLFBO0 = readSurfaceView.asRenderTargetProxy()->glRTFBOIDIs0();
275 // We should never get in the situation where we have a texture render target that is also
276 // backend by FBO 0.
277 SkASSERT(!usesGLFBO0 || !SkToBool(readSurfaceView.asTextureProxy()));
278
279 bool vkRTSupportsInputAttachment =
281
282 GrBackendFormat format = readSurfaceView.proxy()->backendFormat();
283 int numSamples = readSurfaceView.asRenderTargetProxy()->numSamples();
284 GrProtected isProtected = readSurfaceView.asRenderTargetProxy()->isProtected();
285
286 characterization->set(
287 direct->threadSafeProxy(),
288 maxResourceBytes,
289 ii,
290 format,
291 readSurfaceView.origin(),
292 numSamples,
294 mipmapped,
298 isProtected,
299 this->props());
300 return true;
301}
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
bool supportsVkInputAttachment() const
GrTextureProxy * asTextureProxy() const
GrSurfaceOrigin origin() const
GrSurfaceProxy * proxy() const
GrRenderTargetProxy * asRenderTargetProxy() const
GrProtected isProtected() const
const GrBackendFormat & backendFormat() const
skgpu::Mipmapped mipmapped() const
uint32_t uint32_t * format
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
SkColorType colorType() const

◆ onCopyOnWrite()

bool SkSurface_Ganesh::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 227 of file SkSurface_Ganesh.cpp.

227 {
228 GrSurfaceProxyView readSurfaceView = fDevice->readSurfaceView();
229
230 // are we sharing our backing proxy with the image? Note this call should never create a new
231 // image because onCopyOnWrite is only called when there is a cached image.
233 SkASSERT(image);
234
235 if (static_cast<SkImage_Ganesh*>(image.get())
236 ->surfaceMustCopyOnWrite(readSurfaceView.proxy())) {
237 if (!fDevice->replaceBackingProxy(mode)) {
238 return false;
239 }
240 } else if (kDiscard_ContentChangeMode == mode) {
242 }
243 return true;
244}
bool surfaceMustCopyOnWrite(GrSurfaceProxy *surfaceProxy) const
void onDiscard() override
@ kDiscard_ContentChangeMode
discards surface on change
Definition SkSurface.h:204
bool replaceBackingProxy(SkSurface::ContentChangeMode, sk_sp< GrRenderTargetProxy >, GrColorType, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
Definition Device.cpp:1308
sk_sp< SkImage > image
Definition examples.cpp:29

◆ onDiscard()

void SkSurface_Ganesh::onDiscard ( )
overridevirtual

Called as a performance hint when the Surface is allowed to make it's contents undefined.

Reimplemented from SkSurface_Base.

Definition at line 246 of file SkSurface_Ganesh.cpp.

246{ fDevice->discard(); }

◆ onDraw()

void SkSurface_Ganesh::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 303 of file SkSurface_Ganesh.cpp.

307 {
308 // If the dst is also GPU we try to not force a new image snapshot (by calling the base class
309 // onDraw) since that may not always perform the copy-on-write optimization.
310 auto tryDraw = [&] {
311 auto surfaceContext = fDevice->recordingContext();
312 auto canvasContext = GrAsDirectContext(canvas->recordingContext());
313 if (!canvasContext) {
314 return false;
315 }
316 if (canvasContext->priv().contextID() != surfaceContext->priv().contextID()) {
317 return false;
318 }
319 GrSurfaceProxyView srcView = fDevice->readSurfaceView();
320 if (!srcView.asTextureProxyRef()) {
321 return false;
322 }
323 // Possibly we could skip making an image here if SkGpuDevice exposed a lower level way
324 // of drawing a texture proxy.
325 const SkImageInfo info = fDevice->imageInfo();
326 sk_sp<SkImage> image = sk_make_sp<SkImage_Ganesh>(sk_ref_sp(canvasContext),
328 std::move(srcView),
329 info.colorInfo());
330 canvas->drawImage(image.get(), x, y, sampling, paint);
331 return true;
332 };
333 if (!tryDraw()) {
334 INHERITED::onDraw(canvas, x, y, sampling, paint);
335 }
336}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kNeedNewImageUniqueID
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
sk_sp< GrTextureProxy > asTextureProxyRef() const
virtual GrRecordingContext * recordingContext() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
virtual void onDraw(SkCanvas *, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *)
const Paint & paint
double y
double x

◆ onGetRecordingContext()

GrRecordingContext * SkSurface_Ganesh::onGetRecordingContext ( ) const
overridevirtual

Reimplemented from SkSurface_Base.

Definition at line 77 of file SkSurface_Ganesh.cpp.

77 {
78 return fDevice->recordingContext();
79}

◆ onIsCompatible()

bool SkSurface_Ganesh::onIsCompatible ( const GrSurfaceCharacterization characterization) const
overridevirtual

Reimplemented from SkSurface_Base.

Definition at line 338 of file SkSurface_Ganesh.cpp.

338 {
339 auto direct = fDevice->recordingContext()->asDirectContext();
340 if (!direct) {
341 return false;
342 }
343
344 if (!characterization.isValid()) {
345 return false;
346 }
347
348 if (characterization.vulkanSecondaryCBCompatible()) {
349 return false;
350 }
351
352 SkImageInfo ii = fDevice->imageInfo();
353 if (ii.colorType() == kUnknown_SkColorType) {
354 return false;
355 }
356
357 GrSurfaceProxyView targetView = fDevice->readSurfaceView();
358 // As long as the current state if the context allows for greater or equal resources,
359 // we allow the DDL to be replayed.
360 // DDL TODO: should we just remove the resource check and ignore the cache limits on playback?
361 size_t maxResourceBytes = direct->getResourceCacheLimit();
362
363 if (characterization.isTextureable()) {
364 if (!targetView.asTextureProxy()) {
365 // If the characterization was textureable we require the replay dest to also be
366 // textureable. If the characterized surface wasn't textureable we allow the replay
367 // dest to be textureable.
368 return false;
369 }
370
371 if (characterization.isMipMapped() &&
372 skgpu::Mipmapped::kNo == targetView.asTextureProxy()->mipmapped()) {
373 // Fail if the DDL's surface was mipmapped but the replay surface is not.
374 // Allow drawing to proceed if the DDL was not mipmapped but the replay surface is.
375 return false;
376 }
377 }
378
379 if (characterization.usesGLFBO0() != targetView.asRenderTargetProxy()->glRTFBOIDIs0()) {
380 // FBO0-ness effects how MSAA and window rectangles work. If the characterization was
381 // tagged as FBO0 it would never have been allowed to use window rectangles. If MSAA
382 // was also never used then a DDL recorded with this characterization should be replayable
383 // on a non-FBO0 surface.
384 if (!characterization.usesGLFBO0() || characterization.sampleCount() > 1) {
385 return false;
386 }
387 }
388
390 int numSamples = targetView.asRenderTargetProxy()->numSamples();
391 GrProtected isProtected = targetView.proxy()->isProtected();
392
393 return characterization.contextInfo() &&
394 characterization.contextInfo()->priv().matches(direct) &&
395 characterization.cacheMaxResourceBytes() <= maxResourceBytes &&
396 characterization.origin() == targetView.origin() &&
397 characterization.backendFormat() == format && characterization.width() == ii.width() &&
398 characterization.height() == ii.height() &&
399 characterization.colorType() == ii.colorType() &&
400 characterization.sampleCount() == numSamples &&
401 SkColorSpace::Equals(characterization.colorSpace(), ii.colorInfo().colorSpace()) &&
402 characterization.isProtected() == isProtected &&
403 characterization.surfaceProps() == fDevice->surfaceProps();
404}
bool matches(GrContext_Base *candidate) const
GrContextThreadSafeProxyPriv priv()
GrContextThreadSafeProxy * contextInfo() const
SkColorSpace * colorSpace() const
static bool Equals(const SkColorSpace *, const SkColorSpace *)
const SkSurfaceProps & surfaceProps() const
Definition SkDevice.h:131
const SkColorInfo & colorInfo() const
int width() const
int height() const

◆ onNewCanvas()

SkCanvas * SkSurface_Ganesh::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 132 of file SkSurface_Ganesh.cpp.

132{ return new SkCanvas(fDevice); }
friend class SkCanvas

◆ onNewImageSnapshot()

sk_sp< SkImage > SkSurface_Ganesh::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 147 of file SkSurface_Ganesh.cpp.

147 {
148 GrRenderTargetProxy* rtp = fDevice->targetProxy();
149 if (!rtp) {
150 return nullptr;
151 }
152
153 auto rContext = fDevice->recordingContext();
154
155 GrSurfaceProxyView srcView = fDevice->readSurfaceView();
156
157 skgpu::Budgeted budgeted = rtp->isBudgeted();
158
159 if (subset || !srcView.asTextureProxy() || rtp->refsWrappedObjects()) {
160 // If the original render target is a buffer originally created by the client, then we don't
161 // want to ever retarget the SkSurface at another buffer we create. If the source is a
162 // texture (and the image is not subsetted) we make a dual-proxied SkImage that will
163 // attempt to share the backing store until the surface writes to the shared backing store
164 // at which point it uses a copy.
165 if (!subset && srcView.asTextureProxy()) {
167 sk_ref_sp(rContext), srcView, fDevice->imageInfo().colorInfo());
168 }
169 auto rect = subset ? *subset : SkIRect::MakeSize(srcView.dimensions());
170 skgpu::Mipmapped mipmapped = srcView.mipmapped();
171 srcView = GrSurfaceProxyView::Copy(rContext,
172 std::move(srcView),
173 mipmapped,
174 rect,
176 budgeted,
177 /*label=*/"SurfaceGpu_NewImageSnapshot");
178 }
179
180 const SkImageInfo info = fDevice->imageInfo();
181 if (!srcView.asTextureProxy()) {
182 return nullptr;
183 }
184 // The surfaceDrawContext coming out of SkGpuDevice should always be exact and the
185 // above copy creates a kExact surfaceContext.
186 SkASSERT(srcView.proxy()->priv().isExact());
187 return sk_make_sp<SkImage_Ganesh>(
188 sk_ref_sp(rContext), kNeedNewImageUniqueID, std::move(srcView), info.colorInfo());
189}
skgpu::Mipmapped mipmapped() const
SkISize dimensions() const
static GrSurfaceProxyView Copy(GrRecordingContext *context, GrSurfaceProxyView src, skgpu::Mipmapped mipmapped, SkIRect srcRect, SkBackingFit fit, skgpu::Budgeted budgeted, std::string_view label)
skgpu::Budgeted isBudgeted() const
static sk_sp< SkImage > MakeWithVolatileSrc(sk_sp< GrRecordingContext > rContext, GrSurfaceProxyView volatileSrc, SkColorInfo colorInfo)
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
Budgeted
Definition GpuTypes.h:35
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66

◆ onNewSurface()

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

Implements SkSurface_Base.

Definition at line 134 of file SkSurface_Ganesh.cpp.

134 {
135 GrSurfaceProxyView targetView = fDevice->readSurfaceView();
136 int sampleCount = targetView.asRenderTargetProxy()->numSamples();
137 GrSurfaceOrigin origin = targetView.origin();
138 // TODO: Make caller specify this (change virtual signature of onNewSurface).
140
141 bool isProtected = targetView.asRenderTargetProxy()->isProtected() == GrProtected::kYes;
143 fDevice->recordingContext(), kBudgeted, info, sampleCount, origin, &this->props(),
144 /* shouldCreateWithMips= */ false, isProtected);
145}
GrSurfaceOrigin
Definition GrTypes.h:147
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)

◆ onWait()

bool SkSurface_Ganesh::onWait ( int  numSemaphores,
const GrBackendSemaphore waitSemaphores,
bool  deleteSemaphoresAfterWait 
)
overridevirtual

Caused the current backend 3D API to wait on the passed in semaphores before executing new commands on the gpu. Any previously submitting commands will not be blocked by these semaphores.

Reimplemented from SkSurface_Base.

Definition at line 250 of file SkSurface_Ganesh.cpp.

252 {
253 return fDevice->wait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
254}
bool wait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)
Definition Device.cpp:1291

◆ onWritePixels()

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

Implements SkSurface_Base.

Definition at line 191 of file SkSurface_Ganesh.cpp.

191 {
192 fDevice->writePixels(src, x, y);
193}
bool writePixels(const SkPixmap &src, int x, int y)
Definition SkDevice.h:147

◆ replaceBackendTexture()

bool SkSurface_Ganesh::replaceBackendTexture ( const GrBackendTexture backendTexture,
GrSurfaceOrigin  origin,
ContentChangeMode  mode,
TextureReleaseProc  ,
ReleaseContext   
)
overridevirtual

If the surface was made via MakeFromBackendTexture then it's backing texture may be substituted with a different texture. The contents of the previous backing texture are copied into the new texture. SkCanvas state is preserved. The original sample count is used. The GrBackendFormat and dimensions of replacement texture must match that of the original.

Upon success textureReleaseProc is called when it is safe to delete the texture in the backend API (accounting only for use of the texture by this surface). If SkSurface creation fails textureReleaseProc is called before this function returns.

Parameters
backendTexturethe new backing texture for the surface
modeRetain or discard current Content
TextureReleaseProcfunction called when texture can be released
ReleaseContextstate passed to textureReleaseProc

Reimplemented from SkSurface_Base.

Definition at line 468 of file SkSurface_Ganesh.cpp.

472 {
473 auto releaseHelper = skgpu::RefCntedCallback::Make(releaseProc, releaseContext);
474
475 auto rContext = fDevice->recordingContext();
476 if (rContext->abandoned()) {
477 return false;
478 }
479 if (!backendTexture.isValid()) {
480 return false;
481 }
482 if (backendTexture.width() != this->width() || backendTexture.height() != this->height()) {
483 return false;
484 }
485 auto* oldRTP = fDevice->targetProxy();
486 auto oldProxy = sk_ref_sp(oldRTP->asTextureProxy());
487 if (!oldProxy) {
488 return false;
489 }
490 auto* oldTexture = oldProxy->peekTexture();
491 if (!oldTexture) {
492 return false;
493 }
494 if (!oldTexture->resourcePriv().refsWrappedObjects()) {
495 return false;
496 }
497 if (oldTexture->backendFormat() != backendTexture.getBackendFormat()) {
498 return false;
499 }
500 if (oldTexture->getBackendTexture().isSameTexture(backendTexture)) {
501 return false;
502 }
503 SkASSERT(oldTexture->asRenderTarget());
504 int sampleCnt = oldTexture->asRenderTarget()->numSamples();
507 rContext->priv().caps(), backendTexture, sampleCnt, grColorType, true)) {
508 return false;
509 }
510
511 sk_sp<SkColorSpace> colorSpace = fDevice->imageInfo().refColorSpace();
512
513 SkASSERT(sampleCnt > 0);
514 sk_sp<GrTextureProxy> proxy(rContext->priv().proxyProvider()->wrapRenderableBackendTexture(
515 backendTexture,
516 sampleCnt,
519 std::move(releaseHelper)));
520 if (!proxy) {
521 return false;
522 }
523
524 return fDevice->replaceBackingProxy(mode,
525 sk_ref_sp(proxy->asRenderTargetProxy()),
526 grColorType,
527 std::move(colorSpace),
528 origin,
529 this->props());
530}
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
static void releaseProc(const void *ptr, void *context)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static bool validate_backend_texture(const GrCaps *caps, const GrBackendTexture &tex, int sampleCnt, GrColorType grCT, bool texturable)
GrBackendFormat getBackendFormat() const
SkImageInfo imageInfo() const override
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
sk_sp< SkColorSpace > refColorSpace() const

◆ resolveMSAA()

void SkSurface_Ganesh::resolveMSAA ( )

Definition at line 248 of file SkSurface_Ganesh.cpp.

248{ fDevice->resolveMSAA(); }

◆ type()

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

Reimplemented from SkSurface_Base.

Definition at line 54 of file SkSurface_Ganesh.h.


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