Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
GrGLGpu Class Referencefinal

#include <GrGLGpu.h>

Inheritance diagram for GrGLGpu:
GrGpu

Classes

class  SamplerObjectCache
 

Public Types

using ResolveDirection = GrGLRenderTarget::ResolveDirection
 
- Public Types inherited from GrGpu
enum class  DisconnectType { kAbandon , kCleanup }
 

Public Member Functions

 ~GrGLGpu () override
 
void disconnect (DisconnectType) override
 
GrThreadSafePipelineBuilderpipelineBuilder () override
 
sk_sp< GrThreadSafePipelineBuilderrefPipelineBuilder () override
 
const GrGLContextglContext () const
 
const GrGLInterfaceglInterface () const
 
const GrGLContextInfoctxInfo () const
 
GrGLStandard glStandard () const
 
GrGLVersion glVersion () const
 
SkSL::GLSLGeneration glslGeneration () const
 
const GrGLCapsglCaps () const
 
GrStagingBufferManagerstagingBufferManager () override
 
void bindTexture (int unitIdx, GrSamplerState samplerState, const skgpu::Swizzle &, GrGLTexture *)
 
void bindVertexArray (GrGLuint id)
 
void notifyVertexArrayDelete (GrGLuint id)
 
GrGLenum bindBuffer (GrGpuBufferType type, const GrBuffer *)
 
bool flushGLState (GrRenderTarget *, bool useMultisampleFBO, const GrProgramInfo &)
 
void flushScissorRect (const SkIRect &scissor, int rtHeight, GrSurfaceOrigin)
 
void flushViewport (const SkIRect &viewport, int rtHeight, GrSurfaceOrigin)
 
GrGLProgramcurrentProgram ()
 
GrGLAttribArrayStatebindInternalVertexArray (const GrBuffer *indexBuffer, int numAttribs, GrPrimitiveRestart primitiveRestart)
 
GrGLenum prepareToDraw (GrPrimitiveType primitiveType)
 
void resolveRenderFBOs (GrGLRenderTarget *, const SkIRect &resolveRect, ResolveDirection, bool invalidateReadBufferAfterBlit=false)
 
void drawSingleIntoMSAAFBO (GrGLRenderTarget *rt, const SkIRect &drawBounds)
 
void clear (const GrScissorState &, std::array< float, 4 > color, GrRenderTarget *, bool useMultisampleFBO, GrSurfaceOrigin)
 
void clearStencilClip (const GrScissorState &, bool insideStencilMask, GrRenderTarget *, bool useMultisampleFBO, GrSurfaceOrigin)
 
void beginCommandBuffer (GrGLRenderTarget *, bool useMultisampleFBO, const SkIRect &bounds, GrSurfaceOrigin, const GrOpsRenderPass::LoadAndStoreInfo &colorLoadStore, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
 
void endCommandBuffer (GrGLRenderTarget *, bool useMultisampleFBO, const GrOpsRenderPass::LoadAndStoreInfo &colorLoadStore, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
 
void invalidateBoundRenderTarget ()
 
sk_sp< GrAttachmentmakeStencilAttachment (const GrBackendFormat &colorFormat, SkISize dimensions, int numStencilSamples) override
 
sk_sp< GrAttachmentmakeMSAAAttachment (SkISize dimensions, const GrBackendFormat &format, int numSamples, GrProtected isProtected, GrMemoryless) override
 
void deleteBackendTexture (const GrBackendTexture &) override
 
bool compile (const GrProgramDesc &, const GrProgramInfo &) override
 
bool precompileShader (const SkData &key, const SkData &data) override
 
void willExecute () override
 
void submit (GrOpsRenderPass *renderPass) override
 
GrGLsync insertFence ()
 
bool waitFence (GrGLsync)
 
void deleteFence (GrGLsync)
 
std::unique_ptr< GrSemaphoremakeSemaphore (bool isOwned) override
 
std::unique_ptr< GrSemaphorewrapBackendSemaphore (const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership) override
 
void insertSemaphore (GrSemaphore *semaphore) override
 
void waitSemaphore (GrSemaphore *semaphore) override
 
void checkFinishProcs () override
 
void finishOutstandingGpuWork () override
 
void clearErrorsAndCheckForOOM ()
 
GrGLenum getErrorAndCheckForOOM ()
 
std::unique_ptr< GrSemaphoreprepareTextureForCrossContextUsage (GrTexture *) override
 
void deleteSync (GrGLsync)
 
void bindFramebuffer (GrGLenum fboTarget, GrGLuint fboid)
 
void deleteFramebuffer (GrGLuint fboid)
 
void flushProgram (sk_sp< GrGLProgram >)
 
void flushProgram (GrGLuint)
 
void didDrawTo (GrRenderTarget *)
 
- Public Member Functions inherited from GrGpu
 GrGpu (GrDirectContext *direct)
 
virtual ~GrGpu ()
 
GrDirectContextgetContext ()
 
const GrDirectContextgetContext () const
 
const GrCapscaps () const
 
sk_sp< const GrCapsrefCaps () const
 
virtual GrRingBufferuniformsRingBuffer ()
 
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)
 
bool submitToGpu (GrSyncCpu sync)
 
virtual void takeOwnershipOfBuffer (sk_sp< GrGpuBuffer >)
 
bool checkAndResetOOMed ()
 
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)
 
void handleDirtyContext ()
 
virtual void storeVkPipelineCacheData ()
 

Static Public Member Functions

static std::unique_ptr< GrGpuMake (sk_sp< const GrGLInterface >, const GrContextOptions &, GrDirectContext *)
 

Private Member Functions

GrBackendTexture onCreateBackendTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label) override
 
GrBackendTexture onCreateCompressedBackendTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected) override
 
bool onClearBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color) override
 
bool onUpdateCompressedBackendTexture (const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t length) override
 
void onResetContext (uint32_t resetBits) override
 
void onResetTextureBindings () override
 
void xferBarrier (GrRenderTarget *, GrXferBarrierType) override
 
sk_sp< GrTextureonCreateTexture (SkISize dimensions, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, skgpu::Budgeted, GrProtected, int mipLevelCount, uint32_t levelClearMask, std::string_view label) override
 
sk_sp< GrTextureonCreateCompressedTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, const void *data, size_t dataSize) override
 
sk_sp< GrGpuBufferonCreateBuffer (size_t size, GrGpuBufferType, GrAccessPattern) override
 
sk_sp< GrTextureonWrapBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType) override
 
sk_sp< GrTextureonWrapCompressedBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable) override
 
sk_sp< GrTextureonWrapRenderableBackendTexture (const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable) override
 
sk_sp< GrRenderTargetonWrapBackendRenderTarget (const GrBackendRenderTarget &) override
 
GrBackendFormat getPreferredStencilFormat (const GrBackendFormat &format) override
 
bool onReadPixels (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType dstColorType, void *, size_t rowBytes) override
 
bool onWritePixels (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel[], int mipLevelCount, bool prepForTexSampling) override
 
bool onTransferFromBufferToBuffer (sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size) override
 
bool onTransferPixelsTo (GrTexture *, SkIRect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer >, size_t offset, size_t rowBytes) override
 
bool onTransferPixelsFrom (GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer >, size_t offset) override
 
void onResolveRenderTarget (GrRenderTarget *target, const SkIRect &resolveRect) override
 
bool onRegenerateMipMapLevels (GrTexture *) override
 
bool onCopySurface (GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter) override
 
void addFinishedProc (GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext) override
 
GrOpsRenderPassonGetOpsRenderPass (GrRenderTarget *, bool useMultisampleFBO, GrAttachment *, GrSurfaceOrigin, const SkIRect &, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers) override
 
bool onSubmitToGpu (GrSyncCpu sync) override
 

Additional Inherited Members

- Protected Member Functions inherited from GrGpu
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 inherited from GrGpu
static bool CompressedDataIsCorrect (SkISize dimensions, SkTextureCompressionType, skgpu::Mipmapped, const void *data, size_t length)
 
- Protected Attributes inherited from GrGpu
Stats fStats
 

Detailed Description

Definition at line 89 of file GrGLGpu.h.

Member Typedef Documentation

◆ ResolveDirection

Definition at line 166 of file GrGLGpu.h.

Constructor & Destructor Documentation

◆ ~GrGLGpu()

GrGLGpu::~GrGLGpu ( )
override

Definition at line 473 of file GrGLGpu.cpp.

473 {
474 // Ensure any GrGpuResource objects get deleted first, since they may require a working GrGLGpu
475 // to release the resources held by the objects themselves.
476 fCopyProgramArrayBuffer.reset();
477 fMipmapProgramArrayBuffer.reset();
478 if (fProgramCache) {
479 fProgramCache->reset();
480 }
481
482 fHWProgram.reset();
483 if (fHWProgramID) {
484 // detach the current program so there is no confusion on OpenGL's part
485 // that we want it to be deleted
486 GL_CALL(UseProgram(0));
487 }
488
489 if (fTempSrcFBOID) {
490 this->deleteFramebuffer(fTempSrcFBOID);
491 }
492 if (fTempDstFBOID) {
493 this->deleteFramebuffer(fTempDstFBOID);
494 }
495 if (fStencilClearFBOID) {
496 this->deleteFramebuffer(fStencilClearFBOID);
497 }
498
499 for (size_t i = 0; i < std::size(fCopyPrograms); ++i) {
500 if (0 != fCopyPrograms[i].fProgram) {
501 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram));
502 }
503 }
504
505 for (size_t i = 0; i < std::size(fMipmapPrograms); ++i) {
506 if (0 != fMipmapPrograms[i].fProgram) {
507 GL_CALL(DeleteProgram(fMipmapPrograms[i].fProgram));
508 }
509 }
510
511 fSamplerObjectCache.reset();
512
513 fFinishCallbacks.callAll(true);
514}
#define GL_CALL(X)
void callAll(bool doDelete)
GrGLuint fProgram
Definition GrGLGpu.h:826
void deleteFramebuffer(GrGLuint fboid)
Definition GrGLGpu.cpp:3192
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310

Member Function Documentation

◆ addFinishedProc()

void GrGLGpu::addFinishedProc ( GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 4244 of file GrGLGpu.cpp.

4245 {
4246 fFinishCallbacks.add(finishedProc, finishedContext);
4247}
void add(GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)

◆ beginCommandBuffer()

void GrGLGpu::beginCommandBuffer ( GrGLRenderTarget rt,
bool  useMultisampleFBO,
const SkIRect bounds,
GrSurfaceOrigin  origin,
const GrOpsRenderPass::LoadAndStoreInfo colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadStore 
)

Definition at line 2200 of file GrGLGpu.cpp.

2203 {
2204 SkASSERT(!fIsExecutingCommandBuffer_DebugOnly);
2205
2206 this->handleDirtyContext();
2207
2208 this->flushRenderTarget(rt, useMultisampleFBO);
2209 SkDEBUGCODE(fIsExecutingCommandBuffer_DebugOnly = true);
2210
2211 if (use_tiled_rendering(this->glCaps(), stencilLoadStore)) {
2212 auto nativeBounds = GrNativeRect::MakeRelativeTo(origin, rt->height(), bounds);
2213 GrGLbitfield preserveMask = (GrLoadOp::kLoad == colorLoadStore.fLoadOp)
2215 SkASSERT(GrLoadOp::kLoad != stencilLoadStore.fLoadOp); // Handled by use_tiled_rendering().
2216 GL_CALL(StartTiling(nativeBounds.fX, nativeBounds.fY, nativeBounds.fWidth,
2217 nativeBounds.fHeight, preserveMask));
2218 }
2219
2220 GrGLbitfield clearMask = 0;
2221 if (GrLoadOp::kClear == colorLoadStore.fLoadOp) {
2222 SkASSERT(!this->caps()->performColorClearsAsDraws());
2223 this->flushClearColor(colorLoadStore.fClearColor);
2224 this->flushColorWrite(true);
2225 clearMask |= GR_GL_COLOR_BUFFER_BIT;
2226 }
2227 if (GrLoadOp::kClear == stencilLoadStore.fLoadOp) {
2228 SkASSERT(!this->caps()->performStencilClearsAsDraws());
2229 GL_CALL(StencilMask(0xffffffff));
2230 GL_CALL(ClearStencil(0));
2231 clearMask |= GR_GL_STENCIL_BUFFER_BIT;
2232 }
2233 if (clearMask) {
2234 this->flushScissorTest(GrScissorTest::kDisabled);
2235 this->disableWindowRectangles();
2236 GL_CALL(Clear(clearMask));
2237 if (clearMask & GR_GL_COLOR_BUFFER_BIT) {
2238 this->didWriteToSurface(rt, origin, nullptr);
2239 }
2240 }
2241}
#define GR_GL_STENCIL_BUFFER_BIT
Definition GrGLDefines.h:22
#define GR_GL_NONE
#define GR_GL_COLOR_BUFFER_BIT
Definition GrGLDefines.h:23
#define GR_GL_COLOR_BUFFER_BIT0
static bool use_tiled_rendering(const GrGLCaps &glCaps, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
Definition GrGLGpu.cpp:2192
unsigned int GrGLbitfield
Definition GrGLTypes.h:104
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
const GrGLCaps & glCaps() const
Definition GrGLGpu.h:108
const GrCaps * caps() const
Definition GrGpu.h:73
void didWriteToSurface(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
Definition GrGpu.cpp:665
void handleDirtyContext()
Definition GrGpu.h:677
int height() const
Definition GrSurface.h:37
static GrNativeRect MakeRelativeTo(GrSurfaceOrigin origin, int rtHeight, SkIRect devRect)
std::array< float, 4 > fClearColor

◆ bindBuffer()

GrGLenum GrGLGpu::bindBuffer ( GrGpuBufferType  type,
const GrBuffer buffer 
)

Definition at line 2143 of file GrGLGpu.cpp.

2143 {
2144 this->handleDirtyContext();
2145
2146 // Index buffer state is tied to the vertex array.
2148 this->bindVertexArray(0);
2149 }
2150
2151 auto* bufferState = this->hwBufferState(type);
2152 if (buffer->isCpuBuffer()) {
2153 if (!bufferState->fBufferZeroKnownBound) {
2154 GL_CALL(BindBuffer(bufferState->fGLTarget, 0));
2155 bufferState->fBufferZeroKnownBound = true;
2156 bufferState->fBoundBufferUniqueID.makeInvalid();
2157 }
2158 } else if (static_cast<const GrGpuBuffer*>(buffer)->uniqueID() !=
2159 bufferState->fBoundBufferUniqueID) {
2160 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(buffer);
2161 GL_CALL(BindBuffer(bufferState->fGLTarget, glBuffer->bufferID()));
2162 bufferState->fBufferZeroKnownBound = false;
2163 bufferState->fBoundBufferUniqueID = glBuffer->uniqueID();
2164 }
2165
2166 return bufferState->fGLTarget;
2167}
GrGLuint bufferID() const
Definition GrGLBuffer.h:29
void bindVertexArray(GrGLuint id)
Definition GrGLGpu.h:117
UniqueID uniqueID() const
static const uint8_t buffer[]

◆ bindFramebuffer()

void GrGLGpu::bindFramebuffer ( GrGLenum  fboTarget,
GrGLuint  fboid 
)

Definition at line 3184 of file GrGLGpu.cpp.

3184 {
3185 GL_CALL(BindFramebuffer(target, fboid));
3187 fBoundDrawFramebuffer = fboid;
3188 }
3189 this->onFBOChanged();
3190}
#define GR_GL_DRAW_FRAMEBUFFER
#define GR_GL_FRAMEBUFFER
uint32_t * target

◆ bindInternalVertexArray()

GrGLAttribArrayState * GrGLGpu::bindInternalVertexArray ( const GrBuffer indexBuffer,
int  numAttribs,
GrPrimitiveRestart  primitiveRestart 
)
inline

Definition at line 156 of file GrGLGpu.h.

157 {
158 auto* attribState = fHWVertexArrayState.bindInternalVertexArray(this, indexBuffer);
159 attribState->enableVertexArrays(this, numAttribs, primitiveRestart);
160 return attribState;
161 }

◆ bindTexture()

void GrGLGpu::bindTexture ( int  unitIdx,
GrSamplerState  samplerState,
const skgpu::Swizzle swizzle,
GrGLTexture texture 
)

Definition at line 2815 of file GrGLGpu.cpp.

2816 {
2818
2819#ifdef SK_DEBUG
2820 if (!this->caps()->npotTextureTileSupport()) {
2821 if (samplerState.isRepeatedX()) {
2822 const int w = texture->width();
2824 }
2825 if (samplerState.isRepeatedY()) {
2826 const int h = texture->height();
2828 }
2829 }
2830#endif
2831
2832 GrGpuResource::UniqueID textureID = texture->uniqueID();
2833 GrGLenum target = texture->target();
2834 if (fHWTextureUnitBindings[unitIdx].boundID(target) != textureID) {
2835 this->setTextureUnit(unitIdx);
2836 GL_CALL(BindTexture(target, texture->textureID()));
2837 fHWTextureUnitBindings[unitIdx].setBoundID(target, textureID);
2838 }
2839
2840 if (samplerState.mipmapped() == skgpu::Mipmapped::kYes) {
2841 if (!this->caps()->mipmapSupport() || texture->mipmapped() == skgpu::Mipmapped::kNo) {
2842 // We should have caught this already.
2843 SkASSERT(!samplerState.isAniso());
2844 samplerState = GrSamplerState(samplerState.wrapModeX(),
2845 samplerState.wrapModeY(),
2846 samplerState.filter(),
2847 GrSamplerState::MipmapMode::kNone);
2848 } else {
2849 SkASSERT(!texture->mipmapsAreDirty());
2850 }
2851 }
2852
2853 auto timestamp = texture->parameters()->resetTimestamp();
2854 bool setAll = timestamp < fResetTimestampForTextureParameters;
2855 const GrGLTextureParameters::SamplerOverriddenState* samplerStateToRecord = nullptr;
2857 if (this->glCaps().useSamplerObjects()) {
2858 fSamplerObjectCache->bindSampler(unitIdx, samplerState);
2859 if (this->glCaps().mustSetAnyTexParameterToEnableMipmapping()) {
2860 if (samplerState.mipmapped() == skgpu::Mipmapped::kYes) {
2861 GrGLenum minFilter = filter_to_gl_min_filter(samplerState.filter(),
2862 samplerState.mipmapMode());
2863 const GrGLTextureParameters::SamplerOverriddenState& oldSamplerState =
2864 texture->parameters()->samplerOverriddenState();
2865 this->setTextureUnit(unitIdx);
2866 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, minFilter));
2867 newSamplerState = oldSamplerState;
2868 newSamplerState.fMinFilter = minFilter;
2869 samplerStateToRecord = &newSamplerState;
2870 }
2871 }
2872 } else {
2873 if (fSamplerObjectCache) {
2874 fSamplerObjectCache->unbindSampler(unitIdx);
2875 }
2876 const GrGLTextureParameters::SamplerOverriddenState& oldSamplerState =
2877 texture->parameters()->samplerOverriddenState();
2878 samplerStateToRecord = &newSamplerState;
2879
2880 newSamplerState.fMinFilter = filter_to_gl_min_filter(samplerState.filter(),
2881 samplerState.mipmapMode());
2882 newSamplerState.fMagFilter = filter_to_gl_mag_filter(samplerState.filter());
2883
2884 newSamplerState.fWrapS = wrap_mode_to_gl_wrap(samplerState.wrapModeX(), this->glCaps());
2885 newSamplerState.fWrapT = wrap_mode_to_gl_wrap(samplerState.wrapModeY(), this->glCaps());
2886
2887 newSamplerState.fMaxAniso = std::min(static_cast<GrGLfloat>(samplerState.maxAniso()),
2888 this->glCaps().maxTextureMaxAnisotropy());
2889
2890 // These are the OpenGL default values.
2891 newSamplerState.fMinLOD = -1000.f;
2892 newSamplerState.fMaxLOD = 1000.f;
2893
2894 if (setAll || newSamplerState.fMagFilter != oldSamplerState.fMagFilter) {
2895 this->setTextureUnit(unitIdx);
2896 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newSamplerState.fMagFilter));
2897 }
2898 if (setAll || newSamplerState.fMinFilter != oldSamplerState.fMinFilter) {
2899 this->setTextureUnit(unitIdx);
2900 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newSamplerState.fMinFilter));
2901 }
2902 if (this->glCaps().mipmapLodControlSupport()) {
2903 if (setAll || newSamplerState.fMinLOD != oldSamplerState.fMinLOD) {
2904 this->setTextureUnit(unitIdx);
2905 GL_CALL(TexParameterf(target, GR_GL_TEXTURE_MIN_LOD, newSamplerState.fMinLOD));
2906 }
2907 if (setAll || newSamplerState.fMaxLOD != oldSamplerState.fMaxLOD) {
2908 this->setTextureUnit(unitIdx);
2909 GL_CALL(TexParameterf(target, GR_GL_TEXTURE_MAX_LOD, newSamplerState.fMaxLOD));
2910 }
2911 }
2912 if (setAll || newSamplerState.fWrapS != oldSamplerState.fWrapS) {
2913 this->setTextureUnit(unitIdx);
2914 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newSamplerState.fWrapS));
2915 }
2916 if (setAll || newSamplerState.fWrapT != oldSamplerState.fWrapT) {
2917 this->setTextureUnit(unitIdx);
2918 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newSamplerState.fWrapT));
2919 }
2920 if (this->glCaps().clampToBorderSupport()) {
2921 // Make sure the border color is transparent black (the default)
2922 if (setAll || oldSamplerState.fBorderColorInvalid) {
2923 this->setTextureUnit(unitIdx);
2924 static const GrGLfloat kTransparentBlack[4] = {0.f, 0.f, 0.f, 0.f};
2925 GL_CALL(TexParameterfv(target, GR_GL_TEXTURE_BORDER_COLOR, kTransparentBlack));
2926 }
2927 }
2928 if (this->caps()->anisoSupport()) {
2929 if (setAll || oldSamplerState.fMaxAniso != newSamplerState.fMaxAniso) {
2930 GL_CALL(TexParameterf(target,
2932 newSamplerState.fMaxAniso));
2933 }
2934 }
2935 }
2936 GrGLTextureParameters::NonsamplerState newNonsamplerState;
2937 newNonsamplerState.fBaseMipMapLevel = 0;
2938 newNonsamplerState.fMaxMipmapLevel = texture->maxMipmapLevel();
2939 newNonsamplerState.fSwizzleIsRGBA = true;
2940
2941 const GrGLTextureParameters::NonsamplerState& oldNonsamplerState =
2942 texture->parameters()->nonsamplerState();
2943 if (this->glCaps().textureSwizzleSupport()) {
2944 if (setAll || !oldNonsamplerState.fSwizzleIsRGBA) {
2945 static constexpr GrGLenum kRGBA[4] {
2946 GR_GL_RED,
2948 GR_GL_BLUE,
2950 };
2951 this->setTextureUnit(unitIdx);
2952 if (GR_IS_GR_GL(this->glStandard())) {
2953 static_assert(sizeof(kRGBA[0]) == sizeof(GrGLint));
2955 reinterpret_cast<const GrGLint*>(kRGBA)));
2956 } else if (GR_IS_GR_GL_ES(this->glStandard())) {
2957 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA.
2958 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, kRGBA[0]));
2959 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, kRGBA[1]));
2960 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, kRGBA[2]));
2961 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_A, kRGBA[3]));
2962 }
2963 }
2964 }
2965 // These are not supported in ES2 contexts
2966 if (this->glCaps().mipmapLevelControlSupport() &&
2967 (texture->textureType() != GrTextureType::kExternal ||
2968 !this->glCaps().dontSetBaseOrMaxLevelForExternalTextures())) {
2969 if (newNonsamplerState.fBaseMipMapLevel != oldNonsamplerState.fBaseMipMapLevel) {
2970 this->setTextureUnit(unitIdx);
2972 newNonsamplerState.fBaseMipMapLevel));
2973 }
2974 if (newNonsamplerState.fMaxMipmapLevel != oldNonsamplerState.fMaxMipmapLevel) {
2975 this->setTextureUnit(unitIdx);
2976 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAX_LEVEL,
2977 newNonsamplerState.fMaxMipmapLevel));
2978 }
2979 }
2980 texture->parameters()->set(samplerStateToRecord, newNonsamplerState,
2981 fResetTimestampForTextureParameters);
2982}
#define GR_GL_RED
#define GR_GL_TEXTURE_MAX_LOD
#define GR_GL_TEXTURE_BASE_LEVEL
#define GR_GL_TEXTURE_MAX_ANISOTROPY
#define GR_GL_TEXTURE_SWIZZLE_B
#define GR_GL_TEXTURE_WRAP_T
#define GR_GL_TEXTURE_MAG_FILTER
#define GR_GL_BLUE
#define GR_GL_GREEN
#define GR_GL_TEXTURE_SWIZZLE_RGBA
#define GR_GL_ALPHA
#define GR_GL_TEXTURE_SWIZZLE_A
#define GR_GL_TEXTURE_BORDER_COLOR
#define GR_GL_TEXTURE_WRAP_S
#define GR_GL_TEXTURE_MIN_LOD
#define GR_GL_TEXTURE_SWIZZLE_R
#define GR_GL_TEXTURE_MAX_LEVEL
#define GR_GL_TEXTURE_SWIZZLE_G
#define GR_GL_TEXTURE_MIN_FILTER
static GrGLenum wrap_mode_to_gl_wrap(GrSamplerState::WrapMode wrapMode, const GrCaps &caps)
Definition GrGLGpu.cpp:240
static GrGLenum filter_to_gl_min_filter(GrSamplerState::Filter filter, GrSamplerState::MipmapMode mm)
Definition GrGLGpu.cpp:219
static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter)
Definition GrGLGpu.cpp:211
float GrGLfloat
Definition GrGLTypes.h:116
int GrGLint
Definition GrGLTypes.h:108
unsigned int GrGLenum
Definition GrGLTypes.h:102
#define GR_IS_GR_GL(standard)
Definition GrGLTypes.h:48
#define GR_IS_GR_GL_ES(standard)
Definition GrGLTypes.h:49
constexpr bool SkIsPow2(T value)
Definition SkMath.h:51
GrGLStandard glStandard() const
Definition GrGLGpu.h:105
constexpr skgpu::Mipmapped mipmapped() const
constexpr WrapMode wrapModeX() const
bool isAniso() const
constexpr Filter filter() const
constexpr bool isRepeatedX() const
constexpr MipmapMode mipmapMode() const
int maxAniso() const
constexpr bool isRepeatedY() const
constexpr WrapMode wrapModeY() const
@ kRGBA
Definition embedder.h:605
FlTexture * texture
SkScalar w
SkScalar h

◆ bindVertexArray()

void GrGLGpu::bindVertexArray ( GrGLuint  id)
inline

Definition at line 117 of file GrGLGpu.h.

117 {
118 fHWVertexArrayState.setVertexArrayID(this, id);
119 }

◆ checkFinishProcs()

void GrGLGpu::checkFinishProcs ( )
overridevirtual

Implements GrGpu.

Definition at line 4369 of file GrGLGpu.cpp.

4369 {
4370 fFinishCallbacks.check();
4371}

◆ clear()

void GrGLGpu::clear ( const GrScissorState scissor,
std::array< float, 4 >  color,
GrRenderTarget target,
bool  useMultisampleFBO,
GrSurfaceOrigin  origin 
)

Definition at line 2169 of file GrGLGpu.cpp.

2173 {
2174 // parent class should never let us get here with no RT
2176 SkASSERT(!this->caps()->performColorClearsAsDraws());
2177 SkASSERT(!scissor.enabled() || !this->caps()->performPartialClearsAsDraws());
2178
2179 this->handleDirtyContext();
2180
2181 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
2182
2183 this->flushRenderTarget(glRT, useMultisampleFBO);
2184 this->flushScissor(scissor, glRT->height(), origin);
2185 this->disableWindowRectangles();
2186 this->flushColorWrite(true);
2187 this->flushClearColor(color);
2189 this->didWriteToSurface(glRT, origin, scissor.enabled() ? &scissor.rect() : nullptr);
2190}
SkColor4f color
bool enabled() const
const SkIRect & rect() const

◆ clearErrorsAndCheckForOOM()

void GrGLGpu::clearErrorsAndCheckForOOM ( )

Definition at line 4377 of file GrGLGpu.cpp.

4377 {
4378 while (this->getErrorAndCheckForOOM() != GR_GL_NO_ERROR) {}
4379}
#define GR_GL_NO_ERROR
GrGLenum getErrorAndCheckForOOM()
Definition GrGLGpu.cpp:4381

◆ clearStencilClip()

void GrGLGpu::clearStencilClip ( const GrScissorState scissor,
bool  insideStencilMask,
GrRenderTarget target,
bool  useMultisampleFBO,
GrSurfaceOrigin  origin 
)

Definition at line 2291 of file GrGLGpu.cpp.

2293 {
2295 SkASSERT(!this->caps()->performStencilClearsAsDraws());
2296 SkASSERT(!scissor.enabled() || !this->caps()->performPartialClearsAsDraws());
2297 this->handleDirtyContext();
2298
2299 GrAttachment* sb = target->getStencilAttachment(useMultisampleFBO);
2300 if (!sb) {
2301 // We should only get here if we marked a proxy as requiring a SB. However,
2302 // the SB creation could later fail. Likely clipping is going to go awry now.
2303 return;
2304 }
2305
2306 GrGLint stencilBitCount = GrBackendFormatStencilBits(sb->backendFormat());
2307#if 0
2308 SkASSERT(stencilBitCount > 0);
2309 GrGLint clipStencilMask = (1 << (stencilBitCount - 1));
2310#else
2311 // we could just clear the clip bit but when we go through
2312 // ANGLE a partial stencil mask will cause clears to be
2313 // turned into draws. Our contract on OpsTask says that
2314 // changing the clip between stencil passes may or may not
2315 // zero the client's clip bits. So we just clear the whole thing.
2316 static const GrGLint clipStencilMask = ~0;
2317#endif
2318 GrGLint value;
2319 if (insideStencilMask) {
2320 value = (1 << (stencilBitCount - 1));
2321 } else {
2322 value = 0;
2323 }
2324 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target);
2325 this->flushRenderTarget(glRT, useMultisampleFBO);
2326
2327 this->flushScissor(scissor, glRT->height(), origin);
2328 this->disableWindowRectangles();
2329
2330 GL_CALL(StencilMask((uint32_t) clipStencilMask));
2331 GL_CALL(ClearStencil(value));
2333 fHWStencilSettings.invalidate();
2334}
int GrBackendFormatStencilBits(const GrBackendFormat &format)
virtual GrBackendFormat backendFormat() const =0
uint8_t value

◆ compile()

bool GrGLGpu::compile ( const GrProgramDesc ,
const GrProgramInfo  
)
overridevirtual

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

Implements GrGpu.

Definition at line 4012 of file GrGLGpu.cpp.

4012 {
4014
4015 sk_sp<GrGLProgram> tmp = fProgramCache->findOrCreateProgram(this->getContext(),
4016 desc, programInfo, &stat);
4017 if (!tmp) {
4018 return false;
4019 }
4020
4022}
GrDirectContext * getContext()
Definition GrGpu.h:67

◆ ctxInfo()

const GrGLContextInfo & GrGLGpu::ctxInfo ( ) const
inline

Definition at line 104 of file GrGLGpu.h.

104{ return *fGLContext; }

◆ currentProgram()

GrGLProgram * GrGLGpu::currentProgram ( )
inline

Definition at line 144 of file GrGLGpu.h.

144 {
145 this->handleDirtyContext();
146 return fHWProgram.get();
147 }
T * get() const
Definition SkRefCnt.h:303

◆ deleteBackendTexture()

void GrGLGpu::deleteBackendTexture ( const GrBackendTexture )
overridevirtual

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.

Implements GrGpu.

Definition at line 4003 of file GrGLGpu.cpp.

4003 {
4004 SkASSERT(GrBackendApi::kOpenGL == tex.backend());
4005
4008 GL_CALL(DeleteTextures(1, &info.fID));
4009 }
4010}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)

◆ deleteFence()

void GrGLGpu::deleteFence ( GrGLsync  fence)

Definition at line 4335 of file GrGLGpu.cpp.

4335 {
4336 if (this->glCaps().fenceSyncSupport()) {
4337 this->deleteSync(fence);
4338 }
4339}
void deleteSync(GrGLsync)
Definition GrGLGpu.cpp:4394

◆ deleteFramebuffer()

void GrGLGpu::deleteFramebuffer ( GrGLuint  fboid)

Definition at line 3192 of file GrGLGpu.cpp.

3192 {
3193 // We're relying on the GL state shadowing being correct in the workaround code below so we
3194 // need to handle a dirty context.
3195 this->handleDirtyContext();
3196 if (fboid == fBoundDrawFramebuffer &&
3197 this->caps()->workarounds().unbind_attachments_on_bound_render_fbo_delete) {
3198 // This workaround only applies to deleting currently bound framebuffers
3199 // on Adreno 420. Because this is a somewhat rare case, instead of
3200 // tracking all the attachments of every framebuffer instead just always
3201 // unbind all attachments.
3202 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0,
3203 GR_GL_RENDERBUFFER, 0));
3204 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT,
3205 GR_GL_RENDERBUFFER, 0));
3206 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT,
3207 GR_GL_RENDERBUFFER, 0));
3208 }
3209
3210 GL_CALL(DeleteFramebuffers(1, &fboid));
3211
3212 // Deleting the currently bound framebuffer rebinds to 0.
3213 if (fboid == fBoundDrawFramebuffer) {
3214 this->onFBOChanged();
3215 }
3216}
#define GR_GL_RENDERBUFFER
#define GR_GL_STENCIL_ATTACHMENT
#define GR_GL_DEPTH_ATTACHMENT
#define GR_GL_COLOR_ATTACHMENT0

◆ deleteSync()

void GrGLGpu::deleteSync ( GrGLsync  sync)

Definition at line 4394 of file GrGLGpu.cpp.

4394 {
4395 if (this->glCaps().fenceType() == GrGLCaps::FenceType::kNVFence) {
4396 GrGLuint nvFence = SkToUInt(reinterpret_cast<intptr_t>(sync));
4397 GL_CALL(DeleteFences(1, &nvFence));
4398 } else {
4399 GL_CALL(DeleteSync(sync));
4400 }
4401}
unsigned int GrGLuint
Definition GrGLTypes.h:113
constexpr unsigned SkToUInt(S x)
Definition SkTo.h:30

◆ didDrawTo()

void GrGLGpu::didDrawTo ( GrRenderTarget rt)

Definition at line 2134 of file GrGLGpu.cpp.

2134 {
2135 SkASSERT(fHWWriteToColor != kUnknown_TriState);
2136 if (fHWWriteToColor == kYes_TriState) {
2137 // The bounds are only used to check for empty and we don't know the bounds. The origin
2138 // is irrelevant if there are no bounds.
2139 this->didWriteToSurface(rt, kTopLeft_GrSurfaceOrigin, /*bounds=*/nullptr);
2140 }
2141}
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148

◆ disconnect()

void GrGLGpu::disconnect ( DisconnectType  type)
overridevirtual

Reimplemented from GrGpu.

Definition at line 516 of file GrGLGpu.cpp.

516 {
519 if (fHWProgramID) {
520 GL_CALL(UseProgram(0));
521 }
522 if (fTempSrcFBOID) {
523 this->deleteFramebuffer(fTempSrcFBOID);
524 }
525 if (fTempDstFBOID) {
526 this->deleteFramebuffer(fTempDstFBOID);
527 }
528 if (fStencilClearFBOID) {
529 this->deleteFramebuffer(fStencilClearFBOID);
530 }
531 for (size_t i = 0; i < std::size(fCopyPrograms); ++i) {
532 if (fCopyPrograms[i].fProgram) {
533 GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram));
534 }
535 }
536 for (size_t i = 0; i < std::size(fMipmapPrograms); ++i) {
537 if (fMipmapPrograms[i].fProgram) {
538 GL_CALL(DeleteProgram(fMipmapPrograms[i].fProgram));
539 }
540 }
541
542 if (fSamplerObjectCache) {
543 fSamplerObjectCache->release();
544 }
545 } else {
546 if (fProgramCache) {
547 fProgramCache->abandon();
548 }
549 if (fSamplerObjectCache) {
550 fSamplerObjectCache->abandon();
551 }
552 }
553
554 fHWProgram.reset();
555 fProgramCache->reset();
556 fProgramCache.reset();
557
558 fHWProgramID = 0;
559 fTempSrcFBOID = 0;
560 fTempDstFBOID = 0;
561 fStencilClearFBOID = 0;
562 fCopyProgramArrayBuffer.reset();
563 for (size_t i = 0; i < std::size(fCopyPrograms); ++i) {
564 fCopyPrograms[i].fProgram = 0;
565 }
566 fMipmapProgramArrayBuffer.reset();
567 for (size_t i = 0; i < std::size(fMipmapPrograms); ++i) {
568 fMipmapPrograms[i].fProgram = 0;
569 }
570
571 fFinishCallbacks.callAll(/* doDelete */ DisconnectType::kCleanup == type);
572}
virtual void disconnect(DisconnectType)
Definition GrGpu.cpp:51

◆ drawSingleIntoMSAAFBO()

void GrGLGpu::drawSingleIntoMSAAFBO ( GrGLRenderTarget rt,
const SkIRect drawBounds 
)
inline

Definition at line 179 of file GrGLGpu.h.

179 {
180 this->copySurfaceAsDraw(rt, true/*drawToMultisampleFBO*/, rt, drawBounds, drawBounds,
181 GrSamplerState::Filter::kNearest);
182 }

◆ endCommandBuffer()

void GrGLGpu::endCommandBuffer ( GrGLRenderTarget rt,
bool  useMultisampleFBO,
const GrOpsRenderPass::LoadAndStoreInfo colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadStore 
)

Definition at line 2243 of file GrGLGpu.cpp.

2245 {
2246 SkASSERT(fIsExecutingCommandBuffer_DebugOnly);
2247
2248 this->handleDirtyContext();
2249
2250 if (rt->uniqueID() != fHWBoundRenderTargetUniqueID ||
2251 useMultisampleFBO != fHWBoundFramebufferIsMSAA) {
2252 // The framebuffer binding changed in the middle of a command buffer. We should have already
2253 // printed a warning during onFBOChanged.
2254 return;
2255 }
2256
2257 if (GrGLCaps::kNone_InvalidateFBType != this->glCaps().invalidateFBType()) {
2258 STArray<2, GrGLenum> discardAttachments;
2259 if (GrStoreOp::kDiscard == colorLoadStore.fStoreOp) {
2260 discardAttachments.push_back(
2261 rt->isFBO0(useMultisampleFBO) ? GR_GL_COLOR : GR_GL_COLOR_ATTACHMENT0);
2262 }
2263 if (GrStoreOp::kDiscard == stencilLoadStore.fStoreOp) {
2264 discardAttachments.push_back(
2265 rt->isFBO0(useMultisampleFBO) ? GR_GL_STENCIL : GR_GL_STENCIL_ATTACHMENT);
2266 }
2267
2268 if (!discardAttachments.empty()) {
2269 if (GrGLCaps::kInvalidate_InvalidateFBType == this->glCaps().invalidateFBType()) {
2270 GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, discardAttachments.size(),
2271 discardAttachments.begin()));
2272 } else {
2273 SkASSERT(GrGLCaps::kDiscard_InvalidateFBType == this->glCaps().invalidateFBType());
2274 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, discardAttachments.size(),
2275 discardAttachments.begin()));
2276 }
2277 }
2278 }
2279
2280 if (use_tiled_rendering(this->glCaps(), stencilLoadStore)) {
2281 GrGLbitfield preserveMask = (GrStoreOp::kStore == colorLoadStore.fStoreOp)
2283 // Handled by use_tiled_rendering().
2284 SkASSERT(GrStoreOp::kStore != stencilLoadStore.fStoreOp);
2285 GL_CALL(EndTiling(preserveMask));
2286 }
2287
2288 SkDEBUGCODE(fIsExecutingCommandBuffer_DebugOnly = false);
2289}
#define GR_GL_STENCIL
#define GR_GL_COLOR
@ kNone_InvalidateFBType
Definition GrGLCaps.h:95
@ kDiscard_InvalidateFBType
Definition GrGLCaps.h:96
@ kInvalidate_InvalidateFBType
Definition GrGLCaps.h:97
bool isFBO0(bool multisample) const
bool empty() const
Definition SkTArray.h:194
int size() const
Definition SkTArray.h:416

◆ finishOutstandingGpuWork()

void GrGLGpu::finishOutstandingGpuWork ( )
overridevirtual

Implements GrGpu.

Definition at line 4373 of file GrGLGpu.cpp.

4373 {
4374 GL_CALL(Finish());
4375}

◆ flushGLState()

bool GrGLGpu::flushGLState ( GrRenderTarget renderTarget,
bool  useMultisampleFBO,
const GrProgramInfo programInfo 
)

Definition at line 2065 of file GrGLGpu.cpp.

2066 {
2067 this->handleDirtyContext();
2068
2069 sk_sp<GrGLProgram> program = fProgramCache->findOrCreateProgram(this->getContext(),
2070 programInfo);
2071 if (!program) {
2072 GrCapsDebugf(this->caps(), "Failed to create program!\n");
2073 return false;
2074 }
2075
2076 this->flushProgram(std::move(program));
2077
2078 // Swizzle the blend to match what the shader will output.
2079 this->flushBlendAndColorWrite(programInfo.pipeline().getXferProcessor().getBlendInfo(),
2080 programInfo.pipeline().writeSwizzle());
2081
2082 fHWProgram->updateUniforms(renderTarget, programInfo);
2083
2084 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
2085 GrStencilSettings stencil;
2086 if (programInfo.isStencilEnabled()) {
2087 SkASSERT(glRT->getStencilAttachment(useMultisampleFBO));
2088 stencil.reset(*programInfo.userStencilSettings(),
2089 programInfo.pipeline().hasStencilClip(),
2090 glRT->numStencilBits(useMultisampleFBO));
2091 }
2092 this->flushStencil(stencil, programInfo.origin());
2093 this->flushScissorTest(GrScissorTest(programInfo.pipeline().isScissorTestEnabled()));
2094 this->flushWindowRectangles(programInfo.pipeline().getWindowRectsState(),
2095 glRT, programInfo.origin());
2096 this->flushConservativeRasterState(programInfo.pipeline().usesConservativeRaster());
2097 this->flushWireframeState(programInfo.pipeline().isWireframe());
2098
2099 // This must come after textures are flushed because a texture may need
2100 // to be msaa-resolved (which will modify bound FBO state).
2101 this->flushRenderTarget(glRT, useMultisampleFBO);
2102
2103 return true;
2104}
#define GrCapsDebugf(caps,...)
GrScissorTest
void flushProgram(sk_sp< GrGLProgram >)
Definition GrGLGpu.cpp:2106
void updateUniforms(const GrRenderTarget *, const GrProgramInfo &)
const skgpu::Swizzle & writeSwizzle() const
Definition GrPipeline.h:197
bool hasStencilClip() const
Definition GrPipeline.h:174
bool isScissorTestEnabled() const
Definition GrPipeline.h:163
bool isWireframe() const
Definition GrPipeline.h:170
bool usesConservativeRaster() const
Definition GrPipeline.h:169
const GrWindowRectsState & getWindowRectsState() const
Definition GrPipeline.h:167
const GrXferProcessor & getXferProcessor() const
Definition GrPipeline.h:116
GrSurfaceOrigin origin() const
const GrPipeline & pipeline() const
const GrUserStencilSettings * userStencilSettings() const
bool isStencilEnabled() const
GrAttachment * getStencilAttachment(bool useMSAASurface) const
int numStencilBits(bool useMSAASurface) const
void reset(const GrUserStencilSettings &, bool hasStencilClip, int numStencilBits)
skgpu::BlendInfo getBlendInfo() const

◆ flushProgram() [1/2]

void GrGLGpu::flushProgram ( GrGLuint  id)

Definition at line 2123 of file GrGLGpu.cpp.

2123 {
2124 SkASSERT(id);
2125 if (fHWProgramID == id) {
2126 SkASSERT(!fHWProgram);
2127 return;
2128 }
2129 fHWProgram.reset();
2130 GL_CALL(UseProgram(id));
2131 fHWProgramID = id;
2132}
const uintptr_t id

◆ flushProgram() [2/2]

void GrGLGpu::flushProgram ( sk_sp< GrGLProgram program)

Definition at line 2106 of file GrGLGpu.cpp.

2106 {
2107 if (!program) {
2108 fHWProgram.reset();
2109 fHWProgramID = 0;
2110 return;
2111 }
2112 SkASSERT((program == fHWProgram) == (fHWProgramID == program->programID()));
2113 if (program == fHWProgram) {
2114 return;
2115 }
2116 auto id = program->programID();
2117 SkASSERT(id);
2118 GL_CALL(UseProgram(id));
2119 fHWProgram = std::move(program);
2120 fHWProgramID = id;
2121}
GrGLuint programID() const
Definition GrGLProgram.h:78

◆ flushScissorRect()

void GrGLGpu::flushScissorRect ( const SkIRect scissor,
int  rtHeight,
GrSurfaceOrigin  rtOrigin 
)

Definition at line 2005 of file GrGLGpu.cpp.

2005 {
2006 SkASSERT(fHWScissorSettings.fEnabled == TriState::kYes_TriState);
2007 auto nativeScissor = GrNativeRect::MakeRelativeTo(rtOrigin, rtHeight, scissor);
2008 if (fHWScissorSettings.fRect != nativeScissor) {
2009 GL_CALL(Scissor(nativeScissor.fX, nativeScissor.fY, nativeScissor.fWidth,
2010 nativeScissor.fHeight));
2011 fHWScissorSettings.fRect = nativeScissor;
2012 }
2013}

◆ flushViewport()

void GrGLGpu::flushViewport ( const SkIRect viewport,
int  rtHeight,
GrSurfaceOrigin  rtOrigin 
)

Definition at line 2015 of file GrGLGpu.cpp.

2015 {
2016 auto nativeViewport = GrNativeRect::MakeRelativeTo(rtOrigin, rtHeight, viewport);
2017 if (fHWViewport != nativeViewport) {
2018 GL_CALL(Viewport(nativeViewport.fX, nativeViewport.fY,
2019 nativeViewport.fWidth, nativeViewport.fHeight));
2020 fHWViewport = nativeViewport;
2021 }
2022}

◆ getErrorAndCheckForOOM()

GrGLenum GrGLGpu::getErrorAndCheckForOOM ( )

Definition at line 4381 of file GrGLGpu.cpp.

4381 {
4382#if GR_GL_CHECK_ERROR
4383 if (this->glInterface()->checkAndResetOOMed()) {
4384 this->setOOMed();
4385 }
4386#endif
4387 GrGLenum error = this->fGLContext->glInterface()->fFunctions.fGetError();
4388 if (error == GR_GL_OUT_OF_MEMORY) {
4389 this->setOOMed();
4390 }
4391 return error;
4392}
#define GR_GL_OUT_OF_MEMORY
const GrGLInterface * glInterface() const
Definition GrGLGpu.h:103
void setOOMed()
Definition GrGpu.h:701
bool checkAndResetOOMed()
Definition GrGpu.cpp:783
const uint8_t uint32_t uint32_t GError ** error

◆ getPreferredStencilFormat()

GrBackendFormat GrGLGpu::getPreferredStencilFormat ( const GrBackendFormat format)
inlineoverrideprivatevirtual

Implements GrGpu.

Definition at line 346 of file GrGLGpu.h.

346 {
347 int idx = this->getCompatibleStencilIndex(GrBackendFormats::AsGLFormat(format));
348 if (idx < 0) {
349 return {};
350 }
351 return GrBackendFormats::MakeGL(GrGLFormatToEnum(this->glCaps().stencilFormats()[idx]),
353 }
#define GR_GL_TEXTURE_NONE
static constexpr GrGLenum GrGLFormatToEnum(GrGLFormat format)
Definition GrGLUtil.h:445
uint32_t uint32_t * format
SK_API GrGLFormat AsGLFormat(const GrBackendFormat &)
SK_API GrBackendFormat MakeGL(GrGLenum format, GrGLenum target)

◆ glCaps()

const GrGLCaps & GrGLGpu::glCaps ( ) const
inline

Definition at line 108 of file GrGLGpu.h.

108{ return *fGLContext->caps(); }

◆ glContext()

const GrGLContext & GrGLGpu::glContext ( ) const
inline

Definition at line 101 of file GrGLGpu.h.

101{ return *fGLContext; }

◆ glInterface()

const GrGLInterface * GrGLGpu::glInterface ( ) const
inline

Definition at line 103 of file GrGLGpu.h.

103{ return fGLContext->glInterface(); }

◆ glslGeneration()

SkSL::GLSLGeneration GrGLGpu::glslGeneration ( ) const
inline

Definition at line 107 of file GrGLGpu.h.

107{ return fGLContext->glslGeneration(); }

◆ glStandard()

GrGLStandard GrGLGpu::glStandard ( ) const
inline

Definition at line 105 of file GrGLGpu.h.

105{ return fGLContext->standard(); }

◆ glVersion()

GrGLVersion GrGLGpu::glVersion ( ) const
inline

Definition at line 106 of file GrGLGpu.h.

106{ return fGLContext->version(); }

◆ insertFence()

GrGLsync GrGLGpu::insertFence ( )

Definition at line 4286 of file GrGLGpu.cpp.

4286 {
4287 if (!this->glCaps().fenceSyncSupport()) {
4288 return nullptr;
4289 }
4290 GrGLsync sync;
4291 if (this->glCaps().fenceType() == GrGLCaps::FenceType::kNVFence) {
4292 static_assert(sizeof(GrGLsync) >= sizeof(GrGLuint));
4293 GrGLuint fence = 0;
4294 GL_CALL(GenFences(1, &fence));
4295 GL_CALL(SetFence(fence, GR_GL_ALL_COMPLETED));
4296 sync = reinterpret_cast<GrGLsync>(static_cast<intptr_t>(fence));
4297 } else {
4298 GL_CALL_RET(sync, FenceSync(GR_GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
4299 }
4300 this->setNeedsFlush();
4301 return sync;
4302}
#define GR_GL_ALL_COMPLETED
#define GR_GL_SYNC_GPU_COMMANDS_COMPLETE
#define GL_CALL_RET(R, X)
struct __GLsync * GrGLsync
Definition GrGLTypes.h:129

◆ insertSemaphore()

void GrGLGpu::insertSemaphore ( GrSemaphore semaphore)
overridevirtual

Implements GrGpu.

Definition at line 4352 of file GrGLGpu.cpp.

4352 {
4353 SkASSERT(semaphore);
4354 GrGLSemaphore* glSem = static_cast<GrGLSemaphore*>(semaphore);
4355
4356 GrGLsync sync;
4357 GL_CALL_RET(sync, FenceSync(GR_GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
4358 glSem->setSync(sync);
4359 this->setNeedsFlush();
4360}
void setSync(const GrGLsync &sync)

◆ invalidateBoundRenderTarget()

void GrGLGpu::invalidateBoundRenderTarget ( )
inline

Definition at line 205 of file GrGLGpu.h.

205 {
206 fHWBoundRenderTargetUniqueID.makeInvalid();
207 }

◆ Make()

std::unique_ptr< GrGpu > GrGLGpu::Make ( sk_sp< const GrGLInterface interface,
const GrContextOptions options,
GrDirectContext direct 
)
static

Definition at line 408 of file GrGLGpu.cpp.

410 {
411#if !defined(SK_DISABLE_LEGACY_GL_MAKE_NATIVE_INTERFACE)
412 if (!interface) {
413 interface = GrGLMakeNativeInterface();
414 if (!interface) {
415 return nullptr;
416 }
417 }
418#else
419 if (!interface) {
420 return nullptr;
421 }
422#endif
423#ifdef USE_NSIGHT
424 const_cast<GrContextOptions&>(options).fSuppressPathRendering = true;
425#endif
426 auto glContext = GrGLContext::Make(std::move(interface), options);
427 if (!glContext) {
428 return nullptr;
429 }
430 return std::unique_ptr<GrGpu>(new GrGLGpu(std::move(glContext), direct));
431}
const char * options
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
static std::unique_ptr< GrGLContext > Make(sk_sp< const GrGLInterface >, const GrContextOptions &)
const GrGLContext & glContext() const
Definition GrGLGpu.h:101

◆ makeMSAAAttachment()

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

Implements GrGpu.

Definition at line 1975 of file GrGLGpu.cpp.

1977 {
1978 SkASSERT(isMemoryless == GrMemoryless::kNo);
1980 this, dimensions, numSamples, GrBackendFormats::AsGLFormat(format));
1981}
static sk_sp< GrGLAttachment > MakeMSAA(GrGLGpu *gpu, SkISize dimensions, int sampleCnt, GrGLFormat format)

◆ makeSemaphore()

std::unique_ptr< GrSemaphore > GrGLGpu::makeSemaphore ( bool  isOwned)
overridevirtual

Implements GrGpu.

Definition at line 4341 of file GrGLGpu.cpp.

4341 {
4342 SkASSERT(this->caps()->semaphoreSupport());
4343 return GrGLSemaphore::Make(this, isOwned);
4344}
static std::unique_ptr< GrGLSemaphore > Make(GrGLGpu *gpu, bool isOwned)

◆ makeStencilAttachment()

sk_sp< GrAttachment > GrGLGpu::makeStencilAttachment ( const GrBackendFormat colorFormat,
SkISize  dimensions,
int  numStencilSamples 
)
overridevirtual

Implements GrGpu.

Definition at line 1960 of file GrGLGpu.cpp.

1961 {
1962 int sIdx = this->getCompatibleStencilIndex(GrBackendFormats::AsGLFormat(colorFormat));
1963 if (sIdx < 0) {
1964 return nullptr;
1965 }
1966 GrGLFormat sFmt = this->glCaps().stencilFormats()[sIdx];
1967
1968 auto stencil = GrGLAttachment::MakeStencil(this, dimensions, numStencilSamples, sFmt);
1969 if (stencil) {
1971 }
1972 return stencil;
1973}
GrGLFormat
Definition GrGLTypes.h:59
static sk_sp< GrGLAttachment > MakeStencil(GrGLGpu *gpu, SkISize dimensions, int sampleCnt, GrGLFormat format)
const skia_private::TArray< GrGLFormat, true > & stencilFormats() const
Definition GrGLCaps.h:223
void incStencilAttachmentCreates()
Definition GrGpu.h:539
Stats fStats
Definition GrGpu.h:703

◆ notifyVertexArrayDelete()

void GrGLGpu::notifyVertexArrayDelete ( GrGLuint  id)
inline

Definition at line 123 of file GrGLGpu.h.

123 {
124 fHWVertexArrayState.notifyVertexArrayDelete(id);
125 }

◆ onClearBackendTexture()

bool GrGLGpu::onClearBackendTexture ( const GrBackendTexture backendTexture,
sk_sp< skgpu::RefCntedCallback finishedCallback,
std::array< float, 4 >  color 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 3957 of file GrGLGpu.cpp.

3959 {
3960 this->handleDirtyContext();
3961
3964
3965 int numMipLevels = 1;
3966 if (backendTexture.hasMipmaps()) {
3967 numMipLevels =
3968 SkMipmap::ComputeLevelCount(backendTexture.width(), backendTexture.height()) + 1;
3969 }
3970
3971 GrGLFormat glFormat = GrGLFormatFromGLEnum(info.fFormat);
3972
3973 this->bindTextureToScratchUnit(info.fTarget, info.fID);
3974
3975 // If we have mips make sure the base level is set to 0 and the max level set to numMipLevels-1
3976 // so that the uploads go to the right levels.
3977 if (numMipLevels && this->glCaps().mipmapLevelControlSupport()) {
3978 auto params = get_gl_texture_params(backendTexture);
3979 GrGLTextureParameters::NonsamplerState nonsamplerState = params->nonsamplerState();
3980 if (params->nonsamplerState().fBaseMipMapLevel != 0) {
3981 GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_BASE_LEVEL, 0));
3982 nonsamplerState.fBaseMipMapLevel = 0;
3983 }
3984 if (params->nonsamplerState().fMaxMipmapLevel != (numMipLevels - 1)) {
3985 GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_MAX_LEVEL, numMipLevels - 1));
3986 nonsamplerState.fBaseMipMapLevel = numMipLevels - 1;
3987 }
3988 params->set(nullptr, nonsamplerState, fResetTimestampForTextureParameters);
3989 }
3990
3991 uint32_t levelMask = (1 << numMipLevels) - 1;
3992 bool result = this->uploadColorToTex(glFormat,
3993 backendTexture.dimensions(),
3994 info.fTarget,
3995 color,
3996 levelMask);
3997
3998 // Unbind this texture from the scratch texture unit.
3999 this->bindTextureToScratchUnit(info.fTarget, 0);
4000 return result;
4001}
static sk_sp< GrGLTextureParameters > get_gl_texture_params(const GrBackendTexture &backendTex)
Definition GrGLGpu.cpp:747
static constexpr GrGLFormat GrGLFormatFromGLEnum(GrGLenum glFormat)
Definition GrGLUtil.h:409
#define SkAssertResult(cond)
Definition SkAssert.h:123
SkISize dimensions() const
bool hasMipmaps() const
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134
const EmbeddedViewParams * params
GAsyncResult * result

◆ onCopySurface()

bool GrGLGpu::onCopySurface ( GrSurface dst,
const SkIRect dstRect,
GrSurface src,
const SkIRect srcRect,
GrSamplerState::Filter  filter 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 3218 of file GrGLGpu.cpp.

3220 {
3221 // Don't prefer copying as a draw if the dst doesn't already have a FBO object.
3222 // This implicitly handles this->glCaps().useDrawInsteadOfAllRenderTargetWrites().
3223 bool preferCopy = SkToBool(dst->asRenderTarget());
3224 bool scalingCopy = dstRect.size() != srcRect.size();
3225 auto dstFormat = GrBackendFormats::AsGLFormat(dst->backendFormat());
3226 if (preferCopy &&
3227 this->glCaps().canCopyAsDraw(dstFormat, SkToBool(src->asTexture()), scalingCopy)) {
3228 GrRenderTarget* dstRT = dst->asRenderTarget();
3229 bool drawToMultisampleFBO = dstRT && dstRT->numSamples() > 1;
3230 if (this->copySurfaceAsDraw(dst, drawToMultisampleFBO, src, srcRect, dstRect, filter)) {
3231 return true;
3232 }
3233 }
3234
3235 // Prefer copying as with glCopyTexSubImage when the dimensions are the same.
3236 if (!scalingCopy && can_copy_texsubimage(dst, src, this->glCaps())) {
3237 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstRect.topLeft());
3238 return true;
3239 }
3240
3241 if (can_blit_framebuffer_for_copy_surface(dst, src, srcRect, dstRect, this->glCaps())) {
3242 return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstRect, filter);
3243 }
3244
3245 if (!preferCopy &&
3246 this->glCaps().canCopyAsDraw(dstFormat, SkToBool(src->asTexture()), scalingCopy)) {
3247 GrRenderTarget* dstRT = dst->asRenderTarget();
3248 bool drawToMultisampleFBO = dstRT && dstRT->numSamples() > 1;
3249 if (this->copySurfaceAsDraw(dst, drawToMultisampleFBO, src, srcRect, dstRect, filter)) {
3250 return true;
3251 }
3252 }
3253
3254 return false;
3255}
static bool can_blit_framebuffer_for_copy_surface(const GrSurface *dst, const GrSurface *src, const SkIRect &srcRect, const SkIRect &dstRect, const GrGLCaps &caps)
Definition GrGLGpu.cpp:3053
static bool can_copy_texsubimage(const GrSurface *dst, const GrSurface *src, const GrGLCaps &caps)
Definition GrGLGpu.cpp:3101
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
int numSamples() const
dst
Definition cp.py:12
constexpr SkISize size() const
Definition SkRect.h:172
constexpr SkIPoint topLeft() const
Definition SkRect.h:151

◆ onCreateBackendTexture()

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

Implements GrGpu.

Definition at line 3896 of file GrGLGpu.cpp.

3901 {
3902 this->handleDirtyContext();
3903
3905 if (glFormat == GrGLFormat::kUnknown) {
3906 return {};
3907 }
3908
3909 int numMipLevels = 1;
3910 if (mipmapped == skgpu::Mipmapped::kYes) {
3911 numMipLevels = SkMipmap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1;
3912 }
3913
3914 // Compressed formats go through onCreateCompressedBackendTexture
3915 SkASSERT(!GrGLFormatIsCompressed(glFormat));
3916
3919
3920 if (glFormat == GrGLFormat::kUnknown) {
3921 return {};
3922 }
3923 switch (format.textureType()) {
3926 return {};
3927 case GrTextureType::k2D:
3928 info.fTarget = GR_GL_TEXTURE_2D;
3929 break;
3931 if (!this->glCaps().rectangleTextureSupport() || mipmapped == skgpu::Mipmapped::kYes) {
3932 return {};
3933 }
3934 info.fTarget = GR_GL_TEXTURE_RECTANGLE;
3935 break;
3936 }
3937 info.fFormat = GrGLFormatToEnum(glFormat);
3938 info.fID = this->createTexture(dimensions, glFormat, info.fTarget, renderable, &initialState,
3939 numMipLevels, isProtected, label);
3940 if (!info.fID) {
3941 return {};
3942 }
3943 info.fProtected = isProtected;
3944
3945 // Unbind this texture from the scratch texture unit.
3946 this->bindTextureToScratchUnit(info.fTarget, 0);
3947
3948 auto parameters = sk_make_sp<GrGLTextureParameters>();
3949 // The non-sampler params are still at their default values.
3950 parameters->set(&initialState, GrGLTextureParameters::NonsamplerState(),
3951 fResetTimestampForTextureParameters);
3952
3954 dimensions.width(), dimensions.height(), mipmapped, info, std::move(parameters), label);
3955}
#define GR_GL_TEXTURE_2D
#define GR_GL_TEXTURE_RECTANGLE
bool GrGLFormatIsCompressed(GrGLFormat format)
Definition GrGLUtil.cpp:812
SK_API GrBackendTexture MakeGL(int width, int height, skgpu::Mipmapped, const GrGLTextureInfo &glInfo, std::string_view label={})
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ onCreateBuffer()

sk_sp< GrGpuBuffer > GrGLGpu::onCreateBuffer ( size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1985 of file GrGLGpu.cpp.

1987 {
1988 return GrGLBuffer::Make(this, size, intendedType, accessPattern);
1989}
static sk_sp< GrGLBuffer > Make(GrGLGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern)

◆ onCreateCompressedBackendTexture()

GrBackendTexture GrGLGpu::onCreateCompressedBackendTexture ( SkISize  dimensions,
const GrBackendFormat format,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1667 of file GrGLGpu.cpp.

1670 {
1671 if (isProtected == GrProtected::kYes && !this->glCaps().supportsProtectedContent()) {
1672 return {};
1673 }
1674
1675 this->handleDirtyContext();
1676
1678 if (glFormat == GrGLFormat::kUnknown) {
1679 return {};
1680 }
1681
1683
1686
1687 info.fTarget = GR_GL_TEXTURE_2D;
1688 info.fFormat = GrGLFormatToEnum(glFormat);
1689 info.fProtected = isProtected;
1690 info.fID = this->createCompressedTexture2D(dimensions, compression, glFormat,
1691 mipmapped, info.fProtected, &initialState);
1692 if (!info.fID) {
1693 return {};
1694 }
1695
1696 // Unbind this texture from the scratch texture unit.
1697 this->bindTextureToScratchUnit(GR_GL_TEXTURE_2D, 0);
1698
1699 auto parameters = sk_make_sp<GrGLTextureParameters>();
1700 // The non-sampler params are still at their default values.
1701 parameters->set(&initialState, GrGLTextureParameters::NonsamplerState(),
1702 fResetTimestampForTextureParameters);
1703
1705 dimensions.width(), dimensions.height(), mipmapped, info, std::move(parameters));
1706}
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)

◆ onCreateCompressedTexture()

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

Implements GrGpu.

Definition at line 1619 of file GrGLGpu.cpp.

1625 {
1626 if (isProtected == GrProtected::kYes && !this->glCaps().supportsProtectedContent()) {
1627 return nullptr;
1628 }
1630
1633 desc.fSize = dimensions;
1634 desc.fTarget = GR_GL_TEXTURE_2D;
1637 desc.fIsProtected = isProtected;
1638 desc.fID = this->createCompressedTexture2D(desc.fSize, compression, desc.fFormat,
1639 mipmapped, desc.fIsProtected, &initialState);
1640 if (!desc.fID) {
1641 return nullptr;
1642 }
1643
1644 if (data) {
1645 if (!this->uploadCompressedTexData(compression, desc.fFormat, dimensions, mipmapped,
1646 GR_GL_TEXTURE_2D, data, dataSize)) {
1647 GL_CALL(DeleteTextures(1, &desc.fID));
1648 return nullptr;
1649 }
1650 }
1651
1652 // Unbind this texture from the scratch texture unit.
1653 this->bindTextureToScratchUnit(GR_GL_TEXTURE_2D, 0);
1654
1655 GrMipmapStatus mipmapStatus = mipmapped == skgpu::Mipmapped::kYes
1658
1659 auto tex = sk_make_sp<GrGLTexture>(this, budgeted, desc, mipmapStatus,
1660 /*label=*/"GLGpuCreateCompressedTexture");
1661 // The non-sampler params are still at their default values.
1662 tex->parameters()->set(&initialState, GrGLTextureParameters::NonsamplerState(),
1663 fResetTimestampForTextureParameters);
1664 return tex;
1665}
GrMipmapStatus

◆ onCreateTexture()

sk_sp< GrTexture > GrGLGpu::onCreateTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrRenderable  renderable,
int  renderTargetSampleCnt,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
int  mipLevelCount,
uint32_t  levelClearMask,
std::string_view  label 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1508 of file GrGLGpu.cpp.

1516 {
1517 if (isProtected == GrProtected::kYes && !this->glCaps().supportsProtectedContent()) {
1518 return nullptr;
1519 }
1520 SkASSERT(GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType() || renderTargetSampleCnt == 1);
1521
1522 SkASSERT(mipLevelCount > 0);
1523 GrMipmapStatus mipmapStatus =
1526 GrGLTexture::Desc texDesc;
1527 texDesc.fSize = dimensions;
1528 switch (format.textureType()) {
1531 return nullptr;
1532 case GrTextureType::k2D:
1533 texDesc.fTarget = GR_GL_TEXTURE_2D;
1534 break;
1536 if (mipLevelCount > 1 || !this->glCaps().rectangleTextureSupport()) {
1537 return nullptr;
1538 }
1540 break;
1541 }
1546 texDesc.fIsProtected = isProtected;
1547
1548 texDesc.fID = this->createTexture(dimensions, texDesc.fFormat, texDesc.fTarget, renderable,
1549 &initialState, mipLevelCount, texDesc.fIsProtected, label);
1550 if (!texDesc.fID) {
1551 return return_null_texture();
1552 }
1553
1555 if (renderable == GrRenderable::kYes) {
1556 // unbind the texture from the texture unit before binding it to the frame buffer
1557 GL_CALL(BindTexture(texDesc.fTarget, 0));
1558 GrGLRenderTarget::IDs rtIDDesc;
1559
1560 if (!this->createRenderTargetObjects(texDesc, renderTargetSampleCnt, &rtIDDesc)) {
1561 GL_CALL(DeleteTextures(1, &texDesc.fID));
1562 return return_null_texture();
1563 }
1564 tex = sk_make_sp<GrGLTextureRenderTarget>(this,
1565 budgeted,
1566 renderTargetSampleCnt,
1567 texDesc,
1568 rtIDDesc,
1569 mipmapStatus,
1570 label);
1571 tex->baseLevelWasBoundToFBO();
1572 } else {
1573 tex = sk_make_sp<GrGLTexture>(this, budgeted, texDesc, mipmapStatus, label);
1574 }
1575 // The non-sampler params are still at their default values.
1576 tex->parameters()->set(&initialState, GrGLTextureParameters::NonsamplerState(),
1577 fResetTimestampForTextureParameters);
1578 if (levelClearMask) {
1579 if (this->glCaps().clearTextureSupport()) {
1580 GrGLenum externalFormat, externalType;
1583 texDesc.fFormat, &externalFormat, &externalType, &colorType);
1584 for (int i = 0; i < mipLevelCount; ++i) {
1585 if (levelClearMask & (1U << i)) {
1586 GL_CALL(ClearTexImage(tex->textureID(), i, externalFormat, externalType,
1587 nullptr));
1588 }
1589 }
1590 } else if (this->glCaps().canFormatBeFBOColorAttachment(
1592 !this->glCaps().performColorClearsAsDraws()) {
1593 this->flushScissorTest(GrScissorTest::kDisabled);
1594 this->disableWindowRectangles();
1595 this->flushColorWrite(true);
1596 this->flushClearColor({0, 0, 0, 0});
1597 for (int i = 0; i < mipLevelCount; ++i) {
1598 if (levelClearMask & (1U << i)) {
1599 this->bindSurfaceFBOForPixelOps(tex.get(), i, GR_GL_FRAMEBUFFER,
1600 kDst_TempFBOTarget);
1602 this->unbindSurfaceFBOForPixelOps(tex.get(), i, GR_GL_FRAMEBUFFER);
1603 }
1604 }
1605 fHWBoundRenderTargetUniqueID.makeInvalid();
1606 } else {
1607 this->bindTextureToScratchUnit(texDesc.fTarget, tex->textureID());
1608 std::array<float, 4> zeros = {};
1609 this->uploadColorToTex(texDesc.fFormat,
1610 texDesc.fSize,
1611 texDesc.fTarget,
1612 zeros,
1613 levelClearMask);
1614 }
1615 }
1616 return tex;
1617}
static sk_sp< GrTexture > return_null_texture()
Definition GrGLGpu.cpp:1484
GrColorType
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
@ kNone_MSFBOType
Definition GrGLCaps.h:59
void getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format, GrGLenum *externalFormat, GrGLenum *externalType, GrColorType *colorType) const
skgpu::Protected fIsProtected
Definition GrGLTexture.h:28
GrBackendObjectOwnership fOwnership
Definition GrGLTexture.h:27
GrGLFormat fFormat
Definition GrGLTexture.h:26

◆ onGetOpsRenderPass()

GrOpsRenderPass * GrGLGpu::onGetOpsRenderPass ( GrRenderTarget rt,
bool  useMultisampleFBO,
GrAttachment ,
GrSurfaceOrigin  origin,
const SkIRect bounds,
const GrOpsRenderPass::LoadAndStoreInfo colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo stencilInfo,
const skia_private::TArray< GrSurfaceProxy *, true > &  sampledProxies,
GrXferBarrierFlags  renderPassXferBarriers 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 2424 of file GrGLGpu.cpp.

2433 {
2434 if (!fCachedOpsRenderPass) {
2435 fCachedOpsRenderPass = std::make_unique<GrGLOpsRenderPass>(this);
2436 }
2437 if (useMultisampleFBO && rt->numSamples() == 1) {
2438 // We will be using dynamic msaa. Ensure there is an attachment.
2439 auto glRT = static_cast<GrGLRenderTarget*>(rt);
2440 if (!glRT->ensureDynamicMSAAAttachment()) {
2441 SkDebugf("WARNING: Failed to make dmsaa attachment. Render pass will be dropped.");
2442 return nullptr;
2443 }
2444 }
2445 fCachedOpsRenderPass->set(rt, useMultisampleFBO, bounds, origin, colorInfo, stencilInfo);
2446 return fCachedOpsRenderPass.get();
2447}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ onReadPixels()

bool GrGLGpu::onReadPixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  dstColorType,
void *  buffer,
size_t  rowBytes 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 2396 of file GrGLGpu.cpp.

2401 {
2403
2404 size_t bytesPerPixel = GrColorTypeBytesPerPixel(dstColorType);
2405
2406 // GL_PACK_ROW_LENGTH is in terms of pixels not bytes.
2407 int rowPixelWidth;
2408
2409 if (rowBytes == SkToSizeT(rect.width()*bytesPerPixel)) {
2410 rowPixelWidth = rect.width();
2411 } else {
2412 SkASSERT(!(rowBytes % bytesPerPixel));
2413 rowPixelWidth = rowBytes / bytesPerPixel;
2414 }
2415 this->unbindXferBuffer(GrGpuBufferType::kXferGpuToCpu);
2416 return this->readOrTransferPixelsFrom(surface,
2417 rect,
2418 surfaceColorType,
2419 dstColorType,
2420 buffer,
2421 rowPixelWidth);
2422}
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
constexpr size_t SkToSizeT(S x)
Definition SkTo.h:31
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

◆ onRegenerateMipMapLevels()

bool GrGLGpu::onRegenerateMipMapLevels ( GrTexture texture)
overrideprivatevirtual

Implements GrGpu.

Definition at line 3723 of file GrGLGpu.cpp.

3723 {
3724 using RegenerateMipmapType = GrGLCaps::RegenerateMipmapType;
3725
3726 auto glTex = static_cast<GrGLTexture*>(texture);
3727 // Mipmaps are only supported on 2D textures:
3728 if (GR_GL_TEXTURE_2D != glTex->target()) {
3729 return false;
3730 }
3731 GrGLFormat format = glTex->format();
3732 // Manual implementation of mipmap generation, to work around driver bugs w/sRGB.
3733 // Uses draw calls to do a series of downsample operations to successive mips.
3734
3735 // The manual approach requires the ability to limit which level we're sampling and that the
3736 // destination can be bound to a FBO:
3737 if (!this->glCaps().doManualMipmapping() || !this->glCaps().isFormatRenderable(format, 1)) {
3738 GrGLenum target = glTex->target();
3739 this->bindTextureToScratchUnit(target, glTex->textureID());
3740 GL_CALL(GenerateMipmap(glTex->target()));
3741 return true;
3742 }
3743
3744 int width = texture->width();
3745 int height = texture->height();
3746 int levelCount = SkMipmap::ComputeLevelCount(width, height) + 1;
3747 SkASSERT(levelCount == texture->maxMipmapLevel() + 1);
3748
3749 // Create (if necessary), then bind temporary FBO:
3750 if (0 == fTempDstFBOID) {
3751 GL_CALL(GenFramebuffers(1, &fTempDstFBOID));
3752 }
3753 this->bindFramebuffer(GR_GL_FRAMEBUFFER, fTempDstFBOID);
3754 fHWBoundRenderTargetUniqueID.makeInvalid();
3755
3756 // Bind the texture, to get things configured for filtering.
3757 // We'll be changing our base level and max level further below:
3758 this->setTextureUnit(0);
3759 // The mipmap program does not do any swizzling.
3760 this->bindTexture(0, GrSamplerState::Filter::kLinear, skgpu::Swizzle::RGBA(), glTex);
3761
3762 // Vertex data:
3763 if (!fMipmapProgramArrayBuffer) {
3764 static const GrGLfloat vdata[] = {
3765 0, 0,
3766 0, 1,
3767 1, 0,
3768 1, 1
3769 };
3770 fMipmapProgramArrayBuffer = GrGLBuffer::Make(this,
3771 sizeof(vdata),
3774 fMipmapProgramArrayBuffer->updateData(vdata, /*offset=*/0,
3775
3776 sizeof(vdata),
3777 /*preserve=*/false);
3778 }
3779 if (!fMipmapProgramArrayBuffer) {
3780 return false;
3781 }
3782
3783 fHWVertexArrayState.setVertexArrayID(this, 0);
3784
3785 GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
3786 attribs->enableVertexArrays(this, 1);
3787 attribs->set(this, 0, fMipmapProgramArrayBuffer.get(), kFloat2_GrVertexAttribType,
3788 SkSLType::kFloat2, 2 * sizeof(GrGLfloat), 0);
3789
3790 // Set "simple" state once:
3791 this->flushBlendAndColorWrite(skgpu::BlendInfo(), skgpu::Swizzle::RGBA());
3792 this->flushScissorTest(GrScissorTest::kDisabled);
3793 this->disableWindowRectangles();
3794 this->disableStencil();
3795
3796 // Do all the blits:
3797 width = texture->width();
3798 height = texture->height();
3799
3800 std::unique_ptr<GrSemaphore> semaphore;
3801 for (GrGLint level = 1; level < levelCount; ++level) {
3802 // Get and bind the program for this particular downsample (filter shape can vary):
3803 int progIdx = TextureSizeToMipmapProgramIdx(width, height);
3804 if (!fMipmapPrograms[progIdx].fProgram) {
3805 if (!this->createMipmapProgram(progIdx)) {
3806 SkDebugf("Failed to create mipmap program.\n");
3807 // Invalidate all params to cover base and max level change in a previous iteration.
3808 glTex->textureParamsModified();
3809 return false;
3810 }
3811 }
3812 this->flushProgram(fMipmapPrograms[progIdx].fProgram);
3813
3814 if (this->glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusSync &&
3815 level > 1) {
3816 this->waitSemaphore(semaphore.get());
3817 semaphore.reset();
3818 }
3819
3820 // Texcoord uniform is expected to contain (1/w, (w-1)/w, 1/h, (h-1)/h)
3821 const float invWidth = 1.0f / width;
3822 const float invHeight = 1.0f / height;
3823 GL_CALL(Uniform4f(fMipmapPrograms[progIdx].fTexCoordXformUniform,
3824 invWidth, (width - 1) * invWidth, invHeight, (height - 1) * invHeight));
3825 GL_CALL(Uniform1i(fMipmapPrograms[progIdx].fTextureUniform, 0));
3826
3827 // Set the base level so that we only sample from the previous mip.
3828 SkASSERT(this->glCaps().mipmapLevelControlSupport());
3829 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_BASE_LEVEL, level - 1));
3830 // Setting the max level is technically unnecessary and can affect
3831 // validation for the framebuffer. However, by making it clear that a
3832 // rendering feedback loop is not occurring, we avoid hitting a slow
3833 // path on some drivers.
3834 if (this->glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusMaxLevel) {
3835 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAX_LEVEL, level - 1));
3836 }
3837
3839 glTex->textureID(), level));
3840
3841 width = std::max(1, width / 2);
3842 height = std::max(1, height / 2);
3844
3845 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4));
3846
3847 if (this->glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusSync &&
3848 level < levelCount-1) {
3849 semaphore = this->makeSemaphore(true);
3850 this->insertSemaphore(semaphore.get());
3851 }
3852 }
3853
3854 // Unbind:
3856 GR_GL_TEXTURE_2D, 0, 0));
3857
3858 // We modified the base level and max level params.
3859 GrGLTextureParameters::NonsamplerState nonsamplerState = glTex->parameters()->nonsamplerState();
3860 // We drew the 2nd to last level into the last level.
3861 nonsamplerState.fBaseMipMapLevel = levelCount - 2;
3862 if (this->glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusMaxLevel) {
3863 nonsamplerState.fMaxMipmapLevel = levelCount - 2;
3864 }
3865 glTex->parameters()->set(nullptr, nonsamplerState, fResetTimestampForTextureParameters);
3866
3867 return true;
3868}
#define GR_GL_TRIANGLE_STRIP
Definition GrGLDefines.h:35
@ kStatic_GrAccessPattern
@ kFloat2_GrVertexAttribType
void set(GrGLGpu *, int attribIndex, const GrBuffer *vertexBuffer, GrVertexAttribType cpuType, SkSLType gpuType, GrGLsizei stride, size_t offsetInBytes, int divisor=0)
void enableVertexArrays(const GrGLGpu *, int enabledCount, GrPrimitiveRestart=GrPrimitiveRestart::kNo)
bool doManualMipmapping() const
Definition GrGLCaps.h:392
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
RegenerateMipmapType
Definition GrGLCaps.h:133
void bindTexture(int unitIdx, GrSamplerState samplerState, const skgpu::Swizzle &, GrGLTexture *)
Definition GrGLGpu.cpp:2815
void bindFramebuffer(GrGLenum fboTarget, GrGLuint fboid)
Definition GrGLGpu.cpp:3184
void flushViewport(const SkIRect &viewport, int rtHeight, GrSurfaceOrigin)
Definition GrGLGpu.cpp:2015
GrGLint fTextureUniform
Definition GrGLGpu.h:827
GrGLint fTexCoordXformUniform
Definition GrGLGpu.h:828
std::unique_ptr< GrSemaphore > makeSemaphore(bool isOwned) override
Definition GrGLGpu.cpp:4341
void insertSemaphore(GrSemaphore *semaphore) override
Definition GrGLGpu.cpp:4352
void waitSemaphore(GrSemaphore *semaphore) override
Definition GrGLGpu.cpp:4362
GrGLFormat format() const
Definition GrGLTexture.h:50
bool updateData(const void *src, size_t offset, size_t size, bool preserve)
static constexpr Swizzle RGBA()
Definition Swizzle.h:66
int32_t height
int32_t width
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ onResetContext()

void GrGLGpu::onResetContext ( uint32_t  resetBits)
overrideprivatevirtual

Reimplemented from GrGpu.

Definition at line 584 of file GrGLGpu.cpp.

584 {
585 if (resetBits & kMisc_GrGLBackendState) {
586 // we don't use the zb at all
587 GL_CALL(Disable(GR_GL_DEPTH_TEST));
588 GL_CALL(DepthMask(GR_GL_FALSE));
589
590 // We don't use face culling.
591 GL_CALL(Disable(GR_GL_CULL_FACE));
592 // We do use separate stencil. Our algorithms don't care which face is front vs. back so
593 // just set this to the default for self-consistency.
594 GL_CALL(FrontFace(GR_GL_CCW));
595
596 this->hwBufferState(GrGpuBufferType::kXferCpuToGpu)->invalidate();
597 this->hwBufferState(GrGpuBufferType::kXferGpuToCpu)->invalidate();
598
599 if (GR_IS_GR_GL(this->glStandard())) {
600#ifndef USE_NSIGHT
601 // Desktop-only state that we never change
602 if (!this->glCaps().isCoreProfile()) {
603 GL_CALL(Disable(GR_GL_POINT_SMOOTH));
604 GL_CALL(Disable(GR_GL_LINE_SMOOTH));
609 }
610 // The windows NVIDIA driver has GL_ARB_imaging in the extension string when using a
611 // core profile. This seems like a bug since the core spec removes any mention of
612 // GL_ARB_imaging.
613 if (this->glCaps().imagingSupport() && !this->glCaps().isCoreProfile()) {
614 GL_CALL(Disable(GR_GL_COLOR_TABLE));
615 }
617
618 fHWWireframeEnabled = kUnknown_TriState;
619#endif
620 // Since ES doesn't support glPointSize at all we always use the VS to
621 // set the point size
623
624 }
625
626 if (GR_IS_GR_GL_ES(this->glStandard()) &&
627 this->glCaps().fbFetchRequiresEnablePerSample()) {
628 // The arm extension requires specifically enabling MSAA fetching per sample.
629 // On some devices this may have a perf hit. Also multiple render targets are disabled
631 }
632 fHWWriteToColor = kUnknown_TriState;
633 // we only ever use lines in hairline mode
634 GL_CALL(LineWidth(1));
635 GL_CALL(Disable(GR_GL_DITHER));
636
637 fHWClearColor[0] = fHWClearColor[1] = fHWClearColor[2] = fHWClearColor[3] = SK_FloatNaN;
638 }
639
640 if (resetBits & kMSAAEnable_GrGLBackendState) {
641 if (this->glCaps().clientCanDisableMultisample()) {
642 // Restore GL_MULTISAMPLE to its initial state. It being enabled has no effect on draws
643 // to non-MSAA targets.
644 GL_CALL(Enable(GR_GL_MULTISAMPLE));
645 }
646 fHWConservativeRasterEnabled = kUnknown_TriState;
647 }
648
649 fHWActiveTextureUnitIdx = -1; // invalid
650 fLastPrimitiveType = static_cast<GrPrimitiveType>(-1);
651
652 if (resetBits & kTextureBinding_GrGLBackendState) {
653 for (int s = 0; s < this->numTextureUnits(); ++s) {
654 fHWTextureUnitBindings[s].invalidateAllTargets(false);
655 }
656 if (fSamplerObjectCache) {
657 fSamplerObjectCache->invalidateBindings();
658 }
659 }
660
661 if (resetBits & kBlend_GrGLBackendState) {
662 fHWBlendState.invalidate();
663 }
664
665 if (resetBits & kView_GrGLBackendState) {
666 fHWScissorSettings.invalidate();
667 fHWWindowRectsState.invalidate();
668 fHWViewport.invalidate();
669 }
670
671 if (resetBits & kStencil_GrGLBackendState) {
672 fHWStencilSettings.invalidate();
673 fHWStencilTestEnabled = kUnknown_TriState;
674 }
675
676 // Vertex
677 if (resetBits & kVertex_GrGLBackendState) {
678 fHWVertexArrayState.invalidate();
679 this->hwBufferState(GrGpuBufferType::kVertex)->invalidate();
680 this->hwBufferState(GrGpuBufferType::kIndex)->invalidate();
681 this->hwBufferState(GrGpuBufferType::kDrawIndirect)->invalidate();
682 }
683
684 if (resetBits & kRenderTarget_GrGLBackendState) {
685 fHWBoundRenderTargetUniqueID.makeInvalid();
686 fHWSRGBFramebuffer = kUnknown_TriState;
687 fBoundDrawFramebuffer = 0;
688 }
689
690 // we assume these values
691 if (resetBits & kPixelStore_GrGLBackendState) {
692 if (this->caps()->writePixelsRowBytesSupport() ||
693 this->caps()->transferPixelsToRowBytesSupport()) {
694 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
695 }
696 if (this->glCaps().readPixelsRowBytesSupport()) {
697 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0));
698 }
699 if (this->glCaps().packFlipYSupport()) {
701 }
702 }
703
704 if (resetBits & kProgram_GrGLBackendState) {
705 fHWProgramID = 0;
706 fHWProgram.reset();
707 }
708 ++fResetTimestampForTextureParameters;
709}
#define GR_GL_CCW
#define GR_GL_COLOR_TABLE
#define GR_GL_CULL_FACE
#define GR_GL_UNPACK_ROW_LENGTH
#define GR_GL_POINT_SMOOTH
#define GR_GL_POLYGON_STIPPLE
#define GR_GL_POLYGON_SMOOTH
#define GR_GL_MULTISAMPLE
#define GR_GL_COLOR_LOGIC_OP
#define GR_GL_FALSE
Definition GrGLDefines.h:26
#define GR_GL_LINE_SMOOTH
#define GR_GL_INDEX_LOGIC_OP
#define GR_GL_POLYGON_OFFSET_FILL
#define GR_GL_PACK_ROW_LENGTH
#define GR_GL_DITHER
#define GR_GL_VERTEX_PROGRAM_POINT_SIZE
#define GR_GL_FETCH_PER_SAMPLE
#define GR_GL_DEPTH_TEST
#define GR_GL_PACK_REVERSE_ROW_ORDER
GrPrimitiveType
Definition GrTypesPriv.h:42
@ kProgram_GrGLBackendState
Definition GrTypes.h:167
@ kView_GrGLBackendState
Definition GrTypes.h:161
@ kTextureBinding_GrGLBackendState
Definition GrTypes.h:159
@ kVertex_GrGLBackendState
Definition GrTypes.h:164
@ kBlend_GrGLBackendState
Definition GrTypes.h:162
@ kMisc_GrGLBackendState
Definition GrTypes.h:169
@ kMSAAEnable_GrGLBackendState
Definition GrTypes.h:163
@ kPixelStore_GrGLBackendState
Definition GrTypes.h:166
@ kStencil_GrGLBackendState
Definition GrTypes.h:165
@ kRenderTarget_GrGLBackendState
Definition GrTypes.h:157
constexpr float SK_FloatNaN
struct MyStruct s
void invalidate()

◆ onResetTextureBindings()

void GrGLGpu::onResetTextureBindings ( )
overrideprivatevirtual

Reimplemented from GrGpu.

Definition at line 2984 of file GrGLGpu.cpp.

2984 {
2985 static constexpr GrGLenum kTargets[] = {GR_GL_TEXTURE_2D, GR_GL_TEXTURE_RECTANGLE,
2987 for (int i = 0; i < this->numTextureUnits(); ++i) {
2988 this->setTextureUnit(i);
2989 for (auto target : kTargets) {
2990 if (fHWTextureUnitBindings[i].hasBeenModified(target)) {
2991 GL_CALL(BindTexture(target, 0));
2992 }
2993 }
2994 fHWTextureUnitBindings[i].invalidateAllTargets(true);
2995 }
2996}
#define GR_GL_TEXTURE_EXTERNAL

◆ onResolveRenderTarget()

void GrGLGpu::onResolveRenderTarget ( GrRenderTarget target,
const SkIRect resolveRect 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 2541 of file GrGLGpu.cpp.

2541 {
2542 auto glRT = static_cast<GrGLRenderTarget*>(target);
2544 this->resolveRenderFBOs(glRT, SkIRect::MakeSize(glRT->dimensions()),
2545 ResolveDirection::kMSAAToSingle);
2546 } else {
2547 this->resolveRenderFBOs(glRT, resolveRect, ResolveDirection::kMSAAToSingle);
2548 }
2549}
bool framebufferResolvesMustBeFullSize() const
Definition GrGLCaps.h:299
void resolveRenderFBOs(GrGLRenderTarget *, const SkIRect &resolveRect, ResolveDirection, bool invalidateReadBufferAfterBlit=false)
Definition GrGLGpu.cpp:2551
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66

◆ onSubmitToGpu()

bool GrGLGpu::onSubmitToGpu ( GrSyncCpu  sync)
overrideprivatevirtual

Implements GrGpu.

Definition at line 4256 of file GrGLGpu.cpp.

4256 {
4257 if (sync == GrSyncCpu::kYes ||
4258 (!fFinishCallbacks.empty() && !this->glCaps().fenceSyncSupport())) {
4260 fFinishCallbacks.callAll(true);
4261 } else {
4262 this->flush();
4263 // See if any previously inserted finish procs are good to go.
4264 fFinishCallbacks.check();
4265 }
4266 if (!this->glCaps().skipErrorChecks()) {
4268 }
4269 return true;
4270}
void clearErrorsAndCheckForOOM()
Definition GrGLGpu.cpp:4377
void finishOutstandingGpuWork() override
Definition GrGLGpu.cpp:4373

◆ onTransferFromBufferToBuffer()

bool GrGLGpu::onTransferFromBufferToBuffer ( sk_sp< GrGpuBuffer src,
size_t  srcOffset,
sk_sp< GrGpuBuffer dst,
size_t  dstOffset,
size_t  size 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 988 of file GrGLGpu.cpp.

992 {
993 SkASSERT(!src->isMapped());
994 SkASSERT(!dst->isMapped());
995
996 auto glSrc = static_cast<const GrGLBuffer*>(src.get());
997 auto glDst = static_cast<const GrGLBuffer*>(dst.get());
998
999 // If we refactored bindBuffer() to use something other than GrGpuBufferType to indicate the
1000 // binding target then we could use the COPY_READ and COPY_WRITE targets here. But
1001 // CopyBufferSubData is documented to work with all the targets so it's not clear it's worth it.
1004
1005 GL_CALL(CopyBufferSubData(GR_GL_PIXEL_UNPACK_BUFFER,
1007 srcOffset,
1008 dstOffset,
1009 size));
1010 return true;
1011}
#define GR_GL_PIXEL_PACK_BUFFER
#define GR_GL_PIXEL_UNPACK_BUFFER
GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer *)
Definition GrGLGpu.cpp:2143

◆ onTransferPixelsFrom()

bool GrGLGpu::onTransferPixelsFrom ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1082 of file GrGLGpu.cpp.

1087 {
1088 auto* glBuffer = static_cast<GrGLBuffer*>(transferBuffer.get());
1089 SkASSERT(glBuffer->size() >= offset + (rect.width() *
1090 rect.height()*
1091 GrColorTypeBytesPerPixel(dstColorType)));
1092
1094
1095 auto offsetAsPtr = reinterpret_cast<void*>(offset);
1096 return this->readOrTransferPixelsFrom(surface,
1097 rect,
1098 surfaceColorType,
1099 dstColorType,
1100 offsetAsPtr,
1101 rect.width());
1102}
Point offset

◆ onTransferPixelsTo()

bool GrGLGpu::onTransferPixelsTo ( GrTexture texture,
SkIRect  rect,
GrColorType  textureColorType,
GrColorType  bufferColorType,
sk_sp< GrGpuBuffer transferBuffer,
size_t  offset,
size_t  rowBytes 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1013 of file GrGLGpu.cpp.

1019 {
1020 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture);
1021
1022 // Can't transfer compressed data
1024
1025 if (!check_write_and_transfer_input(glTex)) {
1026 return false;
1027 }
1028
1029 static_assert(sizeof(int) == sizeof(int32_t), "");
1030
1031 this->bindTextureToScratchUnit(glTex->target(), glTex->textureID());
1032
1033 SkASSERT(!transferBuffer->isMapped());
1034 SkASSERT(!transferBuffer->isCpuBuffer());
1035 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer.get());
1037
1038 SkASSERT(SkIRect::MakeSize(texture->dimensions()).contains(rect));
1039
1040 size_t bpp = GrColorTypeBytesPerPixel(bufferColorType);
1041 const size_t trimRowBytes = rect.width() * bpp;
1042 const void* pixels = (void*)offset;
1043
1044 SkASSERT(glBuffer->size() >= offset + rowBytes*(rect.height() - 1) + trimRowBytes);
1045
1046 bool restoreGLRowLength = false;
1047 if (trimRowBytes != rowBytes) {
1048 // we should have checked for this support already
1049 SkASSERT(this->glCaps().transferPixelsToRowBytesSupport());
1050 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowBytes / bpp));
1051 restoreGLRowLength = true;
1052 }
1053
1054 GrGLFormat textureFormat = glTex->format();
1055 // External format and type come from the upload data.
1056 GrGLenum externalFormat = 0;
1057 GrGLenum externalType = 0;
1059 textureFormat, textureColorType, bufferColorType, &externalFormat, &externalType);
1060 if (!externalFormat || !externalType) {
1061 return false;
1062 }
1063
1064 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1));
1065 GL_CALL(TexSubImage2D(glTex->target(),
1066 0,
1067 rect.left(),
1068 rect.top(),
1069 rect.width(),
1070 rect.height(),
1071 externalFormat,
1072 externalType,
1073 pixels));
1074
1075 if (restoreGLRowLength) {
1076 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
1077 }
1078
1079 return true;
1080}
#define GR_GL_UNPACK_ALIGNMENT
static bool check_write_and_transfer_input(GrGLTexture *glTex)
Definition GrGLGpu.cpp:928
Type::kYUV Type::kRGBA() int(0.7 *637)
void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum *externalFormat, GrGLenum *externalType) const
GrGLenum target() const
GrGLuint textureID() const
Definition GrGLTexture.h:46
size_t size() const final
Definition GrGpuBuffer.h:34
bool isMapped() const
bool isCpuBuffer() const final
Definition GrGpuBuffer.h:71
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463

◆ onUpdateCompressedBackendTexture()

bool GrGLGpu::onUpdateCompressedBackendTexture ( const GrBackendTexture backendTexture,
sk_sp< skgpu::RefCntedCallback finishedCallback,
const void *  data,
size_t  length 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 1708 of file GrGLGpu.cpp.

1711 {
1714
1715 GrBackendFormat format = backendTexture.getBackendFormat();
1717 if (glFormat == GrGLFormat::kUnknown) {
1718 return false;
1719 }
1721
1722 skgpu::Mipmapped mipmapped =
1723 backendTexture.hasMipmaps() ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
1724
1725 this->bindTextureToScratchUnit(info.fTarget, info.fID);
1726
1727 // If we have mips make sure the base level is set to 0 and the max level set to numMipLevels-1
1728 // so that the uploads go to the right levels.
1729 if (backendTexture.hasMipmaps() && this->glCaps().mipmapLevelControlSupport()) {
1730 auto params = get_gl_texture_params(backendTexture);
1731 GrGLTextureParameters::NonsamplerState nonsamplerState = params->nonsamplerState();
1732 if (params->nonsamplerState().fBaseMipMapLevel != 0) {
1733 GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_BASE_LEVEL, 0));
1734 nonsamplerState.fBaseMipMapLevel = 0;
1735 }
1736 int numMipLevels =
1737 SkMipmap::ComputeLevelCount(backendTexture.width(), backendTexture.height()) + 1;
1738 if (params->nonsamplerState().fMaxMipmapLevel != (numMipLevels - 1)) {
1739 GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_MAX_LEVEL, numMipLevels - 1));
1740 nonsamplerState.fBaseMipMapLevel = numMipLevels - 1;
1741 }
1742 params->set(nullptr, nonsamplerState, fResetTimestampForTextureParameters);
1743 }
1744
1745 bool result = this->uploadCompressedTexData(compression,
1746 glFormat,
1747 backendTexture.dimensions(),
1748 mipmapped,
1750 data,
1751 length);
1752
1753 // Unbind this texture from the scratch texture unit.
1754 this->bindTextureToScratchUnit(info.fTarget, 0);
1755
1756 return result;
1757}
GrBackendFormat getBackendFormat() const
size_t length
Mipmapped
Definition GpuTypes.h:53

◆ onWrapBackendRenderTarget()

sk_sp< GrRenderTarget > GrGLGpu::onWrapBackendRenderTarget ( const GrBackendRenderTarget backendRT)
overrideprivatevirtual

Implements GrGpu.

Definition at line 889 of file GrGLGpu.cpp.

889 {
892 return nullptr;
893 }
894
895 if (backendRT.isProtected() && !this->glCaps().supportsProtectedContent()) {
896 return nullptr;
897 }
898
899 const auto format = GrBackendFormats::AsGLFormat(backendRT.getBackendFormat());
900 if (!this->glCaps().isFormatRenderable(format, backendRT.sampleCnt())) {
901 return nullptr;
902 }
903
904 int sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format);
905
907 if (sampleCount <= 1) {
908 rtIDs.fSingleSampleFBOID = info.fFBOID;
910 } else {
912 rtIDs.fMultisampleFBOID = info.fFBOID;
913 }
914 rtIDs.fMSColorRenderbufferID = 0;
916 rtIDs.fTotalMemorySamplesPerPixel = sampleCount;
917
919 backendRT.dimensions(),
920 format,
921 sampleCount,
922 rtIDs,
923 backendRT.stencilBits(),
924 skgpu::Protected(backendRT.isProtected()),
925 /*label=*/"GLGpu_WrapBackendRenderTarget");
926}
GrBackendFormat getBackendFormat() const
SkISize dimensions() const
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &format) const override
Definition GrGLCaps.h:158
static sk_sp< GrGLRenderTarget > MakeWrapped(GrGLGpu *, const SkISize &, GrGLFormat, int sampleCount, const IDs &, int stencilBits, skgpu::Protected, std::string_view label)
SK_API bool GetGLFramebufferInfo(const GrBackendRenderTarget &, GrGLFramebufferInfo *)
Protected
Definition GpuTypes.h:61
GrBackendObjectOwnership fRTFBOOwnership

◆ onWrapBackendTexture()

sk_sp< GrTexture > GrGLGpu::onWrapBackendTexture ( const GrBackendTexture backendTex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable,
GrIOType  ioType 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 754 of file GrGLGpu.cpp.

757 {
759 if (!check_backend_texture(backendTex, this->glCaps(), &desc)) {
760 return nullptr;
761 }
762
763 if (kBorrow_GrWrapOwnership == ownership) {
765 } else {
767 }
768
769 GrMipmapStatus mipmapStatus = backendTex.hasMipmaps() ? GrMipmapStatus::kValid
771
773 mipmapStatus,
774 desc,
775 get_gl_texture_params(backendTex),
776 cacheable,
777 ioType,
778 backendTex.getLabel());
779 if (this->glCaps().isFormatRenderable(backendTex.getBackendFormat(), 1)) {
780 // Pessimistically assume this external texture may have been bound to a FBO.
781 texture->baseLevelWasBoundToFBO();
782 }
783 return texture;
784}
static bool check_backend_texture(const GrBackendTexture &backendTex, const GrGLCaps &caps, GrGLTexture::Desc *desc, bool skipRectTexSupportCheck=false)
Definition GrGLGpu.cpp:711
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
std::string_view getLabel() const
static sk_sp< GrGLTexture > MakeWrapped(GrGLGpu *, GrMipmapStatus, const Desc &, sk_sp< GrGLTextureParameters >, GrWrapCacheable, GrIOType, std::string_view label)

◆ onWrapCompressedBackendTexture()

sk_sp< GrTexture > GrGLGpu::onWrapCompressedBackendTexture ( const GrBackendTexture backendTex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 814 of file GrGLGpu.cpp.

816 {
818 if (!check_compressed_backend_texture(backendTex, this->glCaps(), &desc)) {
819 return nullptr;
820 }
821
822 if (kBorrow_GrWrapOwnership == ownership) {
824 } else {
826 }
827
828 GrMipmapStatus mipmapStatus = backendTex.hasMipmaps() ? GrMipmapStatus::kValid
830
831 return GrGLTexture::MakeWrapped(this,
832 mipmapStatus,
833 desc,
834 get_gl_texture_params(backendTex),
835 cacheable,
837 backendTex.getLabel());
838}
static bool check_compressed_backend_texture(const GrBackendTexture &backendTex, const GrGLCaps &caps, GrGLTexture::Desc *desc, bool skipRectTexSupportCheck=false)
Definition GrGLGpu.cpp:786
@ kRead_GrIOType

◆ onWrapRenderableBackendTexture()

sk_sp< GrTexture > GrGLGpu::onWrapRenderableBackendTexture ( const GrBackendTexture backendTex,
int  sampleCnt,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 840 of file GrGLGpu.cpp.

843 {
844 const GrGLCaps& caps = this->glCaps();
845
847 if (!check_backend_texture(backendTex, this->glCaps(), &desc)) {
848 return nullptr;
849 }
850 SkASSERT(caps.isFormatRenderable(desc.fFormat, sampleCnt));
852
853 // We don't support rendering to a EXTERNAL texture.
854 if (GR_GL_TEXTURE_EXTERNAL == desc.fTarget) {
855 return nullptr;
856 }
857
858 if (kBorrow_GrWrapOwnership == ownership) {
860 } else {
862 }
863
864
865 sampleCnt = caps.getRenderTargetSampleCount(sampleCnt, desc.fFormat);
866 SkASSERT(sampleCnt);
867
869 if (!this->createRenderTargetObjects(desc, sampleCnt, &rtIDs)) {
870 return nullptr;
871 }
872
873 GrMipmapStatus mipmapStatus = backendTex.hasMipmaps() ? GrMipmapStatus::kDirty
875
878 sampleCnt,
879 desc,
880 get_gl_texture_params(backendTex),
881 rtIDs,
882 cacheable,
883 mipmapStatus,
884 backendTex.getLabel()));
885 texRT->baseLevelWasBoundToFBO();
886 return texRT;
887}
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
virtual bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const =0
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
static sk_sp< GrGLTextureRenderTarget > MakeWrapped(GrGLGpu *gpu, int sampleCount, const GrGLTexture::Desc &, sk_sp< GrGLTextureParameters >, const GrGLRenderTarget::IDs &, GrWrapCacheable, GrMipmapStatus, std::string_view label)

◆ onWritePixels()

bool GrGLGpu::onWritePixels ( GrSurface surface,
SkIRect  rect,
GrColorType  surfaceColorType,
GrColorType  srcColorType,
const GrMipLevel  texels[],
int  mipLevelCount,
bool  prepForTexSampling 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 941 of file GrGLGpu.cpp.

947 {
948 auto glTex = static_cast<GrGLTexture*>(surface->asTexture());
949
950 if (!check_write_and_transfer_input(glTex)) {
951 return false;
952 }
953
954 this->bindTextureToScratchUnit(glTex->target(), glTex->textureID());
955
956 // If we have mips make sure the base/max levels cover the full range so that the uploads go to
957 // the right levels. We've found some Radeons require this.
958 if (mipLevelCount && this->glCaps().mipmapLevelControlSupport()) {
959 auto params = glTex->parameters();
960 GrGLTextureParameters::NonsamplerState nonsamplerState = params->nonsamplerState();
961 int maxLevel = glTex->maxMipmapLevel();
962 if (params->nonsamplerState().fBaseMipMapLevel != 0) {
963 GL_CALL(TexParameteri(glTex->target(), GR_GL_TEXTURE_BASE_LEVEL, 0));
964 nonsamplerState.fBaseMipMapLevel = 0;
965 }
966 if (params->nonsamplerState().fMaxMipmapLevel != maxLevel) {
967 GL_CALL(TexParameteri(glTex->target(), GR_GL_TEXTURE_MAX_LEVEL, maxLevel));
968 nonsamplerState.fBaseMipMapLevel = maxLevel;
969 }
970 params->set(nullptr, nonsamplerState, fResetTimestampForTextureParameters);
971 }
972
973 if (this->glCaps().flushBeforeWritePixels()) {
974 GL_CALL(Flush());
975 }
976
977 SkASSERT(!GrGLFormatIsCompressed(glTex->format()));
978 return this->uploadColorTypeTexData(glTex->format(),
979 surfaceColorType,
980 glTex->dimensions(),
981 glTex->target(),
982 rect,
983 srcColorType,
984 texels,
985 mipLevelCount);
986}
void Flush(SkSurface *surface)
Definition GpuTools.h:25

◆ pipelineBuilder()

GrThreadSafePipelineBuilder * GrGLGpu::pipelineBuilder ( )
overridevirtual

Implements GrGpu.

Definition at line 574 of file GrGLGpu.cpp.

574 {
575 return fProgramCache.get();
576}

◆ precompileShader()

bool GrGLGpu::precompileShader ( const SkData key,
const SkData data 
)
inlineoverridevirtual

Reimplemented from GrGpu.

Definition at line 222 of file GrGLGpu.h.

222 {
223 return fProgramCache->precompileShader(this->getContext(), key, data);
224 }

◆ prepareTextureForCrossContextUsage()

std::unique_ptr< GrSemaphore > GrGLGpu::prepareTextureForCrossContextUsage ( GrTexture )
overridevirtual

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.

Implements GrGpu.

Definition at line 4403 of file GrGLGpu.cpp.

4403 {
4404 // Set up a semaphore to be signaled once the data is ready, and flush GL
4405 std::unique_ptr<GrSemaphore> semaphore = this->makeSemaphore(true);
4406 SkASSERT(semaphore);
4407 this->insertSemaphore(semaphore.get());
4408 // We must call flush here to make sure the GrGLsync object gets created and sent to the gpu.
4409 this->flush(FlushType::kForce);
4410
4411 return semaphore;
4412}

◆ prepareToDraw()

GrGLenum GrGLGpu::prepareToDraw ( GrPrimitiveType  primitiveType)

Definition at line 2516 of file GrGLGpu.cpp.

2516 {
2518
2519 if (this->glCaps().requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() &&
2520 GrIsPrimTypeLines(primitiveType) && !GrIsPrimTypeLines(fLastPrimitiveType)) {
2521 GL_CALL(Enable(GR_GL_CULL_FACE));
2522 GL_CALL(Disable(GR_GL_CULL_FACE));
2523 }
2524 fLastPrimitiveType = primitiveType;
2525
2526 switch (primitiveType) {
2528 return GR_GL_TRIANGLES;
2530 return GR_GL_TRIANGLE_STRIP;
2532 return GR_GL_POINTS;
2534 return GR_GL_LINES;
2536 return GR_GL_LINE_STRIP;
2537 }
2538 SK_ABORT("invalid GrPrimitiveType");
2539}
#define GR_GL_POINTS
Definition GrGLDefines.h:30
#define GR_GL_LINES
Definition GrGLDefines.h:31
#define GR_GL_TRIANGLES
Definition GrGLDefines.h:34
#define GR_GL_LINE_STRIP
Definition GrGLDefines.h:33
static constexpr bool GrIsPrimTypeLines(GrPrimitiveType type)
Definition GrTypesPriv.h:51
#define SK_ABORT(message,...)
Definition SkAssert.h:70
void incNumDraws()
Definition GrGpu.h:541

◆ refPipelineBuilder()

sk_sp< GrThreadSafePipelineBuilder > GrGLGpu::refPipelineBuilder ( )
overridevirtual

Implements GrGpu.

Definition at line 578 of file GrGLGpu.cpp.

578 {
579 return fProgramCache;
580}

◆ resolveRenderFBOs()

void GrGLGpu::resolveRenderFBOs ( GrGLRenderTarget rt,
const SkIRect resolveRect,
ResolveDirection  resolveDirection,
bool  invalidateReadBufferAfterBlit = false 
)

Definition at line 2551 of file GrGLGpu.cpp.

2553 {
2554 this->handleDirtyContext();
2555 rt->bindForResolve(resolveDirection);
2556
2557 const GrGLCaps& caps = this->glCaps();
2558
2559 // make sure we go through flushRenderTarget() since we've modified
2560 // the bound DRAW FBO ID.
2561 fHWBoundRenderTargetUniqueID.makeInvalid();
2562 if (GrGLCaps::kES_Apple_MSFBOType == caps.msFBOType()) {
2563 // The Apple extension doesn't support blitting from single to multisample.
2564 SkASSERT(resolveDirection != ResolveDirection::kSingleToMSAA);
2565 SkASSERT(resolveRect == SkIRect::MakeSize(rt->dimensions()));
2566 // Apple's extension uses the scissor as the blit bounds.
2567 // Passing in kTopLeft_GrSurfaceOrigin will make sure no transformation of the rect
2568 // happens inside flushScissor since resolveRect is already in native device coordinates.
2569 GrScissorState scissor(rt->dimensions());
2570 SkAssertResult(scissor.set(resolveRect));
2571 this->flushScissor(scissor, rt->height(), kTopLeft_GrSurfaceOrigin);
2572 this->disableWindowRectangles();
2573 GL_CALL(ResolveMultisampleFramebuffer());
2574 } else {
2575 SkASSERT(!caps.framebufferResolvesMustBeFullSize() ||
2576 resolveRect == SkIRect::MakeSize(rt->dimensions()));
2577 int l = resolveRect.x();
2578 int b = resolveRect.y();
2579 int r = resolveRect.x() + resolveRect.width();
2580 int t = resolveRect.y() + resolveRect.height();
2581
2582 // BlitFrameBuffer respects the scissor, so disable it.
2583 this->flushScissorTest(GrScissorTest::kDisabled);
2584 this->disableWindowRectangles();
2585 GL_CALL(BlitFramebuffer(l, b, r, t, l, b, r, t, GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST));
2586 }
2587
2588 if (caps.invalidateFBType() != GrGLCaps::kNone_InvalidateFBType &&
2589 invalidateReadBufferAfterBlit) {
2590 // Invalidate the read FBO attachment after the blit, in hopes that this allows the driver
2591 // to perform tiling optimizations.
2592 bool readBufferIsMSAA = resolveDirection == ResolveDirection::kMSAAToSingle;
2593 GrGLenum colorDiscardAttachment = rt->isFBO0(readBufferIsMSAA) ? GR_GL_COLOR
2595 if (caps.invalidateFBType() == GrGLCaps::kInvalidate_InvalidateFBType) {
2596 GL_CALL(InvalidateFramebuffer(GR_GL_READ_FRAMEBUFFER, 1, &colorDiscardAttachment));
2597 } else {
2598 SkASSERT(caps.invalidateFBType() == GrGLCaps::kDiscard_InvalidateFBType);
2599 // glDiscardFramebuffer only accepts GL_FRAMEBUFFER.
2600 rt->bind(readBufferIsMSAA);
2601 GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, 1, &colorDiscardAttachment));
2602 }
2603 }
2604}
#define GR_GL_READ_FRAMEBUFFER
#define GR_GL_NEAREST
@ kES_Apple_MSFBOType
Definition GrGLCaps.h:69
void bindForResolve(ResolveDirection)
void bind(bool useMultisampleFBO)
SkISize dimensions() const
Definition GrSurface.h:27
static bool b
constexpr int32_t x() const
Definition SkRect.h:141
constexpr int32_t y() const
Definition SkRect.h:148
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158

◆ stagingBufferManager()

GrStagingBufferManager * GrGLGpu::stagingBufferManager ( )
inlineoverridevirtual

Reimplemented from GrGpu.

Definition at line 110 of file GrGLGpu.h.

110{ return fStagingBufferManager.get(); }

◆ submit()

void GrGLGpu::submit ( GrOpsRenderPass renderPass)
overridevirtual

Implements GrGpu.

Definition at line 4280 of file GrGLGpu.cpp.

4280 {
4281 // The GrGLOpsRenderPass doesn't buffer ops so there is nothing to do here
4282 SkASSERT(fCachedOpsRenderPass.get() == renderPass);
4283 fCachedOpsRenderPass->reset();
4284}

◆ waitFence()

bool GrGLGpu::waitFence ( GrGLsync  fence)

Definition at line 4328 of file GrGLGpu.cpp.

4328 {
4329 if (!this->glCaps().fenceSyncSupport()) {
4330 return true;
4331 }
4332 return this->waitSync(fence, 0, false);
4333}

◆ waitSemaphore()

void GrGLGpu::waitSemaphore ( GrSemaphore semaphore)
overridevirtual

Implements GrGpu.

Definition at line 4362 of file GrGLGpu.cpp.

4362 {
4363 SkASSERT(semaphore);
4364 GrGLSemaphore* glSem = static_cast<GrGLSemaphore*>(semaphore);
4365
4366 GL_CALL(WaitSync(glSem->sync(), 0, GR_GL_TIMEOUT_IGNORED));
4367}
#define GR_GL_TIMEOUT_IGNORED
GrGLsync sync() const

◆ willExecute()

void GrGLGpu::willExecute ( )
overridevirtual

Reimplemented from GrGpu.

Definition at line 4272 of file GrGLGpu.cpp.

4272 {
4273 // Because our transfers will be submitted to GL to perfom immediately (no command buffer to
4274 // submit), we must unmap any staging buffers.
4275 if (fStagingBufferManager) {
4276 fStagingBufferManager->detachBuffers();
4277 }
4278}

◆ wrapBackendSemaphore()

std::unique_ptr< GrSemaphore > GrGLGpu::wrapBackendSemaphore ( const GrBackendSemaphore ,
GrSemaphoreWrapType  ,
GrWrapOwnership   
)
overridevirtual

Implements GrGpu.

Definition at line 4346 of file GrGLGpu.cpp.

4348 {
4349 SK_ABORT("Unsupported");
4350}

◆ xferBarrier()

void GrGLGpu::xferBarrier ( GrRenderTarget rt,
GrXferBarrierType  type 
)
overrideprivatevirtual

Implements GrGpu.

Definition at line 3870 of file GrGLGpu.cpp.

3870 {
3871 SkASSERT(type);
3872 switch (type) {
3874 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt);
3875 SkASSERT(glrt->asTexture());
3876 SkASSERT(!glrt->isFBO0(false/*multisample*/));
3877 if (glrt->requiresManualMSAAResolve()) {
3878 // The render target uses separate storage so no need for glTextureBarrier.
3879 // FIXME: The render target will resolve automatically when its texture is bound,
3880 // but we could resolve only the bounds that will be read if we do it here instead.
3881 return;
3882 }
3883 SkASSERT(this->caps()->textureBarrierSupport());
3884 GL_CALL(TextureBarrier());
3885 return;
3886 }
3889 this->caps()->blendEquationSupport());
3890 GL_CALL(BlendBarrier());
3891 return;
3892 default: break; // placate compiler warnings that kNone not handled
3893 }
3894}
@ kTexture_GrXferBarrierType
@ kBlend_GrXferBarrierType
@ kAdvanced_BlendEquationSupport
Definition GrCaps.h:152
bool requiresManualMSAAResolve() const
Definition GrSurface.h:126
virtual GrTexture * asTexture()
Definition GrSurface.h:59

Member Data Documentation

◆ fBoundBufferUniqueID

GrGpuResource::UniqueID GrGLGpu::fBoundBufferUniqueID

Definition at line 743 of file GrGLGpu.h.

◆ fBufferZeroKnownBound

bool GrGLGpu::fBufferZeroKnownBound

Definition at line 744 of file GrGLGpu.h.

◆ fConstColor

SkPMColor4f GrGLGpu::fConstColor

Definition at line 773 of file GrGLGpu.h.

◆ fConstColorValid

bool GrGLGpu::fConstColorValid

Definition at line 774 of file GrGLGpu.h.

◆ fDstCoeff

skgpu::BlendCoeff GrGLGpu::fDstCoeff

Definition at line 772 of file GrGLGpu.h.

◆ fEnabled

TriState GrGLGpu::fEnabled

Definition at line 631 of file GrGLGpu.h.

◆ fEquation

skgpu::BlendEquation GrGLGpu::fEquation

Definition at line 770 of file GrGLGpu.h.

◆ fGLTarget

GrGLenum GrGLGpu::fGLTarget

Definition at line 742 of file GrGLGpu.h.

◆ fPosXformUniform

GrGLint GrGLGpu::fPosXformUniform = 0

Definition at line 829 of file GrGLGpu.h.

◆ fProgram

GrGLuint GrGLGpu::fProgram = 0

Definition at line 826 of file GrGLGpu.h.

◆ fRect

GrNativeRect GrGLGpu::fRect

Definition at line 632 of file GrGLGpu.h.

◆ fSrcCoeff

skgpu::BlendCoeff GrGLGpu::fSrcCoeff

Definition at line 771 of file GrGLGpu.h.

◆ fTexCoordXformUniform

GrGLint GrGLGpu::fTexCoordXformUniform = 0

Definition at line 828 of file GrGLGpu.h.

◆ fTextureUniform

GrGLint GrGLGpu::fTextureUniform = 0

Definition at line 827 of file GrGLGpu.h.


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