Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSurface_Ganesh.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
14#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
23#include "include/gpu/GrTypes.h"
29#include "src/core/SkDevice.h"
50
51#ifdef SK_IN_RENDERENGINE
54#endif
55
56#include <algorithm>
57#include <cstddef>
58#include <utility>
59
61class SkCapabilities;
62class SkPaint;
63class SkPixmap;
64
70
76
80
82
84
87 auto dContext = surface->recordingContext()->asDirectContext();
88 if (!dContext) {
89 return nullptr;
90 }
91 if (dContext->abandoned()) {
92 return nullptr;
93 }
94
95 switch (access) {
96 case SkSurfaces::BackendHandleAccess::kFlushRead:
97 break;
98 case SkSurfaces::BackendHandleAccess::kFlushWrite:
99 case SkSurfaces::BackendHandleAccess::kDiscardWrite:
100 // for now we don't special-case on Discard, but we may in the future.
101 surface->notifyContentWillChange(SkSurface::kRetain_ContentChangeMode);
102 break;
103 }
104
105 dContext->priv().flushSurface(surface->getDevice()->targetProxy());
106
107 // Grab the render target *after* firing notifications, as it may get switched if CoW kicks in.
108 return surface->getDevice()->targetProxy()->peekRenderTarget();
109}
110
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}
122
125 if (!rt) {
126 return GrBackendRenderTarget(); // invalid
127 }
128
129 return rt->getBackendRenderTarget();
130}
131
133
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}
146
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}
190
191void SkSurface_Ganesh::onWritePixels(const SkPixmap& src, int x, int y) {
192 fDevice->writePixels(src, x, y);
193}
194
196 SkIRect srcRect,
197 RescaleGamma rescaleGamma,
198 RescaleMode rescaleMode,
200 ReadPixelsContext context) {
201 fDevice->asyncRescaleAndReadPixels(info, srcRect, rescaleGamma, rescaleMode, callback, context);
202}
203
205 bool readAlpha,
206 sk_sp<SkColorSpace> dstColorSpace,
207 SkIRect srcRect,
208 SkISize dstSize,
209 RescaleGamma rescaleGamma,
210 RescaleMode rescaleMode,
212 ReadPixelsContext context) {
213 fDevice->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
214 readAlpha,
215 std::move(dstColorSpace),
216 srcRect,
217 dstSize,
218 rescaleGamma,
219 rescaleMode,
220 callback,
221 context);
222}
223
224// Create a new render target and, if necessary, copy the contents of the old
225// render target into it. Note that this flushes the SkGpuDevice but
226// doesn't force an OpenGL flush.
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}
245
247
249
250bool SkSurface_Ganesh::onWait(int numSemaphores,
251 const GrBackendSemaphore* waitSemaphores,
252 bool deleteSemaphoresAfterWait) {
253 return fDevice->wait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
254}
255
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}
302
304 SkScalar x,
305 SkScalar y,
306 const SkSamplingOptions& sampling,
307 const SkPaint* paint) {
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}
337
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}
405
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}
421
425
426///////////////////////////////////////////////////////////////////////////////
427
428static bool validate_backend_texture(const GrCaps* caps,
429 const GrBackendTexture& tex,
430 int sampleCnt,
431 GrColorType grCT,
432 bool texturable) {
433 if (!tex.isValid()) {
434 return false;
435 }
436
437 GrBackendFormat backendFormat = tex.getBackendFormat();
438 if (!backendFormat.isValid()) {
439 RENDERENGINE_ABORTF("%s failed due to an invalid format", __func__);
440 return false;
441 }
442
443 if (!caps->areColorTypeAndFormatCompatible(grCT, backendFormat)) {
444 RENDERENGINE_ABORTF("%s failed due to an invalid format and colorType combination",
445 __func__);
446 return false;
447 }
448
449 if (!caps->isFormatAsColorTypeRenderable(grCT, backendFormat, sampleCnt)) {
451 "%s failed due to no supported rendering path for the selected "
452 "format and colorType",
453 __func__);
454 return false;
455 }
456
457 if (texturable && !caps->isFormatTexturable(backendFormat, tex.textureType())) {
459 "%s failed due to no texturing support for the selected format and "
460 "colorType",
461 __func__);
462 return false;
463 }
464
465 return true;
466}
467
469 GrSurfaceOrigin origin,
472 ReleaseContext releaseContext) {
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}
531
533 const GrBackendRenderTarget& rt,
534 GrColorType grCT) {
535 if (!caps->areColorTypeAndFormatCompatible(grCT, rt.getBackendFormat())) {
536 return false;
537 }
538
539 if (!caps->isFormatAsColorTypeRenderable(grCT, rt.getBackendFormat(), rt.sampleCnt())) {
540 return false;
541 }
542
543 // We require the stencil bits to be either 0, 8, or 16.
544 int stencilBits = rt.stencilBits();
545 if (stencilBits != 0 && stencilBits != 8 && stencilBits != 16) {
546 return false;
547 }
548
549 return true;
550}
551
552namespace SkSurfaces {
555 skgpu::Budgeted budgeted) {
556 if (!rContext || !c.isValid()) {
557 return nullptr;
558 }
559
560 if (c.usesGLFBO0()) {
561 // If we are making the surface we will never use FBO0.
562 return nullptr;
563 }
564
565 if (c.vulkanSecondaryCBCompatible()) {
566 return nullptr;
567 }
568
569 auto device = rContext->priv().createDevice(budgeted,
570 c.imageInfo(),
572 c.sampleCount(),
574 c.isProtected(),
575 c.origin(),
576 c.surfaceProps(),
578 if (!device) {
579 return nullptr;
580 }
581
582 sk_sp<SkSurface> result = sk_make_sp<SkSurface_Ganesh>(std::move(device));
583#ifdef SK_DEBUG
584 if (result) {
585 SkASSERT(result->isCompatible(c));
586 }
587#endif
588
589 return result;
590}
591
593 skgpu::Budgeted budgeted,
594 const SkImageInfo& info,
595 int sampleCount,
596 GrSurfaceOrigin origin,
597 const SkSurfaceProps* props,
598 bool shouldCreateWithMips,
599 bool isProtected) {
600 if (!rContext) {
601 return nullptr;
602 }
603 sampleCount = std::max(1, sampleCount);
604 skgpu::Mipmapped mipmapped =
605 shouldCreateWithMips ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
606
607 if (!rContext->priv().caps()->mipmapSupport()) {
608 mipmapped = skgpu::Mipmapped::kNo;
609 }
610
611 auto device = rContext->priv().createDevice(budgeted,
612 info,
614 sampleCount,
615 mipmapped,
616 GrProtected(isProtected),
617 origin,
620 if (!device) {
621 return nullptr;
622 }
623 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
624}
625
627 const GrBackendTexture& tex,
628 GrSurfaceOrigin origin,
629 int sampleCnt,
631 sk_sp<SkColorSpace> colorSpace,
632 const SkSurfaceProps* props,
633 TextureReleaseProc textureReleaseProc,
634 ReleaseContext releaseContext) {
635 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, releaseContext);
636
637 if (!rContext) {
638 RENDERENGINE_ABORTF("%s failed due to a null context ", __func__);
639 return nullptr;
640 }
641 sampleCnt = std::max(1, sampleCnt);
642
644 if (grColorType == GrColorType::kUnknown) {
645 RENDERENGINE_ABORTF("%s failed due to an unsupported colorType %d", __func__, colorType);
646 return nullptr;
647 }
648
649 if (!validate_backend_texture(rContext->priv().caps(), tex, sampleCnt, grColorType, true)) {
650 return nullptr;
651 }
652
654 tex,
655 sampleCnt,
658 std::move(releaseHelper)));
659 if (!proxy) {
660 // TODO(scroggo,kjlubick) inline this into Android's AutoBackendTexture.cpp so we
661 // don't have a sometimes-dependency on the GL backend.
662#ifdef SK_IN_RENDERENGINE
663 GrGLTextureInfo textureInfo;
664 bool retrievedTextureInfo = GrBackendTextures::GetGLTextureInfo(tex, &textureInfo);
666 "%s failed to wrap the texture into a renderable target "
667 "\n\tGrBackendTexture: (%i x %i) hasMipmaps: %i isProtected: %i texType: %i"
668 "\n\t\tGrGLTextureInfo: success: %i fTarget: %u fFormat: %u"
669 "\n\tmaxRenderTargetSize: %d",
670 __func__,
671 tex.width(),
672 tex.height(),
673 tex.hasMipmaps(),
674 tex.isProtected(),
675 static_cast<int>(tex.textureType()),
676 retrievedTextureInfo,
677 textureInfo.fTarget,
678 textureInfo.fFormat,
679 rContext->priv().caps()->maxRenderTargetSize());
680#endif
681 return nullptr;
682 }
683
684 auto device = rContext->priv().createDevice(grColorType,
685 std::move(proxy),
686 std::move(colorSpace),
687 origin,
690 if (!device) {
691 RENDERENGINE_ABORTF("%s failed to wrap the renderTarget into a surface", __func__);
692 return nullptr;
693 }
694
695 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
696}
697
699 const GrBackendRenderTarget& rt,
700 GrSurfaceOrigin origin,
702 sk_sp<SkColorSpace> colorSpace,
703 const SkSurfaceProps* props,
705 ReleaseContext releaseContext) {
706 auto releaseHelper = skgpu::RefCntedCallback::Make(relProc, releaseContext);
707
708 if (!rContext) {
709 return nullptr;
710 }
711
713 if (grColorType == GrColorType::kUnknown) {
714 return nullptr;
715 }
716
717 if (!validate_backend_render_target(rContext->priv().caps(), rt, grColorType)) {
718 return nullptr;
719 }
720
721 auto proxyProvider = rContext->priv().proxyProvider();
722 auto proxy = proxyProvider->wrapBackendRenderTarget(rt, std::move(releaseHelper));
723 if (!proxy) {
724 return nullptr;
725 }
726
727 auto device = rContext->priv().createDevice(grColorType,
728 std::move(proxy),
729 std::move(colorSpace),
730 origin,
733 if (!device) {
734 return nullptr;
735 }
736
737 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
738}
739
741 if (surface == nullptr) {
742 return GrBackendTexture();
743 }
744 auto sb = asSB(surface);
745 if (!sb->isGaneshBacked()) {
746 return GrBackendTexture();
747 }
748 return static_cast<SkSurface_Ganesh*>(surface)->getBackendTexture(access);
749}
750
752 if (surface == nullptr) {
753 return GrBackendRenderTarget();
754 }
755 auto sb = asSB(surface);
756 if (!sb->isGaneshBacked()) {
757 return GrBackendRenderTarget();
758 }
759 return static_cast<SkSurface_Ganesh*>(surface)->getBackendRenderTarget(access);
760}
761
763 if (!surface) {
764 return;
765 }
766 auto sb = asSB(surface);
767 if (!sb->isGaneshBacked()) {
768 return;
769 }
770 auto gs = static_cast<SkSurface_Ganesh*>(surface);
771 gs->resolveMSAA();
772}
773
774} // namespace SkSurfaces
775
776namespace skgpu::ganesh {
778 if (!surface) {
780 }
781 if (auto rContext = surface->recordingContext(); rContext != nullptr) {
782 return rContext->asDirectContext()->flush(surface, {});
783 }
785}
786
788 if (!surface) {
790 }
791 if (auto rContext = surface->recordingContext(); rContext != nullptr) {
792 return rContext->asDirectContext()->flush(surface.get(), {});
793 }
795}
796
798 if (!surface) {
799 return;
800 }
801 if (auto rContext = surface->recordingContext(); rContext != nullptr) {
802 rContext->asDirectContext()->flushAndSubmit(surface, GrSyncCpu::kNo);
803 }
804}
805
807 if (!surface) {
808 return;
809 }
810 if (auto rContext = surface->recordingContext(); rContext != nullptr) {
811 rContext->asDirectContext()->flushAndSubmit(surface.get(), GrSyncCpu::kNo);
812 }
813}
814
815} // namespace skgpu::ganesh
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
skgpu::Protected GrProtected
Definition GrTypes.h:139
GrSurfaceOrigin
Definition GrTypes.h:147
GrSemaphoresSubmitted
Definition GrTypes.h:229
#define SkASSERT(cond)
Definition SkAssert.h:116
SkColorType
Definition SkColorType.h:19
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
static void releaseProc(const void *ptr, void *context)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkYUVColorSpace
Definition SkImageInfo.h:68
@ kNeedNewImageUniqueID
static SkImage_Base * as_IB(SkImage *image)
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
#define RENDERENGINE_ABORTF(...)
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
static SkSurface_Base * asSB(SkSurface *surface)
bool validate_backend_render_target(const GrCaps *caps, const GrBackendRenderTarget &rt, GrColorType grCT)
static GrRenderTarget * prepare_rt_for_external_access(SkSurface_Ganesh *surface, SkSurfaces::BackendHandleAccess access)
static bool validate_backend_texture(const GrCaps *caps, const GrBackendTexture &tex, int sampleCnt, GrColorType grCT, bool texturable)
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
bool isValid() const
GrBackendFormat getBackendFormat() const
GrBackendFormat getBackendFormat() const
bool hasMipmaps() const
GrTextureType textureType() const
const GrCaps * caps() const
bool mipmapSupport() const
Definition GrCaps.h:72
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
int maxRenderTargetSize() const
Definition GrCaps.h:223
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
Definition GrCaps.cpp:428
virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const =0
bool matches(GrContext_Base *candidate) const
GrContextThreadSafeProxyPriv priv()
virtual GrDirectContext * asDirectContext()
sk_sp< GrTextureProxy > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback > releaseHelper)
sk_sp< GrSurfaceProxy > wrapBackendRenderTarget(const GrBackendRenderTarget &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
GrProxyProvider * proxyProvider()
sk_sp< skgpu::ganesh::Device > createDevice(GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &, skgpu::ganesh::Device::InitContents)
GrRecordingContextPriv priv()
SK_API sk_sp< const SkCapabilities > skCapabilities() const
bool supportsVkInputAttachment() const
virtual GrBackendRenderTarget getBackendRenderTarget() const =0
GrContextThreadSafeProxy * contextInfo() const
const SkImageInfo & imageInfo() const
skgpu::Mipmapped mipmapped() const
GrTextureProxy * asTextureProxy() const
SkISize dimensions() const
sk_sp< GrTextureProxy > asTextureProxyRef() const
GrSurfaceOrigin origin() const
GrSurfaceProxy * proxy() const
GrRenderTargetProxy * asRenderTargetProxy() const
static GrSurfaceProxyView Copy(GrRecordingContext *context, GrSurfaceProxyView src, skgpu::Mipmapped mipmapped, SkIRect srcRect, SkBackingFit fit, skgpu::Budgeted budgeted, std::string_view label)
sk_sp< GrRenderTargetProxy > asRenderTargetProxyRef() const
GrProtected isProtected() const
const GrBackendFormat & backendFormat() const
GrSurfaceProxyPriv priv()
skgpu::Budgeted isBudgeted() const
virtual GrTexture * asTexture()
Definition GrSurface.h:59
skgpu::Mipmapped mipmapped() const
virtual GrBackendTexture getBackendTexture() const =0
virtual GrRecordingContext * recordingContext() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
SkColorSpace * colorSpace() const
static bool Equals(const SkColorSpace *, const SkColorSpace *)
const SkImageInfo & imageInfo() const
Definition SkDevice.h:117
bool writePixels(const SkPixmap &src, int x, int y)
Definition SkDevice.h:147
const SkSurfaceProps & surfaceProps() const
Definition SkDevice.h:131
virtual void generatingSurfaceIsDeleted()
bool surfaceMustCopyOnWrite(GrSurfaceProxy *surfaceProxy) const
static sk_sp< SkImage > MakeWithVolatileSrc(sk_sp< GrRecordingContext > rContext, GrSurfaceProxyView volatileSrc, SkColorInfo colorInfo)
RescaleMode
Definition SkImage.h:587
RescaleGamma
Definition SkImage.h:585
friend class SkCanvas
sk_sp< SkImage > refCachedImage()
virtual void onDraw(SkCanvas *, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *)
bool hasCachedImage() const
SkCanvas * onNewCanvas() override
void onDraw(SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *paint) override
GrBackendRenderTarget getBackendRenderTarget(BackendHandleAccess)
bool onCharacterize(GrSurfaceCharacterization *) const override
void onDiscard() override
void onAsyncRescaleAndReadPixels(const SkImageInfo &info, SkIRect srcRect, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
sk_sp< SkSurface > onNewSurface(const SkImageInfo &) override
bool replaceBackendTexture(const GrBackendTexture &, GrSurfaceOrigin, ContentChangeMode, TextureReleaseProc, ReleaseContext) override
GrRecordingContext * onGetRecordingContext() const override
sk_sp< SkImage > onNewImageSnapshot(const SkIRect *subset) override
~SkSurface_Ganesh() override
void onWritePixels(const SkPixmap &, int x, int y) override
GrBackendTexture getBackendTexture(BackendHandleAccess)
bool onCopyOnWrite(ContentChangeMode) override
void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
SkImageInfo imageInfo() const override
skgpu::ganesh::Device * getDevice()
bool draw(sk_sp< const GrDeferredDisplayList >)
bool onWait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait) override
sk_sp< const SkCapabilities > onCapabilities() override
SkSurface_Ganesh(sk_sp< skgpu::ganesh::Device >)
bool onIsCompatible(const GrSurfaceCharacterization &) const override
@ kDiscard_ContentChangeMode
discards surface on change
Definition SkSurface.h:204
@ kRetain_ContentChangeMode
preserves surface on change
Definition SkSurface.h:205
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >) ReadPixelsCallback
Definition SkSurface.h:469
bool isCompatible(const GrSurfaceCharacterization &characterization) const
void(*)(ReleaseContext) TextureReleaseProc
Definition SkSurface.h:251
void * ReleaseContext
Definition SkSurface.h:249
BackendHandleAccess
Definition SkSurface.h:229
void * ReadPixelsContext
Definition SkSurface.h:464
T * get() const
Definition SkRefCnt.h:303
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
GrSurfaceProxyView readSurfaceView()
Definition Device.cpp:1283
GrRenderTargetProxy * targetProxy()
Definition Device.cpp:1287
bool wait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)
Definition Device.cpp:1291
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
void asyncRescaleAndReadPixels(const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
Definition Device.cpp:1373
bool replaceBackingProxy(SkSurface::ContentChangeMode, sk_sp< GrRenderTargetProxy >, GrColorType, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
Definition Device.cpp:1308
GrRecordingContext * recordingContext() const override
Definition Device.h:101
const Paint & paint
VkDevice device
Definition main.cc:53
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
float SkScalar
Definition extension.cpp:12
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GAsyncResult * result
uint32_t uint32_t * format
FlTexture * texture
double y
double x
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
void * ReleaseContext
SK_API void ResolveMSAA(SkSurface *surface)
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)
void(*)(ReleaseContext) RenderTargetReleaseProc
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API GrBackendRenderTarget GetBackendRenderTarget(SkSurface *, BackendHandleAccess)
void(*)(ReleaseContext) TextureReleaseProc
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)
SK_API void FlushAndSubmit(sk_sp< SkSurface >)
SK_API GrSemaphoresSubmitted Flush(sk_sp< SkSurface >)
Budgeted
Definition GpuTypes.h:35
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256
int32_t height
int32_t width
GrGLenum fFormat
Definition GrGLTypes.h:183
GrGLenum fTarget
Definition GrGLTypes.h:181
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66
const SkColorInfo & colorInfo() const
sk_sp< SkColorSpace > refColorSpace() const
int width() const
SkColorType colorType() const
int height() const