Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
GrGpu Class Referenceabstract

#include <GrGpu.h>

Inheritance diagram for GrGpu:
GrD3DGpu GrGLGpu GrMockGpu GrMtlGpu GrVkGpu

Classes

class  Stats
 

Public Types

enum class  DisconnectType { kAbandon , kCleanup }
 

Public Member Functions

 GrGpu (GrDirectContext *direct)
 
virtual ~GrGpu ()
 
GrDirectContextgetContext ()
 
const GrDirectContextgetContext () const
 
const GrCapscaps () const
 
sk_sp< const GrCapsrefCaps () const
 
virtual GrStagingBufferManagerstagingBufferManager ()
 
virtual GrRingBufferuniformsRingBuffer ()
 
virtual void disconnect (DisconnectType)
 
virtual GrThreadSafePipelineBuilderpipelineBuilder ()=0
 
virtual sk_sp< GrThreadSafePipelineBuilderrefPipelineBuilder ()=0
 
virtual bool isDeviceLost () const
 
void markContextDirty (uint32_t state=kAll_GrBackendState)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Budgeted budgeted, GrProtected isProtected, GrColorType textureColorType, GrColorType srcColorType, const GrMipLevel texels[], int texelLevelCount, std::string_view label)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, GrProtected isProtected, std::string_view label)
 
sk_sp< GrTexturecreateCompressedTexture (SkISize dimensions, const GrBackendFormat &format, skgpu::Budgeted budgeted, skgpu::Mipmapped mipmapped, GrProtected isProtected, const void *data, size_t dataSize)
 
sk_sp< GrTexturewrapBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType)
 
sk_sp< GrTexturewrapCompressedBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable)
 
sk_sp< GrTexturewrapRenderableBackendTexture (const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable)
 
sk_sp< GrRenderTargetwrapBackendRenderTarget (const GrBackendRenderTarget &)
 
sk_sp< GrRenderTargetwrapVulkanSecondaryCBAsRenderTarget (const SkImageInfo &, const GrVkDrawableInfo &)
 
sk_sp< GrGpuBuffercreateBuffer (size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern)
 
void resolveRenderTarget (GrRenderTarget *, const SkIRect &resolveRect)
 
bool regenerateMipMapLevels (GrTexture *)
 
void resetTextureBindings ()
 
bool readPixels (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType dstColorType, void *buffer, size_t rowBytes)
 
bool writePixels (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling=false)
 
bool writePixels (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType srcColorType, const void *buffer, size_t rowBytes, bool prepForTexSampling=false)
 
bool transferFromBufferToBuffer (sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size)
 
bool transferPixelsTo (GrTexture *texture, SkIRect rect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset, size_t rowBytes)
 
bool transferPixelsFrom (GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset)
 
bool copySurface (GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter filter)
 
GrOpsRenderPassgetOpsRenderPass (GrRenderTarget *renderTarget, bool useMSAASurface, GrAttachment *stencil, GrSurfaceOrigin, const SkIRect &bounds, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers)
 
void executeFlushInfo (SkSpan< GrSurfaceProxy * >, SkSurfaces::BackendSurfaceAccess access, const GrFlushInfo &, const skgpu::MutableTextureState *newState)
 
virtual void willExecute ()
 
bool submitToGpu (GrSyncCpu sync)
 
virtual void submit (GrOpsRenderPass *)=0
 
virtual std::unique_ptr< GrSemaphoremakeSemaphore (bool isOwned=true)=0
 
virtual std::unique_ptr< GrSemaphorewrapBackendSemaphore (const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership)=0
 
virtual void insertSemaphore (GrSemaphore *semaphore)=0
 
virtual void waitSemaphore (GrSemaphore *semaphore)=0
 
virtual void addFinishedProc (GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)=0
 
virtual void checkFinishProcs ()=0
 
virtual void finishOutstandingGpuWork ()=0
 
virtual void takeOwnershipOfBuffer (sk_sp< GrGpuBuffer >)
 
bool checkAndResetOOMed ()
 
virtual std::unique_ptr< GrSemaphoreprepareTextureForCrossContextUsage (GrTexture *)=0
 
virtual void releaseUnlockedBackendObjects ()
 
Statsstats ()
 
void dumpJSON (SkJSONWriter *) const
 
GrBackendTexture createBackendTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label)
 
bool clearBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color)
 
GrBackendTexture createCompressedBackendTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected)
 
bool updateCompressedBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t length)
 
virtual bool setBackendTextureState (const GrBackendTexture &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState, sk_sp< skgpu::RefCntedCallback > finishedCallback)
 
virtual bool setBackendRenderTargetState (const GrBackendRenderTarget &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState, sk_sp< skgpu::RefCntedCallback > finishedCallback)
 
virtual void deleteBackendTexture (const GrBackendTexture &)=0
 
virtual bool compile (const GrProgramDesc &, const GrProgramInfo &)=0
 
virtual bool precompileShader (const SkData &key, const SkData &data)
 
virtual sk_sp< GrAttachmentmakeStencilAttachment (const GrBackendFormat &colorFormat, SkISize dimensions, int numStencilSamples)=0
 
virtual GrBackendFormat getPreferredStencilFormat (const GrBackendFormat &)=0
 
virtual sk_sp< GrAttachmentmakeMSAAAttachment (SkISize dimensions, const GrBackendFormat &format, int numSamples, GrProtected isProtected, GrMemoryless isMemoryless)=0
 
void handleDirtyContext ()
 
virtual void storeVkPipelineCacheData ()
 
virtual void xferBarrier (GrRenderTarget *, GrXferBarrierType)=0
 

Protected Member Functions

void didWriteToSurface (GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
 
void setOOMed ()
 
void initCaps (sk_sp< const GrCaps > caps)
 

Static Protected Member Functions

static bool CompressedDataIsCorrect (SkISize dimensions, SkTextureCompressionType, skgpu::Mipmapped, const void *data, size_t length)
 

Protected Attributes

Stats fStats
 

Private Member Functions

virtual GrBackendTexture onCreateBackendTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label)=0
 
virtual GrBackendTexture onCreateCompressedBackendTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected)=0
 
virtual bool onClearBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color)=0
 
virtual bool onUpdateCompressedBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t length)=0
 
virtual void onResetContext (uint32_t resetBits)
 
virtual void onResetTextureBindings ()
 
virtual sk_sp< GrTextureonCreateTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, skgpu::Budgeted, GrProtected, int mipLevelCoont, uint32_t levelClearMask, std::string_view label)=0
 
virtual sk_sp< GrTextureonCreateCompressedTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, const void *data, size_t dataSize)=0
 
virtual sk_sp< GrTextureonWrapBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType)=0
 
virtual sk_sp< GrTextureonWrapCompressedBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable)=0
 
virtual sk_sp< GrTextureonWrapRenderableBackendTexture (const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable)=0
 
virtual sk_sp< GrRenderTargetonWrapBackendRenderTarget (const GrBackendRenderTarget &)=0
 
virtual sk_sp< GrRenderTargetonWrapVulkanSecondaryCBAsRenderTarget (const SkImageInfo &, const GrVkDrawableInfo &)
 
virtual sk_sp< GrGpuBufferonCreateBuffer (size_t size, GrGpuBufferType intendedType, GrAccessPattern)=0
 
virtual bool onReadPixels (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType dstColorType, void *, size_t rowBytes)=0
 
virtual bool onWritePixels (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel[], int mipLevelCount, bool prepForTexSampling)=0
 
virtual bool onTransferFromBufferToBuffer (sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size)=0
 
virtual bool onTransferPixelsTo (GrTexture *, SkIRect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset, size_t rowBytes)=0
 
virtual bool onTransferPixelsFrom (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset)=0
 
virtual void onResolveRenderTarget (GrRenderTarget *target, const SkIRect &resolveRect)=0
 
virtual bool onRegenerateMipMapLevels (GrTexture *)=0
 
virtual bool onCopySurface (GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter)=0
 
virtual GrOpsRenderPassonGetOpsRenderPass (GrRenderTarget *renderTarget, bool useMSAASurface, GrAttachment *stencil, GrSurfaceOrigin, const SkIRect &bounds, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers)=0
 
virtual void prepareSurfacesForBackendAccessAndStateUpdates (SkSpan< GrSurfaceProxy * > proxies, SkSurfaces::BackendSurfaceAccess access, const skgpu::MutableTextureState *newState)
 
virtual bool onSubmitToGpu (GrSyncCpu sync)=0
 
virtual void onReportSubmitHistograms ()
 

Detailed Description

Definition at line 62 of file GrGpu.h.

Member Enumeration Documentation

◆ DisconnectType

enum class GrGpu::DisconnectType
strong
Enumerator
kAbandon 
kCleanup 

Definition at line 80 of file GrGpu.h.

80 {
81 // No cleanup should be attempted, immediately cease making backend API calls
82 kAbandon,
83 // Free allocated resources (not known by GrResourceCache) before returning and
84 // ensure no backend backend 3D API calls will be made after disconnect() returns.
85 kCleanup,
86 };

Constructor & Destructor Documentation

◆ GrGpu()

GrGpu::GrGpu ( GrDirectContext direct)

Definition at line 41 of file GrGpu.cpp.

41: fResetBits(kAll_GrBackendState), fContext(direct) {}
static const uint32_t kAll_GrBackendState
Definition: GrTypes.h:176

◆ ~GrGpu()

GrGpu::~GrGpu ( )
virtual

Definition at line 43 of file GrGpu.cpp.

43 {
44 this->callSubmittedProcs(false);
45}

Member Function Documentation

◆ addFinishedProc()

virtual void GrGpu::addFinishedProc ( GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)
pure virtual

◆ caps()

const GrCaps * GrGpu::caps ( ) const
inline

Gets the capabilities of the draw target.

Definition at line 73 of file GrGpu.h.

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

◆ checkAndResetOOMed()

bool GrGpu::checkAndResetOOMed ( )

Checks if we detected an OOM from the underlying 3D API and if so returns true and resets the internal OOM state to false. Otherwise, returns false.

Definition at line 783 of file GrGpu.cpp.

783 {
784 if (fOOMed) {
785 fOOMed = false;
786 return true;
787 }
788 return false;
789}

◆ checkFinishProcs()

virtual void GrGpu::checkFinishProcs ( )
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ clearBackendTexture()

bool GrGpu::clearBackendTexture ( const GrBackendTexture backendTexture,
sk_sp< skgpu::RefCntedCallback finishedCallback,
std::array< float, 4 >  color 
)

Definition at line 898 of file GrGpu.cpp.

900 {
901 if (!backendTexture.isValid()) {
902 return false;
903 }
904
905 if (backendTexture.hasMipmaps() && !this->caps()->mipmapSupport()) {
906 return false;
907 }
908
909 return this->onClearBackendTexture(backendTexture, std::move(finishedCallback), color);
910}
bool hasMipmaps() const
bool isValid() const
virtual bool onClearBackendTexture(const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color)=0
DlColor color

◆ compile()

virtual bool GrGpu::compile ( const GrProgramDesc ,
const GrProgramInfo  
)
pure virtual

In this case we have a program descriptor and a program info but no render target.

Implemented in GrD3DGpu, GrGLGpu, GrMtlGpu, and GrVkGpu.

◆ CompressedDataIsCorrect()

bool GrGpu::CompressedDataIsCorrect ( SkISize  dimensions,
SkTextureCompressionType  compressionType,
skgpu::Mipmapped  mipmapped,
const void *  data,
size_t  length 
)
staticprotected

Definition at line 858 of file GrGpu.cpp.

862 {
863 size_t computedSize = SkCompressedDataSize(
864 compressionType, dimensions, nullptr, mipmapped == skgpu::Mipmapped::kYes);
865 return computedSize == length;
866}
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
size_t length

◆ copySurface()

bool GrGpu::copySurface ( GrSurface dst,
const SkIRect dstRect,
GrSurface src,
const SkIRect srcRect,
GrSamplerState::Filter  filter 
)

Definition at line 410 of file GrGpu.cpp.

412 {
413 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
414 SkASSERT(dst && src);
415 SkASSERT(!src->framebufferOnly());
416
417 if (dst->readOnly()) {
418 return false;
419 }
420
421 this->handleDirtyContext();
422
423 return this->onCopySurface(dst, dstRect, src, srcRect, filter);
424}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
virtual bool onCopySurface(GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter)=0
void handleDirtyContext()
Definition: GrGpu.h:677
dst
Definition: cp.py:12
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ createBackendTexture()

GrBackendTexture GrGpu::createBackendTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrRenderable  renderable,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected,
std::string_view  label 
)

Creates a texture directly in the backend API without wrapping it in a GrTexture. Must be matched with a call to deleteBackendTexture().

If data is null the texture is uninitialized.

If data represents a color then all texture levels are cleared to that color.

If data represents pixmaps then it must have a either one pixmap or, if mipmapping is specified, a complete MIP hierarchy of pixmaps. Additionally, if provided, the mip levels must be sized correctly according to the MIP sizes implied by dimensions. They must all have the same color type and that color type must be compatible with the texture format.

Definition at line 868 of file GrGpu.cpp.

873 {
874 const GrCaps* caps = this->caps();
875
876 if (!format.isValid()) {
877 return {};
878 }
879
881 // Compressed formats must go through the createCompressedBackendTexture API
882 return {};
883 }
884
885 if (dimensions.isEmpty() || dimensions.width() > caps->maxTextureSize() ||
886 dimensions.height() > caps->maxTextureSize()) {
887 return {};
888 }
889
890 if (mipmapped == skgpu::Mipmapped::kYes && !this->caps()->mipmapSupport()) {
891 return {};
892 }
893
894 return this->onCreateBackendTexture(
895 dimensions, format, renderable, mipmapped, isProtected, label);
896}
bool isValid() const
Definition: GrCaps.h:57
int maxTextureSize() const
Definition: GrCaps.h:229
bool isFormatCompressed(const GrBackendFormat &format) const
Definition: GrCaps.cpp:457
virtual GrBackendTexture onCreateBackendTexture(SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label)=0
const GrCaps * caps() const
Definition: GrGpu.h:73
uint32_t uint32_t * format
bool isEmpty() const
Definition: SkSize.h:31
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37

◆ createBuffer()

sk_sp< GrGpuBuffer > GrGpu::createBuffer ( size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern 
)

Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked.

Parameters
sizesize of buffer to create.
intendedTypehint to the graphics subsystem about what the buffer will be used for.
accessPatternhint to the graphics subsystem about how the data will be accessed.
Returns
the buffer if successful, otherwise nullptr.

Definition at line 393 of file GrGpu.cpp.

395 {
396 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
397 this->handleDirtyContext();
398 if ((intendedType == GrGpuBufferType::kXferCpuToGpu ||
399 intendedType == GrGpuBufferType::kXferGpuToCpu) &&
400 accessPattern == kStatic_GrAccessPattern) {
401 return nullptr;
402 }
403 sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern);
404 if (buffer && !this->caps()->reuseScratchBuffers()) {
405 buffer->resourcePriv().removeScratchKey();
406 }
407 return buffer;
408}
@ kStatic_GrAccessPattern
Definition: GrTypesPriv.h:428
virtual sk_sp< GrGpuBuffer > onCreateBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern)=0
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
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

◆ createCompressedBackendTexture()

GrBackendTexture GrGpu::createCompressedBackendTexture ( SkISize  dimensions,
const GrBackendFormat format,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected 
)

Same as the createBackendTexture case except compressed backend textures can never be renderable.

Definition at line 912 of file GrGpu.cpp.

915 {
916 const GrCaps* caps = this->caps();
917
918 if (!format.isValid()) {
919 return {};
920 }
921
923 if (compressionType == SkTextureCompressionType::kNone) {
924 // Uncompressed formats must go through the createBackendTexture API
925 return {};
926 }
927
928 if (dimensions.isEmpty() ||
929 dimensions.width() > caps->maxTextureSize() ||
930 dimensions.height() > caps->maxTextureSize()) {
931 return {};
932 }
933
934 if (mipmapped == skgpu::Mipmapped::kYes && !this->caps()->mipmapSupport()) {
935 return {};
936 }
937
938 return this->onCreateCompressedBackendTexture(dimensions, format, mipmapped, isProtected);
939}
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
SkTextureCompressionType
virtual GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected)=0

◆ createCompressedTexture()

sk_sp< GrTexture > GrGpu::createCompressedTexture ( SkISize  dimensions,
const GrBackendFormat format,
skgpu::Budgeted  budgeted,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected,
const void *  data,
size_t  dataSize 
)

Definition at line 260 of file GrGpu.cpp.

266 {
267 this->handleDirtyContext();
268 if (dimensions.width() < 1 || dimensions.width() > this->caps()->maxTextureSize() ||
269 dimensions.height() < 1 || dimensions.height() > this->caps()->maxTextureSize()) {
270 return nullptr;
271 }
272 // Note if we relax the requirement that data must be provided then we must check
273 // caps()->shouldInitializeTextures() here.
274 if (!data) {
275 return nullptr;
276 }
277
278 // TODO: expand CompressedDataIsCorrect to work here too
280 if (compressionType == SkTextureCompressionType::kNone) {
281 return nullptr;
282 }
283
284 if (!this->caps()->isFormatTexturable(format, GrTextureType::k2D)) {
285 return nullptr;
286 }
287
288 if (dataSize <
290 compressionType, dimensions, nullptr, mipmapped == skgpu::Mipmapped::kYes)) {
291 return nullptr;
292 }
293 return this->onCreateCompressedTexture(dimensions, format, budgeted, mipmapped, isProtected,
294 data, dataSize);
295}
virtual sk_sp< GrTexture > onCreateCompressedTexture(SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, const void *data, size_t dataSize)=0
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ createTexture() [1/2]

sk_sp< GrTexture > GrGpu::createTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
GrRenderable  renderable,
int  renderTargetSampleCnt,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
GrColorType  textureColorType,
GrColorType  srcColorType,
const GrMipLevel  texels[],
int  texelLevelCount,
std::string_view  label 
)

Creates a texture object. If renderable is kYes then the returned texture can be used as a render target by calling GrTexture::asRenderTarget(). Not all pixel configs can be used as render targets. Support for configs as textures or render targets can be checked using GrCaps.

Parameters
dimensionsdimensions of the texture to be created.
formatthe format for the texture (not currently used).
renderableshould the resulting texture be renderable
renderTargetSampleCntThe number of samples to use for rendering if renderable is kYes. If renderable is kNo then this must be 1.
budgeteddoes this texture count against the resource cache budget?
isProtectedshould the texture be created as protected.
texelsarray of mipmap levels containing texel data to load. If level i has pixels then it is assumed that its dimensions are max(1, floor(dimensions.fWidth / 2)) by max(1, floor(dimensions.fHeight / 2)). If texels[i].fPixels == nullptr for all i <= mipLevelCount or mipLevelCount is 0 then the texture's contents are uninitialized. If a level has non-null pixels, its row bytes must be a multiple of the config's bytes-per-pixel. The row bytes must be tight to the level width if !caps->writePixelsRowBytesSupport(). If mipLevelCount > 1 and texels[i].fPixels != nullptr for any i > 0 then all levels must have non-null pixels. All levels must have non-null pixels if GrCaps::createTextureMustSpecifyAllLevels() is true.
textureColorTypeThe color type interpretation of the texture for the purpose of of uploading texel data.
srcColorTypeThe color type of data in texels[].
texelLevelCountthe number of levels in 'texels'. May be 0, 1, or floor(max((log2(dimensions.fWidth), log2(dimensions.fHeight)))). It must be the latter if GrCaps::createTextureMustSpecifyAllLevels() is true.
Returns
The texture object if successful, otherwise nullptr.

Definition at line 189 of file GrGpu.cpp.

200 {
201 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
202 if (texelLevelCount) {
203 if (!validate_texel_levels(dimensions, srcColorType, texels, texelLevelCount,
204 this->caps())) {
205 return nullptr;
206 }
207 }
208
209 int mipLevelCount = std::max(1, texelLevelCount);
210 uint32_t levelClearMask = 0;
211 if (this->caps()->shouldInitializeTextures()) {
212 if (texelLevelCount) {
213 for (int i = 0; i < mipLevelCount; ++i) {
214 if (!texels->fPixels) {
215 levelClearMask |= static_cast<uint32_t>(1 << i);
216 }
217 }
218 } else {
219 levelClearMask = static_cast<uint32_t>((1 << mipLevelCount) - 1);
220 }
221 }
222
223 auto tex = this->createTextureCommon(dimensions,
224 format,
225 textureType,
226 renderable,
227 renderTargetSampleCnt,
228 budgeted,
229 isProtected,
230 texelLevelCount,
231 levelClearMask,
232 label);
233 if (tex) {
234 bool markMipLevelsClean = false;
235 // Currently if level 0 does not have pixels then no other level may, as enforced by
236 // validate_texel_levels.
237 if (texelLevelCount && texels[0].fPixels) {
238 if (!this->writePixels(tex.get(),
239 SkIRect::MakeSize(dimensions),
240 textureColorType,
241 srcColorType,
242 texels,
243 texelLevelCount)) {
244 return nullptr;
245 }
246 // Currently if level[1] of mip map has pixel data then so must all other levels.
247 // as enforced by validate_texel_levels.
248 markMipLevelsClean = (texelLevelCount > 1 && !levelClearMask && texels[1].fPixels);
250 } else if (levelClearMask && mipLevelCount > 1) {
251 markMipLevelsClean = true;
252 }
253 if (markMipLevelsClean) {
254 tex->markMipmapsClean();
255 }
256 }
257 return tex;
258}
static bool validate_texel_levels(SkISize dimensions, GrColorType texelColorType, const GrMipLevel *texels, int mipLevelCount, const GrCaps *caps)
Definition: GrGpu.cpp:55
void incTextureUploads()
Definition: GrGpu.h:535
bool writePixels(GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling=false)
Definition: GrGpu.cpp:461
Stats fStats
Definition: GrGpu.h:703
static float max(float r, float g, float b)
Definition: hsl.cpp:49
const void * fPixels
Definition: GrTypesPriv.h:135
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66

◆ createTexture() [2/2]

sk_sp< GrTexture > GrGpu::createTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
GrRenderable  renderable,
int  renderTargetSampleCnt,
skgpu::Mipmapped  mipmapped,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
std::string_view  label 
)

Simplified createTexture() interface for when there is no initial texel data to upload.

Definition at line 156 of file GrGpu.cpp.

164 {
165 int mipLevelCount = 1;
166 if (mipmapped == skgpu::Mipmapped::kYes) {
167 mipLevelCount =
168 32 - SkCLZ(static_cast<uint32_t>(std::max(dimensions.fWidth, dimensions.fHeight)));
169 }
170 uint32_t levelClearMask =
171 this->caps()->shouldInitializeTextures() ? (1 << mipLevelCount) - 1 : 0;
172 auto tex = this->createTextureCommon(dimensions,
173 format,
174 textureType,
175 renderable,
176 renderTargetSampleCnt,
177 budgeted,
178 isProtected,
179 mipLevelCount,
180 levelClearMask,
181 label);
182 if (tex && mipmapped == skgpu::Mipmapped::kYes && levelClearMask) {
183 tex->markMipmapsClean();
184 }
185
186 return tex;
187}
static int SkCLZ(uint32_t mask)
Definition: SkMathPriv.h:186
bool shouldInitializeTextures() const
Definition: GrCaps.h:386
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

◆ deleteBackendTexture()

virtual void GrGpu::deleteBackendTexture ( const GrBackendTexture )
pure virtual

Frees a texture created by createBackendTexture(). If ownership of the backend texture has been transferred to a context using adopt semantics this should not be called.

Implemented in GrD3DGpu, GrGLGpu, GrMtlGpu, and GrVkGpu.

◆ didWriteToSurface()

void GrGpu::didWriteToSurface ( GrSurface surface,
GrSurfaceOrigin  origin,
const SkIRect bounds,
uint32_t  mipLevels = 1 
) const
protected

Definition at line 665 of file GrGpu.cpp.

666 {
668 SkASSERT(!surface->readOnly());
669 // Mark any MIP chain as dirty if and only if there is a non-empty bounds.
670 if (nullptr == bounds || !bounds->isEmpty()) {
671 GrTexture* texture = surface->asTexture();
672 if (texture) {
673 if (mipLevels == 1) {
674 texture->markMipmapsDirty();
675 } else {
676 texture->markMipmapsClean();
677 }
678 }
679 }
680}
VkSurfaceKHR surface
Definition: main.cc:49
FlTexture * texture
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ disconnect()

void GrGpu::disconnect ( DisconnectType  type)
virtual

Reimplemented in GrGLGpu, GrMtlGpu, and GrVkGpu.

Definition at line 51 of file GrGpu.cpp.

51{}

◆ dumpJSON()

void GrGpu::dumpJSON ( SkJSONWriter writer) const

Definition at line 811 of file GrGpu.cpp.

811{ }

◆ executeFlushInfo()

void GrGpu::executeFlushInfo ( SkSpan< GrSurfaceProxy * >  proxies,
SkSurfaces::BackendSurfaceAccess  access,
const GrFlushInfo info,
const skgpu::MutableTextureState newState 
)

Definition at line 682 of file GrGpu.cpp.

685 {
686 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
687
688 GrResourceProvider* resourceProvider = fContext->priv().resourceProvider();
689
690 std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores(
691 new std::unique_ptr<GrSemaphore>[info.fNumSemaphores]);
692 if (this->caps()->backendSemaphoreSupport() && info.fNumSemaphores) {
693 for (size_t i = 0; i < info.fNumSemaphores; ++i) {
694 if (info.fSignalSemaphores[i].isInitialized()) {
695 semaphores[i] = resourceProvider->wrapBackendSemaphore(
696 info.fSignalSemaphores[i],
699 // If we failed to wrap the semaphore it means the client didn't give us a valid
700 // semaphore to begin with. Therefore, it is fine to not signal it.
701 if (semaphores[i]) {
702 this->insertSemaphore(semaphores[i].get());
703 }
704 } else {
705 semaphores[i] = resourceProvider->makeSemaphore(false);
706 if (semaphores[i]) {
707 this->insertSemaphore(semaphores[i].get());
708 info.fSignalSemaphores[i] = semaphores[i]->backendSemaphore();
709 }
710 }
711 }
712 }
713
714 if (info.fFinishedProc) {
715 this->addFinishedProc(info.fFinishedProc, info.fFinishedContext);
716 }
717
718 if (info.fSubmittedProc) {
719 fSubmittedProcs.emplace_back(info.fSubmittedProc, info.fSubmittedContext);
720 }
721
722 // We currently don't support passing in new surface state for multiple proxies here. The only
723 // time we have multiple proxies is if we are flushing a yuv SkImage which won't have state
724 // updates anyways.
725 SkASSERT(!newState || proxies.size() == 1);
727 this->prepareSurfacesForBackendAccessAndStateUpdates(proxies, access, newState);
728}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
virtual void insertSemaphore(GrSemaphore *semaphore)=0
virtual void prepareSurfacesForBackendAccessAndStateUpdates(SkSpan< GrSurfaceProxy * > proxies, SkSurfaces::BackendSurfaceAccess access, const skgpu::MutableTextureState *newState)
Definition: GrGpu.h:841
virtual void addFinishedProc(GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)=0
std::unique_ptr< GrSemaphore > makeSemaphore(bool isOwned=true)
std::unique_ptr< GrSemaphore > wrapBackendSemaphore(const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership=kBorrow_GrWrapOwnership)
constexpr size_t size() const
Definition: SkSpan_impl.h:95
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248
@ kNoAccess
back-end surface will not be used by client
const myers::Point & get(const myers::Segment &)
GrGpuFinishedProc fFinishedProc
Definition: GrTypes.h:219

◆ finishOutstandingGpuWork()

virtual void GrGpu::finishOutstandingGpuWork ( )
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ getContext() [1/2]

GrDirectContext * GrGpu::getContext ( )
inline

Definition at line 67 of file GrGpu.h.

67{ return fContext; }

◆ getContext() [2/2]

const GrDirectContext * GrGpu::getContext ( ) const
inline

Definition at line 68 of file GrGpu.h.

68{ return fContext; }

◆ getOpsRenderPass()

GrOpsRenderPass * GrGpu::getOpsRenderPass ( GrRenderTarget renderTarget,
bool  useMSAASurface,
GrAttachment stencil,
GrSurfaceOrigin  origin,
const SkIRect bounds,
const GrOpsRenderPass::LoadAndStoreInfo colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo stencilInfo,
const skia_private::TArray< GrSurfaceProxy *, true > &  sampledProxies,
GrXferBarrierFlags  renderPassXferBarriers 
)

Definition at line 730 of file GrGpu.cpp.

739 {
740#if SK_HISTOGRAMS_ENABLED
741 fCurrentSubmitRenderPassCount++;
742#endif
744 return this->onGetOpsRenderPass(renderTarget, useMSAASurface, stencil, origin, bounds,
745 colorInfo, stencilInfo, sampledProxies, renderPassXferBarriers);
746}
void incRenderPasses()
Definition: GrGpu.h:546
virtual GrOpsRenderPass * onGetOpsRenderPass(GrRenderTarget *renderTarget, bool useMSAASurface, GrAttachment *stencil, GrSurfaceOrigin, const SkIRect &bounds, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers)=0

◆ getPreferredStencilFormat()

virtual GrBackendFormat GrGpu::getPreferredStencilFormat ( const GrBackendFormat )
pure virtual

Implemented in GrD3DGpu, and GrVkGpu.

◆ handleDirtyContext()

void GrGpu::handleDirtyContext ( )
inline

Definition at line 677 of file GrGpu.h.

677 {
678 if (fResetBits) {
679 this->resetContext();
680 }
681 }

◆ initCaps()

void GrGpu::initCaps ( sk_sp< const GrCaps caps)
protected

Definition at line 47 of file GrGpu.cpp.

47 {
48 fCaps = std::move(caps);
49}

◆ insertSemaphore()

virtual void GrGpu::insertSemaphore ( GrSemaphore semaphore)
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ isDeviceLost()

virtual bool GrGpu::isDeviceLost ( ) const
inlinevirtual

Reimplemented in GrVkGpu.

Definition at line 97 of file GrGpu.h.

97{ return false; }

◆ makeMSAAAttachment()

virtual sk_sp< GrAttachment > GrGpu::makeMSAAAttachment ( SkISize  dimensions,
const GrBackendFormat format,
int  numSamples,
GrProtected  isProtected,
GrMemoryless  isMemoryless 
)
pure virtual

Implemented in GrD3DGpu, GrVkGpu, and GrGLGpu.

◆ makeSemaphore()

virtual std::unique_ptr< GrSemaphore > GrGpu::makeSemaphore ( bool  isOwned = true)
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ makeStencilAttachment()

virtual sk_sp< GrAttachment > GrGpu::makeStencilAttachment ( const GrBackendFormat colorFormat,
SkISize  dimensions,
int  numStencilSamples 
)
pure virtual

Implemented in GrD3DGpu, GrVkGpu, and GrGLGpu.

◆ markContextDirty()

void GrGpu::markContextDirty ( uint32_t  state = kAll_GrBackendState)
inline

The GrGpu object normally assumes that no outsider is setting state within the underlying 3D API's context/device/whatever. This call informs the GrGpu that the state was modified and it shouldn't make assumptions about the state.

Definition at line 105 of file GrGpu.h.

105{ fResetBits |= state; }
AtkStateType state

◆ onClearBackendTexture()

virtual bool GrGpu::onClearBackendTexture ( const GrBackendTexture ,
sk_sp< skgpu::RefCntedCallback finishedCallback,
std::array< float, 4 >  color 
)
privatepure virtual

◆ onCopySurface()

virtual bool GrGpu::onCopySurface ( GrSurface dst,
const SkIRect dstRect,
GrSurface src,
const SkIRect srcRect,
GrSamplerState::Filter   
)
privatepure virtual

Implemented in GrMtlGpu.

◆ onCreateBackendTexture()

virtual GrBackendTexture GrGpu::onCreateBackendTexture ( SkISize  dimensions,
const GrBackendFormat ,
GrRenderable  ,
skgpu::Mipmapped  ,
GrProtected  ,
std::string_view  label 
)
privatepure virtual

◆ onCreateBuffer()

virtual sk_sp< GrGpuBuffer > GrGpu::onCreateBuffer ( size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern   
)
privatepure virtual

◆ onCreateCompressedBackendTexture()

virtual GrBackendTexture GrGpu::onCreateCompressedBackendTexture ( SkISize  dimensions,
const GrBackendFormat ,
skgpu::Mipmapped  ,
GrProtected   
)
privatepure virtual

◆ onCreateCompressedTexture()

virtual sk_sp< GrTexture > GrGpu::onCreateCompressedTexture ( SkISize  dimensions,
const GrBackendFormat ,
skgpu::Budgeted  ,
skgpu::Mipmapped  ,
GrProtected  ,
const void *  data,
size_t  dataSize 
)
privatepure virtual

◆ onCreateTexture()

virtual sk_sp< GrTexture > GrGpu::onCreateTexture ( SkISize  dimensions,
const GrBackendFormat ,
GrRenderable  ,
int  renderTargetSampleCnt,
skgpu::Budgeted  ,
GrProtected  ,
int  mipLevelCoont,
uint32_t  levelClearMask,
std::string_view  label 
)
privatepure virtual

◆ onGetOpsRenderPass()

virtual GrOpsRenderPass * GrGpu::onGetOpsRenderPass ( GrRenderTarget renderTarget,
bool  useMSAASurface,
GrAttachment stencil,
GrSurfaceOrigin  ,
const SkIRect bounds,
const GrOpsRenderPass::LoadAndStoreInfo ,
const GrOpsRenderPass::StencilLoadAndStoreInfo ,
const skia_private::TArray< GrSurfaceProxy *, true > &  sampledProxies,
GrXferBarrierFlags  renderPassXferBarriers 
)
privatepure virtual

◆ onReadPixels()

virtual bool GrGpu::onReadPixels ( GrSurface ,
SkIRect  ,
GrColorType  surfaceColorType,
GrColorType  dstColorType,
void *  ,
size_t  rowBytes 
)
privatepure virtual

◆ onRegenerateMipMapLevels()

virtual bool GrGpu::onRegenerateMipMapLevels ( GrTexture )
privatepure virtual

Implemented in GrVkGpu.

◆ onReportSubmitHistograms()

virtual void GrGpu::onReportSubmitHistograms ( )
inlineprivatevirtual

Definition at line 849 of file GrGpu.h.

849{}

◆ onResetContext()

virtual void GrGpu::onResetContext ( uint32_t  resetBits)
inlineprivatevirtual

Definition at line 732 of file GrGpu.h.

732{}

◆ onResetTextureBindings()

virtual void GrGpu::onResetTextureBindings ( )
inlineprivatevirtual

Definition at line 735 of file GrGpu.h.

735{}

◆ onResolveRenderTarget()

virtual void GrGpu::onResolveRenderTarget ( GrRenderTarget target,
const SkIRect resolveRect 
)
privatepure virtual

Implemented in GrVkGpu.

◆ onSubmitToGpu()

virtual bool GrGpu::onSubmitToGpu ( GrSyncCpu  sync)
privatepure virtual

◆ onTransferFromBufferToBuffer()

virtual bool GrGpu::onTransferFromBufferToBuffer ( sk_sp< GrGpuBuffer src,
size_t  srcOffset,
sk_sp< GrGpuBuffer dst,
size_t  dstOffset,
size_t  size 
)
privatepure virtual

◆ onTransferPixelsFrom()

virtual bool GrGpu::onTransferPixelsFrom ( GrSurface ,
SkIRect  ,
GrColorType  surfaceColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset 
)
privatepure virtual

◆ onTransferPixelsTo()

virtual bool GrGpu::onTransferPixelsTo ( GrTexture ,
SkIRect  ,
GrColorType  textureColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset,
size_t  rowBytes 
)
privatepure virtual

◆ onUpdateCompressedBackendTexture()

virtual bool GrGpu::onUpdateCompressedBackendTexture ( const GrBackendTexture ,
sk_sp< skgpu::RefCntedCallback finishedCallback,
const void *  data,
size_t  length 
)
privatepure virtual

◆ onWrapBackendRenderTarget()

virtual sk_sp< GrRenderTarget > GrGpu::onWrapBackendRenderTarget ( const GrBackendRenderTarget )
privatepure virtual

◆ onWrapBackendTexture()

virtual sk_sp< GrTexture > GrGpu::onWrapBackendTexture ( const GrBackendTexture ,
GrWrapOwnership  ,
GrWrapCacheable  ,
GrIOType   
)
privatepure virtual

◆ onWrapCompressedBackendTexture()

virtual sk_sp< GrTexture > GrGpu::onWrapCompressedBackendTexture ( const GrBackendTexture ,
GrWrapOwnership  ,
GrWrapCacheable   
)
privatepure virtual

◆ onWrapRenderableBackendTexture()

virtual sk_sp< GrTexture > GrGpu::onWrapRenderableBackendTexture ( const GrBackendTexture ,
int  sampleCnt,
GrWrapOwnership  ,
GrWrapCacheable   
)
privatepure virtual

◆ onWrapVulkanSecondaryCBAsRenderTarget()

sk_sp< GrRenderTarget > GrGpu::onWrapVulkanSecondaryCBAsRenderTarget ( const SkImageInfo imageInfo,
const GrVkDrawableInfo vkInfo 
)
privatevirtual

Definition at line 387 of file GrGpu.cpp.

388 {
389 // This is only supported on Vulkan so we default to returning nullptr here
390 return nullptr;
391}

◆ onWritePixels()

virtual bool GrGpu::onWritePixels ( GrSurface ,
SkIRect  ,
GrColorType  surfaceColorType,
GrColorType  srcColorType,
const  GrMipLevel[],
int  mipLevelCount,
bool  prepForTexSampling 
)
privatepure virtual

◆ pipelineBuilder()

virtual GrThreadSafePipelineBuilder * GrGpu::pipelineBuilder ( )
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ precompileShader()

virtual bool GrGpu::precompileShader ( const SkData key,
const SkData data 
)
inlinevirtual

Reimplemented in GrGLGpu, and GrMtlGpu.

Definition at line 621 of file GrGpu.h.

621{ return false; }

◆ prepareSurfacesForBackendAccessAndStateUpdates()

virtual void GrGpu::prepareSurfacesForBackendAccessAndStateUpdates ( SkSpan< GrSurfaceProxy * >  proxies,
SkSurfaces::BackendSurfaceAccess  access,
const skgpu::MutableTextureState newState 
)
inlineprivatevirtual

Definition at line 841 of file GrGpu.h.

844 {}

◆ prepareTextureForCrossContextUsage()

virtual std::unique_ptr< GrSemaphore > GrGpu::prepareTextureForCrossContextUsage ( GrTexture )
pure virtual

Put this texture in a safe and known state for use across multiple contexts. Depending on the backend, this may return a GrSemaphore. If so, other contexts should wait on that semaphore before using this texture.

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ readPixels()

bool GrGpu::readPixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  dstColorType,
void *  buffer,
size_t  rowBytes 
)

Reads a rectangle of pixels from a render target. No sRGB/linear conversions are performed.

Parameters
surfacethe surface to read from
rectthe rectangle of pixels to read
surfaceColorTypethe color type for this use of the surface.
dstColorTypethe color type of the destination buffer.
buffermemory to read the rectangle into.
rowBytesthe number of bytes between consecutive rows. Must be a multiple of dstColorType's bytes-per-pixel. Must be tight to width if !caps->readPixelsRowBytesSupport().
Returns
true if the read succeeded, false if not. The read can fail because of the surface doesn't support reading, the color type is not allowed for the format of the surface or if the rectangle read is not contained in the surface.

Definition at line 426 of file GrGpu.cpp.

431 {
432 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
434 SkASSERT(!surface->framebufferOnly());
435 SkASSERT(this->caps()->areColorTypeAndFormatCompatible(surfaceColorType,
436 surface->backendFormat()));
437
438 if (!SkIRect::MakeSize(surface->dimensions()).contains(rect)) {
439 return false;
440 }
441
442 size_t minRowBytes = SkToSizeT(GrColorTypeBytesPerPixel(dstColorType) * rect.width());
443 if (!this->caps()->readPixelsRowBytesSupport()) {
444 if (rowBytes != minRowBytes) {
445 return false;
446 }
447 } else {
448 if (rowBytes < minRowBytes) {
449 return false;
450 }
451 if (rowBytes % GrColorTypeBytesPerPixel(dstColorType)) {
452 return false;
453 }
454 }
455
456 this->handleDirtyContext();
457
458 return this->onReadPixels(surface, rect, surfaceColorType, dstColorType, buffer, rowBytes);
459}
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
Definition: GrTypesPriv.h:896
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
virtual bool onReadPixels(GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType dstColorType, void *, size_t rowBytes)=0
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463

◆ refCaps()

sk_sp< const GrCaps > GrGpu::refCaps ( ) const
inline

Definition at line 74 of file GrGpu.h.

74{ return fCaps; }

◆ refPipelineBuilder()

virtual sk_sp< GrThreadSafePipelineBuilder > GrGpu::refPipelineBuilder ( )
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ regenerateMipMapLevels()

bool GrGpu::regenerateMipMapLevels ( GrTexture texture)

Uses the base of the texture to recompute the contents of the other levels.

Definition at line 632 of file GrGpu.cpp.

632 {
633 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
635 SkASSERT(this->caps()->mipmapSupport());
636 SkASSERT(texture->mipmapped() == skgpu::Mipmapped::kYes);
637 if (!texture->mipmapsAreDirty()) {
638 // This can happen when the proxy expects mipmaps to be dirty, but they are not dirty on the
639 // actual target. This may be caused by things that the drawingManager could not predict,
640 // i.e., ops that don't draw anything, aborting a draw for exceptional circumstances, etc.
641 // NOTE: This goes away once we quit tracking mipmap state on the actual texture.
642 return true;
643 }
644 if (texture->readOnly()) {
645 return false;
646 }
647 if (this->onRegenerateMipMapLevels(texture)) {
648 texture->markMipmapsClean();
649 return true;
650 }
651 return false;
652}
virtual bool onRegenerateMipMapLevels(GrTexture *)=0

◆ releaseUnlockedBackendObjects()

virtual void GrGpu::releaseUnlockedBackendObjects ( )
inlinevirtual

Frees any backend specific objects that are not currently in use by the GPU. This is called when the client is trying to free up as much GPU memory as possible. We will not release resources connected to programs/pipelines since the cost to recreate those is significantly higher that other resources.

Reimplemented in GrVkGpu.

Definition at line 453 of file GrGpu.h.

453{}

◆ resetTextureBindings()

void GrGpu::resetTextureBindings ( )

If the backend API has stateful texture bindings, this resets them back to defaults.

Definition at line 654 of file GrGpu.cpp.

654 {
655 this->handleDirtyContext();
657}
virtual void onResetTextureBindings()
Definition: GrGpu.h:735

◆ resolveRenderTarget()

void GrGpu::resolveRenderTarget ( GrRenderTarget target,
const SkIRect resolveRect 
)

Resolves MSAA. The resolveRect must already be in the native destination space.

Definition at line 659 of file GrGpu.cpp.

659 {
661 this->handleDirtyContext();
662 this->onResolveRenderTarget(target, resolveRect);
663}
virtual void onResolveRenderTarget(GrRenderTarget *target, const SkIRect &resolveRect)=0
uint32_t * target

◆ setBackendRenderTargetState()

virtual bool GrGpu::setBackendRenderTargetState ( const GrBackendRenderTarget ,
const skgpu::MutableTextureState ,
skgpu::MutableTextureState previousState,
sk_sp< skgpu::RefCntedCallback finishedCallback 
)
inlinevirtual

Reimplemented in GrVkGpu.

Definition at line 602 of file GrGpu.h.

606 {
607 return false;
608 }

◆ setBackendTextureState()

virtual bool GrGpu::setBackendTextureState ( const GrBackendTexture ,
const skgpu::MutableTextureState ,
skgpu::MutableTextureState previousState,
sk_sp< skgpu::RefCntedCallback finishedCallback 
)
inlinevirtual

Reimplemented in GrVkGpu.

Definition at line 594 of file GrGpu.h.

598 {
599 return false;
600 }

◆ setOOMed()

void GrGpu::setOOMed ( )
inlineprotected

Definition at line 701 of file GrGpu.h.

701{ fOOMed = true; }

◆ stagingBufferManager()

virtual GrStagingBufferManager * GrGpu::stagingBufferManager ( )
inlinevirtual

Reimplemented in GrD3DGpu, GrGLGpu, GrMtlGpu, and GrVkGpu.

Definition at line 76 of file GrGpu.h.

76{ return nullptr; }

◆ stats()

Stats * GrGpu::stats ( )
inline

Definition at line 551 of file GrGpu.h.

551{ return &fStats; }

◆ storeVkPipelineCacheData()

virtual void GrGpu::storeVkPipelineCacheData ( )
inlinevirtual

Reimplemented in GrVkGpu.

Definition at line 683 of file GrGpu.h.

683{}

◆ submit()

virtual void GrGpu::submit ( GrOpsRenderPass )
pure virtual

Implemented in GrVkGpu, GrD3DGpu, GrGLGpu, GrMockGpu, and GrMtlGpu.

◆ submitToGpu()

bool GrGpu::submitToGpu ( GrSyncCpu  sync)

Definition at line 748 of file GrGpu.cpp.

748 {
749 this->stats()->incNumSubmitToGpus();
750
751 if (auto manager = this->stagingBufferManager()) {
752 manager->detachBuffers();
753 }
754
755 if (auto uniformsBuffer = this->uniformsRingBuffer()) {
756 uniformsBuffer->startSubmit(this);
757 }
758
759 bool submitted = this->onSubmitToGpu(sync);
760
761 this->callSubmittedProcs(submitted);
762
763 this->reportSubmitHistograms();
764
765 return submitted;
766}
void incNumSubmitToGpus()
Definition: GrGpu.h:543
Stats * stats()
Definition: GrGpu.h:551
virtual bool onSubmitToGpu(GrSyncCpu sync)=0
virtual GrStagingBufferManager * stagingBufferManager()
Definition: GrGpu.h:76
virtual GrRingBuffer * uniformsRingBuffer()
Definition: GrGpu.h:78
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 manager
Definition: switches.h:218

◆ takeOwnershipOfBuffer()

virtual void GrGpu::takeOwnershipOfBuffer ( sk_sp< GrGpuBuffer )
inlinevirtual

Reimplemented in GrD3DGpu, and GrVkGpu.

Definition at line 432 of file GrGpu.h.

432{}

◆ transferFromBufferToBuffer()

bool GrGpu::transferFromBufferToBuffer ( sk_sp< GrGpuBuffer src,
size_t  srcOffset,
sk_sp< GrGpuBuffer dst,
size_t  dstOffset,
size_t  size 
)

Transfer bytes from one GPU buffer to another. The src buffer must have type kXferCpuToGpu and the dst buffer must not. Neither buffer may currently be mapped. The offsets and size must be aligned to GrCaps::transferFromBufferToBufferAlignment.

Parameters
srcthe buffer to read from
srcOffsetthe aligned offset at the src at which the transfer begins.
dstthe buffer to write to
dstOffsetthe aligned offset in the dst at which the transfer begins
sizethe aligned number of bytes to transfer;

Definition at line 511 of file GrGpu.cpp.

515 {
516 SkASSERT(src);
517 SkASSERT(dst);
518 SkASSERT(srcOffset % this->caps()->transferFromBufferToBufferAlignment() == 0);
519 SkASSERT(dstOffset % this->caps()->transferFromBufferToBufferAlignment() == 0);
520 SkASSERT(size % this->caps()->transferFromBufferToBufferAlignment() == 0);
521 SkASSERT(srcOffset + size <= src->size());
522 SkASSERT(dstOffset + size <= dst->size());
523 SkASSERT(src->intendedType() == GrGpuBufferType::kXferCpuToGpu);
524 SkASSERT(dst->intendedType() != GrGpuBufferType::kXferCpuToGpu);
525
526 this->handleDirtyContext();
527 if (!this->onTransferFromBufferToBuffer(std::move(src),
528 srcOffset,
529 std::move(dst),
530 dstOffset,
531 size)) {
532 return false;
533 }
534
536
537 return true;
538}
void incBufferTransfers()
Definition: GrGpu.h:537
virtual bool onTransferFromBufferToBuffer(sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size)=0

◆ transferPixelsFrom()

bool GrGpu::transferPixelsFrom ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset 
)

Reads the pixels from a rectangle of a surface into a buffer. Use GrCaps::SupportedRead::fOffsetAlignmentForTransferBuffer to determine the requirements for the buffer offset alignment. If the surface is a MIP mapped texture, the base level is read.

If successful the row bytes in the buffer is always: GrColorTypeBytesPerPixel(bufferColorType) * rect.width()

Asserts that the caller has passed a properly aligned offset and that the buffer is large enough to hold the result

Parameters
surfacethe surface to read from.
rectthe rectangle of pixels to read
surfaceColorTypethe color type for this use of the surface.
bufferColorTypethe color type of the transfer buffer's pixel data
transferBufferGrBuffer to write pixels to (type must be "kXferGpuToCpu")
offsetoffset from the start of the buffer

Definition at line 592 of file GrGpu.cpp.

597 {
598 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
600 SkASSERT(transferBuffer);
602 SkASSERT(this->caps()->areColorTypeAndFormatCompatible(surfaceColorType,
603 surface->backendFormat()));
604
605#ifdef SK_DEBUG
606 auto supportedRead = this->caps()->supportedReadPixelsColorType(
607 surfaceColorType, surface->backendFormat(), bufferColorType);
608 SkASSERT(supportedRead.fOffsetAlignmentForTransferBuffer);
609 SkASSERT(offset % supportedRead.fOffsetAlignmentForTransferBuffer == 0);
610#endif
611
612 // We require that the write region is contained in the texture
613 if (!SkIRect::MakeSize(surface->dimensions()).contains(rect)) {
614 return false;
615 }
616
617 this->handleDirtyContext();
618 if (!this->onTransferPixelsFrom(surface,
619 rect,
620 surfaceColorType,
621 bufferColorType,
622 std::move(transferBuffer),
623 offset)) {
624 return false;
625 }
626
628
629 return true;
630}
SupportedRead supportedReadPixelsColorType(GrColorType srcColorType, const GrBackendFormat &srcFormat, GrColorType dstColorType) const
Definition: GrCaps.cpp:366
GrGpuBufferType intendedType() const
Definition: GrGpuBuffer.h:99
void incTransfersFromSurface()
Definition: GrGpu.h:538
virtual bool onTransferPixelsFrom(GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset)=0
SeparatedVector2 offset

◆ transferPixelsTo()

bool GrGpu::transferPixelsTo ( GrTexture texture,
SkIRect  rect,
GrColorType  textureColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset,
size_t  rowBytes 
)

Updates the pixels in a rectangle of a texture using a buffer. If the texture is MIP mapped, the base level is written to.

Parameters
texturethe texture to write to.
rectthe rectangle of pixels in the texture to overwrite
textureColorTypethe color type for this use of the surface.
bufferColorTypethe color type of the transfer buffer's pixel data
transferBufferGrBuffer to read pixels from (type must be "kXferCpuToGpu")
offsetoffset from the start of the buffer
rowBytesnumber of bytes between consecutive rows in the buffer. Must be a multiple of bufferColorType's bytes-per-pixel. Must be tight to rect.width() if !caps->writePixelsRowBytesSupport().

Definition at line 540 of file GrGpu.cpp.

546 {
547 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
549 SkASSERT(transferBuffer);
551
552 if (texture->readOnly()) {
553 return false;
554 }
555
556 // We require that the write region is contained in the texture
557 if (!SkIRect::MakeSize(texture->dimensions()).contains(rect)) {
558 return false;
559 }
560
561 size_t bpp = GrColorTypeBytesPerPixel(bufferColorType);
562 if (this->caps()->writePixelsRowBytesSupport()) {
563 if (rowBytes < SkToSizeT(bpp*rect.width())) {
564 return false;
565 }
566 if (rowBytes % bpp) {
567 return false;
568 }
569 } else {
570 if (rowBytes != SkToSizeT(bpp*rect.width())) {
571 return false;
572 }
573 }
574
575 this->handleDirtyContext();
576 if (!this->onTransferPixelsTo(texture,
577 rect,
578 textureColorType,
579 bufferColorType,
580 std::move(transferBuffer),
581 offset,
582 rowBytes)) {
583 return false;
584 }
585
588
589 return true;
590}
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
void incTransfersToTexture()
Definition: GrGpu.h:536
virtual bool onTransferPixelsTo(GrTexture *, SkIRect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset, size_t rowBytes)=0
void didWriteToSurface(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
Definition: GrGpu.cpp:665

◆ uniformsRingBuffer()

virtual GrRingBuffer * GrGpu::uniformsRingBuffer ( )
inlinevirtual

Reimplemented in GrD3DGpu, and GrMtlGpu.

Definition at line 78 of file GrGpu.h.

78{ return nullptr; }

◆ updateCompressedBackendTexture()

bool GrGpu::updateCompressedBackendTexture ( const GrBackendTexture backendTexture,
sk_sp< skgpu::RefCntedCallback finishedCallback,
const void *  data,
size_t  length 
)

Definition at line 941 of file GrGpu.cpp.

944 {
945 SkASSERT(data);
946
947 if (!backendTexture.isValid()) {
948 return false;
949 }
950
951 GrBackendFormat format = backendTexture.getBackendFormat();
952
954 if (compressionType == SkTextureCompressionType::kNone) {
955 // Uncompressed formats must go through the createBackendTexture API
956 return false;
957 }
958
959 if (backendTexture.hasMipmaps() && !this->caps()->mipmapSupport()) {
960 return false;
961 }
962
963 skgpu::Mipmapped mipmapped =
965
966 if (!CompressedDataIsCorrect(backendTexture.dimensions(),
967 compressionType,
968 mipmapped,
969 data,
970 length)) {
971 return false;
972 }
973
974 return this->onUpdateCompressedBackendTexture(backendTexture,
975 std::move(finishedCallback),
976 data,
977 length);
978}
SkISize dimensions() const
GrBackendFormat getBackendFormat() const
static bool CompressedDataIsCorrect(SkISize dimensions, SkTextureCompressionType, skgpu::Mipmapped, const void *data, size_t length)
Definition: GrGpu.cpp:858
virtual bool onUpdateCompressedBackendTexture(const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t length)=0
Mipmapped
Definition: GpuTypes.h:53

◆ waitSemaphore()

virtual void GrGpu::waitSemaphore ( GrSemaphore semaphore)
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ willExecute()

virtual void GrGpu::willExecute ( )
inlinevirtual

Reimplemented in GrGLGpu.

Definition at line 413 of file GrGpu.h.

413{}

◆ wrapBackendRenderTarget()

sk_sp< GrRenderTarget > GrGpu::wrapBackendRenderTarget ( const GrBackendRenderTarget backendRT)

Implements GrResourceProvider::wrapBackendRenderTarget

Definition at line 366 of file GrGpu.cpp.

366 {
367 this->handleDirtyContext();
368
369 const GrCaps* caps = this->caps();
370
371 if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) {
372 return nullptr;
373 }
374
376 if (backendRT.isFramebufferOnly()) {
377 rt->setFramebufferOnly();
378 }
379 return rt;
380}
bool isFramebufferOnly() const
GrBackendFormat getBackendFormat() const
virtual bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const =0
virtual sk_sp< GrRenderTarget > onWrapBackendRenderTarget(const GrBackendRenderTarget &)=0

◆ wrapBackendSemaphore()

virtual std::unique_ptr< GrSemaphore > GrGpu::wrapBackendSemaphore ( const GrBackendSemaphore ,
GrSemaphoreWrapType  ,
GrWrapOwnership   
)
pure virtual

Implemented in GrD3DGpu, GrGLGpu, GrMockGpu, GrMtlGpu, and GrVkGpu.

◆ wrapBackendTexture()

sk_sp< GrTexture > GrGpu::wrapBackendTexture ( const GrBackendTexture backendTex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable,
GrIOType  ioType 
)

Implements GrResourceProvider::wrapBackendTexture

Definition at line 297 of file GrGpu.cpp.

300 {
301 SkASSERT(ioType != kWrite_GrIOType);
302 this->handleDirtyContext();
303
304 const GrCaps* caps = this->caps();
305 SkASSERT(caps);
306
307 if (!caps->isFormatTexturable(backendTex.getBackendFormat(), backendTex.textureType())) {
308 return nullptr;
309 }
310 if (backendTex.width() > caps->maxTextureSize() ||
311 backendTex.height() > caps->maxTextureSize()) {
312 return nullptr;
313 }
314
315 return this->onWrapBackendTexture(backendTex, ownership, cacheable, ioType);
316}
@ kWrite_GrIOType
Definition: GrTypesPriv.h:404
GrTextureType textureType() const
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
virtual sk_sp< GrTexture > onWrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType)=0

◆ wrapCompressedBackendTexture()

sk_sp< GrTexture > GrGpu::wrapCompressedBackendTexture ( const GrBackendTexture backendTex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)

Definition at line 318 of file GrGpu.cpp.

320 {
321 this->handleDirtyContext();
322
323 const GrCaps* caps = this->caps();
324 SkASSERT(caps);
325
326 if (!caps->isFormatTexturable(backendTex.getBackendFormat(), backendTex.textureType())) {
327 return nullptr;
328 }
329 if (backendTex.width() > caps->maxTextureSize() ||
330 backendTex.height() > caps->maxTextureSize()) {
331 return nullptr;
332 }
333
334 return this->onWrapCompressedBackendTexture(backendTex, ownership, cacheable);
335}
virtual sk_sp< GrTexture > onWrapCompressedBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable)=0

◆ wrapRenderableBackendTexture()

sk_sp< GrTexture > GrGpu::wrapRenderableBackendTexture ( const GrBackendTexture backendTex,
int  sampleCnt,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)

Implements GrResourceProvider::wrapRenderableBackendTexture

Definition at line 337 of file GrGpu.cpp.

340 {
341 this->handleDirtyContext();
342 if (sampleCnt < 1) {
343 return nullptr;
344 }
345
346 const GrCaps* caps = this->caps();
347
348 if (!caps->isFormatTexturable(backendTex.getBackendFormat(), backendTex.textureType()) ||
349 !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) {
350 return nullptr;
351 }
352
353 if (backendTex.width() > caps->maxRenderTargetSize() ||
354 backendTex.height() > caps->maxRenderTargetSize()) {
355 return nullptr;
356 }
357 sk_sp<GrTexture> tex =
358 this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership, cacheable);
359 SkASSERT(!tex || tex->asRenderTarget());
360 if (tex && sampleCnt > 1 && !caps->msaaResolvesAutomatically()) {
362 }
363 return tex;
364}
int maxRenderTargetSize() const
Definition: GrCaps.h:223
bool msaaResolvesAutomatically() const
Definition: GrCaps.h:100
virtual sk_sp< GrTexture > onWrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable)=0
void setRequiresManualMSAAResolve()
Definition: GrSurface.h:121
virtual GrRenderTarget * asRenderTarget()
Definition: GrSurface.h:65

◆ wrapVulkanSecondaryCBAsRenderTarget()

sk_sp< GrRenderTarget > GrGpu::wrapVulkanSecondaryCBAsRenderTarget ( const SkImageInfo imageInfo,
const GrVkDrawableInfo vkInfo 
)

Implements GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget

Definition at line 382 of file GrGpu.cpp.

383 {
384 return this->onWrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo);
385}
virtual sk_sp< GrRenderTarget > onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo &, const GrVkDrawableInfo &)
Definition: GrGpu.cpp:387

◆ writePixels() [1/2]

bool GrGpu::writePixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  srcColorType,
const GrMipLevel  texels[],
int  mipLevelCount,
bool  prepForTexSampling = false 
)

Updates the pixels in a rectangle of a surface. No sRGB/linear conversions are performed.

Parameters
surfacethe surface to write to.
rectthe rectangle of pixels to overwrite
surfaceColorTypethe color type for this use of the surface.
srcColorTypethe color type of the source buffer.
texelsarray of mipmap levels containing texture data. Row bytes must be a multiple of srcColorType's bytes-per-pixel. Must be tight to level width if !caps->writePixelsRowBytesSupport().
mipLevelCountnumber of levels in 'texels'
prepForTexSamplingAfter doing write pixels should the surface be prepared for texture sampling. This is currently only used by Vulkan for inline uploads to set that layout back to sampled after doing the upload. Inline uploads currently can happen between draws in a single op so it is not trivial to break up the OpsTask into two tasks when we see an inline upload. However, once we are able to support doing that we can remove this parameter.
Returns
true if the write succeeded, false if not. The read can fail because of the surface doesn't support writing (e.g. read only), the color type is not allowed for the format of the surface or if the rectangle written is not contained in the surface.

Definition at line 461 of file GrGpu.cpp.

467 {
468 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
469 ATRACE_ANDROID_FRAMEWORK_ALWAYS("Texture upload(%u) %ix%i",
470 surface->uniqueID().asUInt(), rect.width(), rect.height());
472 SkASSERT(!surface->framebufferOnly());
473
474 if (surface->readOnly()) {
475 return false;
476 }
477
478 if (mipLevelCount == 0) {
479 return false;
480 } else if (mipLevelCount == 1) {
481 // We require that if we are not mipped, then the write region is contained in the surface
482 if (!SkIRect::MakeSize(surface->dimensions()).contains(rect)) {
483 return false;
484 }
485 } else if (rect != SkIRect::MakeSize(surface->dimensions())) {
486 // We require that if the texels are mipped, than the write region is the entire surface
487 return false;
488 }
489
490 if (!validate_texel_levels(rect.size(), srcColorType, texels, mipLevelCount, this->caps())) {
491 return false;
492 }
493
494 this->handleDirtyContext();
495 if (!this->onWritePixels(surface,
496 rect,
497 surfaceColorType,
498 srcColorType,
499 texels,
500 mipLevelCount,
501 prepForTexSampling)) {
502 return false;
503 }
504
505 this->didWriteToSurface(surface, kTopLeft_GrSurfaceOrigin, &rect, mipLevelCount);
507
508 return true;
509}
#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt,...)
virtual bool onWritePixels(GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel[], int mipLevelCount, bool prepForTexSampling)=0

◆ writePixels() [2/2]

bool GrGpu::writePixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  srcColorType,
const void *  buffer,
size_t  rowBytes,
bool  prepForTexSampling = false 
)
inline

Helper for the case of a single level.

Definition at line 293 of file GrGpu.h.

299 {
300 GrMipLevel mipLevel = {buffer, rowBytes, nullptr};
301 return this->writePixels(surface,
302 rect,
303 surfaceColorType,
304 srcColorType,
305 &mipLevel,
306 1,
307 prepForTexSampling);
308 }

◆ xferBarrier()

virtual void GrGpu::xferBarrier ( GrRenderTarget ,
GrXferBarrierType   
)
pure virtual

Implemented in GrD3DGpu, and GrVkGpu.

Member Data Documentation

◆ fStats

Stats GrGpu::fStats
protected

Definition at line 703 of file GrGpu.h.


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