#include "src/gpu/ganesh/gl/GrGLGpu.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkRect.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/ganesh/GrBackendSurface.h"
#include "include/gpu/ganesh/GrContextOptions.h"
#include "include/gpu/ganesh/GrDirectContext.h"
#include "include/gpu/ganesh/GrDriverBugWorkarounds.h"
#include "include/gpu/ganesh/GrTypes.h"
#include "include/gpu/ganesh/gl/GrGLConfig.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkPoint_impl.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkScopeExit.h"
#include "src/core/SkCompressedDataUtils.h"
#include "src/core/SkLRUCache.h"
#include "src/core/SkMipmap.h"
#include "src/core/SkSLTypeShared.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/SkRenderEngineAbortf.h"
#include "src/gpu/Swizzle.h"
#include "src/gpu/ganesh/GrAttachment.h"
#include "src/gpu/ganesh/GrBackendSurfacePriv.h"
#include "src/gpu/ganesh/GrBackendUtils.h"
#include "src/gpu/ganesh/GrBuffer.h"
#include "src/gpu/ganesh/GrDataUtils.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpuBuffer.h"
#include "src/gpu/ganesh/GrImageInfo.h"
#include "src/gpu/ganesh/GrPipeline.h"
#include "src/gpu/ganesh/GrProgramInfo.h"
#include "src/gpu/ganesh/GrRenderTarget.h"
#include "src/gpu/ganesh/GrSemaphore.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/GrShaderVar.h"
#include "src/gpu/ganesh/GrStagingBufferManager.h"
#include "src/gpu/ganesh/GrSurface.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/GrUtil.h"
#include "src/gpu/ganesh/GrWindowRectangles.h"
#include "src/gpu/ganesh/gl/GrGLAttachment.h"
#include "src/gpu/ganesh/gl/GrGLBackendSurfacePriv.h"
#include "src/gpu/ganesh/gl/GrGLBuffer.h"
#include "src/gpu/ganesh/gl/GrGLOpsRenderPass.h"
#include "src/gpu/ganesh/gl/GrGLProgram.h"
#include "src/gpu/ganesh/gl/GrGLSemaphore.h"
#include "src/gpu/ganesh/gl/GrGLTextureRenderTarget.h"
#include "src/gpu/ganesh/gl/builders/GrGLShaderStringBuilder.h"
#include "src/sksl/SkSLProgramKind.h"
#include "src/sksl/SkSLProgramSettings.h"
#include "src/sksl/ir/SkSLProgram.h"
#include <algorithm>
#include <cmath>
#include <functional>
#include <memory>
#include <string>
#include <utility>
usingnamespaceskia_private;
#define GL_CALL(X) …
#define GL_CALL_RET(RET, X) …
#define GL_ALLOC_CALL(call) …
static const GrGLenum gXfermodeEquation2Blend[] = …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static const GrGLenum gXfermodeCoeff2Blend[] = …;
static int gl_target_to_binding_index(GrGLenum target) { … }
GrGpuResource::UniqueID GrGLGpu::TextureUnitBindings::boundID(GrGLenum target) const { … }
bool GrGLGpu::TextureUnitBindings::hasBeenModified(GrGLenum target) const { … }
void GrGLGpu::TextureUnitBindings::setBoundID(GrGLenum target, GrGpuResource::UniqueID resourceID) { … }
void GrGLGpu::TextureUnitBindings::invalidateForScratchUse(GrGLenum target) { … }
void GrGLGpu::TextureUnitBindings::invalidateAllTargets(bool markUnmodified) { … }
static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter) { … }
static GrGLenum filter_to_gl_min_filter(GrSamplerState::Filter filter,
GrSamplerState::MipmapMode mm) { … }
static inline GrGLenum wrap_mode_to_gl_wrap(GrSamplerState::WrapMode wrapMode,
const GrCaps& caps) { … }
static void cleanup_program(GrGLGpu* gpu,
GrGLuint* programID,
GrGLuint* vshader,
GrGLuint* fshader) { … }
class GrGLGpu::SamplerObjectCache { … };
std::unique_ptr<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface,
const GrContextOptions& options,
GrDirectContext* direct) { … }
GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrDirectContext* dContext)
: … { … }
GrGLGpu::~GrGLGpu() { … }
void GrGLGpu::disconnect(DisconnectType type) { … }
GrThreadSafePipelineBuilder* GrGLGpu::pipelineBuilder() { … }
sk_sp<GrThreadSafePipelineBuilder> GrGLGpu::refPipelineBuilder() { … }
void GrGLGpu::onResetContext(uint32_t resetBits) { … }
static bool check_backend_texture(const GrBackendTexture& backendTex,
const GrGLCaps& caps,
GrGLTexture::Desc* desc,
bool skipRectTexSupportCheck = false) { … }
static sk_sp<GrGLTextureParameters> get_gl_texture_params(const GrBackendTexture& backendTex) { … }
sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
GrWrapOwnership ownership,
GrWrapCacheable cacheable,
GrIOType ioType) { … }
static bool check_compressed_backend_texture(const GrBackendTexture& backendTex,
const GrGLCaps& caps, GrGLTexture::Desc* desc,
bool skipRectTexSupportCheck = false) { … }
sk_sp<GrTexture> GrGLGpu::onWrapCompressedBackendTexture(const GrBackendTexture& backendTex,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) { … }
sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt,
GrWrapOwnership ownership,
GrWrapCacheable cacheable) { … }
sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) { … }
static bool check_write_and_transfer_input(GrGLTexture* glTex) { … }
bool GrGLGpu::onWritePixels(GrSurface* surface,
SkIRect rect,
GrColorType surfaceColorType,
GrColorType srcColorType,
const GrMipLevel texels[],
int mipLevelCount,
bool prepForTexSampling) { … }
bool GrGLGpu::onTransferFromBufferToBuffer(sk_sp<GrGpuBuffer> src,
size_t srcOffset,
sk_sp<GrGpuBuffer> dst,
size_t dstOffset,
size_t size) { … }
bool GrGLGpu::onTransferPixelsTo(GrTexture* texture,
SkIRect rect,
GrColorType textureColorType,
GrColorType bufferColorType,
sk_sp<GrGpuBuffer> transferBuffer,
size_t offset,
size_t rowBytes) { … }
bool GrGLGpu::onTransferPixelsFrom(GrSurface* surface,
SkIRect rect,
GrColorType surfaceColorType,
GrColorType dstColorType,
sk_sp<GrGpuBuffer> transferBuffer,
size_t offset) { … }
void GrGLGpu::unbindXferBuffer(GrGpuBufferType type) { … }
bool GrGLGpu::uploadColorTypeTexData(GrGLFormat textureFormat,
GrColorType textureColorType,
SkISize texDims,
GrGLenum target,
SkIRect dstRect,
GrColorType srcColorType,
const GrMipLevel texels[],
int mipLevelCount) { … }
bool GrGLGpu::uploadColorToTex(GrGLFormat textureFormat,
SkISize texDims,
GrGLenum target,
std::array<float, 4> color,
uint32_t levelMask) { … }
void GrGLGpu::uploadTexData(SkISize texDims,
GrGLenum target,
SkIRect dstRect,
GrGLenum externalFormat,
GrGLenum externalType,
size_t bpp,
const GrMipLevel texels[],
int mipLevelCount) { … }
bool GrGLGpu::uploadCompressedTexData(SkTextureCompressionType compressionType,
GrGLFormat format,
SkISize dimensions,
skgpu::Mipmapped mipmapped,
GrGLenum target,
const void* data,
size_t dataSize) { … }
bool GrGLGpu::renderbufferStorageMSAA(const GrGLContext& ctx, int sampleCount, GrGLenum format,
int width, int height) { … }
bool GrGLGpu::createRenderTargetObjects(const GrGLTexture::Desc& desc,
int sampleCount,
GrGLRenderTarget::IDs* rtIDs) { … }
static sk_sp<GrTexture> return_null_texture() { … }
static GrGLTextureParameters::SamplerOverriddenState set_initial_texture_params(
const GrGLInterface* interface,
const GrGLCaps& caps,
GrGLenum target) { … }
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) { … }
sk_sp<GrTexture> GrGLGpu::onCreateCompressedTexture(SkISize dimensions,
const GrBackendFormat& format,
skgpu::Budgeted budgeted,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
const void* data,
size_t dataSize) { … }
GrBackendTexture GrGLGpu::onCreateCompressedBackendTexture(SkISize dimensions,
const GrBackendFormat& format,
skgpu::Mipmapped mipmapped,
GrProtected isProtected) { … }
bool GrGLGpu::onUpdateCompressedBackendTexture(const GrBackendTexture& backendTexture,
sk_sp<skgpu::RefCntedCallback> finishedCallback,
const void* data,
size_t length) { … }
int GrGLGpu::getCompatibleStencilIndex(GrGLFormat format) { … }
static void set_khr_debug_label(GrGLGpu* gpu, const GrGLuint id, std::string_view label) { … }
GrGLuint GrGLGpu::createCompressedTexture2D(
SkISize dimensions,
SkTextureCompressionType compression,
GrGLFormat format,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
GrGLTextureParameters::SamplerOverriddenState* initialState) { … }
GrGLuint GrGLGpu::createTexture(SkISize dimensions,
GrGLFormat format,
GrGLenum target,
GrRenderable renderable,
GrGLTextureParameters::SamplerOverriddenState* initialState,
int mipLevelCount,
GrProtected isProtected,
std::string_view label) { … }
sk_sp<GrAttachment> GrGLGpu::makeStencilAttachment(const GrBackendFormat& colorFormat,
SkISize dimensions, int numStencilSamples) { … }
sk_sp<GrAttachment> GrGLGpu::makeMSAAAttachment(SkISize dimensions, const GrBackendFormat& format,
int numSamples, GrProtected isProtected,
GrMemoryless isMemoryless) { … }
sk_sp<GrGpuBuffer> GrGLGpu::onCreateBuffer(size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern) { … }
void GrGLGpu::flushScissorTest(GrScissorTest scissorTest) { … }
void GrGLGpu::flushScissorRect(const SkIRect& scissor, int rtHeight, GrSurfaceOrigin rtOrigin) { … }
void GrGLGpu::flushViewport(const SkIRect& viewport, int rtHeight, GrSurfaceOrigin rtOrigin) { … }
void GrGLGpu::flushWindowRectangles(const GrWindowRectsState& windowState,
const GrGLRenderTarget* rt, GrSurfaceOrigin origin) { … }
void GrGLGpu::disableWindowRectangles() { … }
bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, bool useMultisampleFBO,
const GrProgramInfo& programInfo) { … }
void GrGLGpu::flushProgram(sk_sp<GrGLProgram> program) { … }
void GrGLGpu::flushProgram(GrGLuint id) { … }
void GrGLGpu::didDrawTo(GrRenderTarget* rt) { … }
GrGLenum GrGLGpu::bindBuffer(GrGpuBufferType type, const GrBuffer* buffer) { … }
void GrGLGpu::clear(const GrScissorState& scissor,
std::array<float, 4> color,
GrRenderTarget* target,
bool useMultisampleFBO,
GrSurfaceOrigin origin) { … }
static bool use_tiled_rendering(const GrGLCaps& glCaps,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) { … }
void GrGLGpu::beginCommandBuffer(GrGLRenderTarget* rt, bool useMultisampleFBO,
const SkIRect& bounds, GrSurfaceOrigin origin,
const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) { … }
void GrGLGpu::endCommandBuffer(GrGLRenderTarget* rt, bool useMultisampleFBO,
const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore) { … }
void GrGLGpu::clearStencilClip(const GrScissorState& scissor, bool insideStencilMask,
GrRenderTarget* target, bool useMultisampleFBO,
GrSurfaceOrigin origin) { … }
bool GrGLGpu::readOrTransferPixelsFrom(GrSurface* surface,
SkIRect rect,
GrColorType surfaceColorType,
GrColorType dstColorType,
void* offsetOrPtr,
int rowWidthInPixels) { … }
bool GrGLGpu::onReadPixels(GrSurface* surface,
SkIRect rect,
GrColorType surfaceColorType,
GrColorType dstColorType,
void* buffer,
size_t rowBytes) { … }
GrOpsRenderPass* GrGLGpu::onGetOpsRenderPass(
GrRenderTarget* rt,
bool useMultisampleFBO,
GrAttachment*,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const TArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) { … }
void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, bool useMultisampleFBO) { … }
void GrGLGpu::flushFramebufferSRGB(bool enable) { … }
GrGLenum GrGLGpu::prepareToDraw(GrPrimitiveType primitiveType) { … }
void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) { … }
void GrGLGpu::resolveRenderFBOs(GrGLRenderTarget* rt, const SkIRect& resolveRect,
ResolveDirection resolveDirection,
bool invalidateReadBufferAfterBlit) { … }
namespace {
GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { … }
void set_gl_stencil(const GrGLInterface* gl,
const GrStencilSettings::Face& face,
GrGLenum glFace) { … }
}
void GrGLGpu::flushStencil(const GrStencilSettings& stencilSettings, GrSurfaceOrigin origin) { … }
void GrGLGpu::disableStencil() { … }
void GrGLGpu::flushConservativeRasterState(bool enabled) { … }
void GrGLGpu::flushWireframeState(bool enabled) { … }
void GrGLGpu::flushBlendAndColorWrite(const skgpu::BlendInfo& blendInfo,
const skgpu::Swizzle& swizzle) { … }
void GrGLGpu::bindTexture(int unitIdx, GrSamplerState samplerState, const skgpu::Swizzle& swizzle,
GrGLTexture* texture) { … }
void GrGLGpu::onResetTextureBindings() { … }
void GrGLGpu::flushColorWrite(bool writeColor) { … }
void GrGLGpu::flushClearColor(std::array<float, 4> color) { … }
void GrGLGpu::setTextureUnit(int unit) { … }
void GrGLGpu::bindTextureToScratchUnit(GrGLenum target, GrGLint textureID) { … }
static inline bool can_blit_framebuffer_for_copy_surface(const GrSurface* dst,
const GrSurface* src,
const SkIRect& srcRect,
const SkIRect& dstRect,
const GrGLCaps& caps) { … }
static bool rt_has_msaa_render_buffer(const GrGLRenderTarget* rt, const GrGLCaps& glCaps) { … }
static inline bool can_copy_texsubimage(const GrSurface* dst, const GrSurface* src,
const GrGLCaps& caps) { … }
void GrGLGpu::bindSurfaceFBOForPixelOps(GrSurface* surface, int mipLevel, GrGLenum fboTarget,
TempFBOTarget tempFBOTarget) { … }
void GrGLGpu::unbindSurfaceFBOForPixelOps(GrSurface* surface, int mipLevel, GrGLenum fboTarget) { … }
void GrGLGpu::onFBOChanged() { … }
void GrGLGpu::bindFramebuffer(GrGLenum target, GrGLuint fboid) { … }
void GrGLGpu::deleteFramebuffer(GrGLuint fboid) { … }
bool GrGLGpu::onCopySurface(GrSurface* dst, const SkIRect& dstRect,
GrSurface* src, const SkIRect& srcRect,
GrSamplerState::Filter filter) { … }
bool GrGLGpu::createCopyProgram(GrTexture* srcTex) { … }
bool GrGLGpu::createMipmapProgram(int progIdx) { … }
bool GrGLGpu::copySurfaceAsDraw(GrSurface* dst, bool drawToMultisampleFBO, GrSurface* src,
const SkIRect& srcRect, const SkIRect& dstRect,
GrSamplerState::Filter filter) { … }
void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
const SkIPoint& dstPoint) { … }
bool GrGLGpu::copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
const SkIRect& dstRect, GrSamplerState::Filter filter) { … }
bool GrGLGpu::onRegenerateMipMapLevels(GrTexture* texture) { … }
void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { … }
GrBackendTexture GrGLGpu::onCreateBackendTexture(SkISize dimensions,
const GrBackendFormat& format,
GrRenderable renderable,
skgpu::Mipmapped mipmapped,
GrProtected isProtected,
std::string_view label) { … }
bool GrGLGpu::onClearBackendTexture(const GrBackendTexture& backendTexture,
sk_sp<skgpu::RefCntedCallback> finishedCallback,
std::array<float, 4> color) { … }
void GrGLGpu::deleteBackendTexture(const GrBackendTexture& tex) { … }
bool GrGLGpu::compile(const GrProgramDesc& desc, const GrProgramInfo& programInfo) { … }
#if defined(GPU_TEST_UTILS)
bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
SkASSERT(GrBackendApi::kOpenGL == tex.backend());
GrGLTextureInfo info;
if (!GrBackendTextures::GetGLTextureInfo(tex, &info)) {
return false;
}
GrGLboolean result;
GL_CALL_RET(result, IsTexture(info.fID));
return (GR_GL_TRUE == result);
}
GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(SkISize dimensions,
GrColorType colorType,
int sampleCnt,
GrProtected isProtected) {
if (dimensions.width() > this->caps()->maxRenderTargetSize() ||
dimensions.height() > this->caps()->maxRenderTargetSize()) {
return {};
}
if (isProtected == GrProtected::kYes && !this->glCaps().supportsProtectedContent()) {
return {};
}
this->handleDirtyContext();
auto format = this->glCaps().getFormatFromColorType(colorType);
sampleCnt = this->glCaps().getRenderTargetSampleCount(sampleCnt, format);
if (!sampleCnt) {
return {};
}
bool useTexture = false;
if (sampleCnt > 1 && !this->glCaps().usesMSAARenderBuffers()) {
useTexture = true;
} else if (format == GrGLFormat::kBGRA8 &&
this->glCaps().getRenderbufferInternalFormat(GrGLFormat::kBGRA8) != GR_GL_BGRA8) {
if (sampleCnt > 1) {
return {};
}
useTexture = true;
}
int sFormatIdx = this->getCompatibleStencilIndex(format);
if (sFormatIdx < 0) {
return {};
}
GrGLuint colorID = 0;
GrGLuint stencilID = 0;
GrGLFramebufferInfo info;
info.fFBOID = 0;
info.fFormat = GrGLFormatToEnum(format);
info.fProtected = GrProtected(isProtected == GrProtected::kYes ||
this->glCaps().supportsProtectedContent());
auto deleteIDs = [&](bool saveFBO = false) {
if (colorID) {
if (useTexture) {
GL_CALL(DeleteTextures(1, &colorID));
} else {
GL_CALL(DeleteRenderbuffers(1, &colorID));
}
}
if (stencilID) {
GL_CALL(DeleteRenderbuffers(1, &stencilID));
}
if (!saveFBO && info.fFBOID) {
this->deleteFramebuffer(info.fFBOID);
}
};
if (useTexture) {
GL_CALL(GenTextures(1, &colorID));
} else {
GL_CALL(GenRenderbuffers(1, &colorID));
}
GL_CALL(GenRenderbuffers(1, &stencilID));
if (!stencilID || !colorID) {
deleteIDs();
return {};
}
GL_CALL(GenFramebuffers(1, &info.fFBOID));
if (!info.fFBOID) {
deleteIDs();
return {};
}
this->invalidateBoundRenderTarget();
this->bindFramebuffer(GR_GL_FRAMEBUFFER, info.fFBOID);
if (useTexture) {
GrGLTextureParameters::SamplerOverriddenState initialState;
colorID = this->createTexture(dimensions, format, GR_GL_TEXTURE_2D, GrRenderable::kYes,
&initialState,
1,
info.fProtected,
"Skia");
if (!colorID) {
deleteIDs();
return {};
}
if (sampleCnt == 1) {
GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0,
GR_GL_TEXTURE_2D, colorID, 0));
} else {
GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0,
GR_GL_TEXTURE_2D, colorID, 0, sampleCnt));
}
} else {
GrGLenum renderBufferFormat = this->glCaps().getRenderbufferInternalFormat(format);
GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, colorID));
if (sampleCnt == 1) {
GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, renderBufferFormat, dimensions.width(),
dimensions.height()));
} else {
if (!this->renderbufferStorageMSAA(this->glContext(), sampleCnt, renderBufferFormat,
dimensions.width(), dimensions.height())) {
deleteIDs();
return {};
}
}
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0,
GR_GL_RENDERBUFFER, colorID));
}
GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, stencilID));
auto stencilBufferFormat = this->glCaps().stencilFormats()[sFormatIdx];
if (sampleCnt == 1) {
GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, GrGLFormatToEnum(stencilBufferFormat),
dimensions.width(), dimensions.height()));
} else {
if (!this->renderbufferStorageMSAA(this->glContext(), sampleCnt,
GrGLFormatToEnum(stencilBufferFormat),
dimensions.width(), dimensions.height())) {
deleteIDs();
return {};
}
}
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, GR_GL_RENDERBUFFER,
stencilID));
if (GrGLFormatIsPackedDepthStencil(this->glCaps().stencilFormats()[sFormatIdx])) {
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT,
GR_GL_RENDERBUFFER, stencilID));
}
this->bindFramebuffer(GR_GL_FRAMEBUFFER, 0);
deleteIDs( true);
this->bindFramebuffer(GR_GL_FRAMEBUFFER, info.fFBOID);
GrGLenum status;
GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
if (GR_GL_FRAMEBUFFER_COMPLETE != status) {
this->deleteFramebuffer(info.fFBOID);
return {};
}
auto stencilBits = SkToInt(GrGLFormatStencilBits(this->glCaps().stencilFormats()[sFormatIdx]));
GrBackendRenderTarget beRT = GrBackendRenderTargets::MakeGL(
dimensions.width(), dimensions.height(), sampleCnt, stencilBits, info);
SkASSERT(this->caps()->areColorTypeAndFormatCompatible(colorType, beRT.getBackendFormat()));
return beRT;
}
void GrGLGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
SkASSERT(GrBackendApi::kOpenGL == backendRT.backend());
GrGLFramebufferInfo info;
if (GrBackendRenderTargets::GetGLFramebufferInfo(backendRT, &info)) {
if (info.fFBOID) {
this->deleteFramebuffer(info.fFBOID);
}
}
}
#endif
GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLGpu* gpu,
const GrBuffer* ibuf) { … }
void GrGLGpu::addFinishedProc(GrGpuFinishedProc finishedProc,
GrGpuFinishedContext finishedContext) { … }
void GrGLGpu::flush(FlushType flushType) { … }
bool GrGLGpu::onSubmitToGpu(GrSyncCpu sync) { … }
void GrGLGpu::willExecute() { … }
void GrGLGpu::submit(GrOpsRenderPass* renderPass) { … }
[[nodiscard]] GrGLsync GrGLGpu::insertFence() { … }
bool GrGLGpu::waitSync(GrGLsync sync, uint64_t timeout, bool flush) { … }
bool GrGLGpu::waitFence(GrGLsync fence) { … }
void GrGLGpu::deleteFence(GrGLsync fence) { … }
[[nodiscard]] std::unique_ptr<GrSemaphore> GrGLGpu::makeSemaphore(bool isOwned) { … }
std::unique_ptr<GrSemaphore> GrGLGpu::wrapBackendSemaphore(const GrBackendSemaphore&,
GrSemaphoreWrapType,
GrWrapOwnership) { … }
void GrGLGpu::insertSemaphore(GrSemaphore* semaphore) { … }
void GrGLGpu::waitSemaphore(GrSemaphore* semaphore) { … }
void GrGLGpu::checkFinishProcs() { … }
void GrGLGpu::finishOutstandingGpuWork() { … }
void GrGLGpu::clearErrorsAndCheckForOOM() { … }
GrGLenum GrGLGpu::getErrorAndCheckForOOM() { … }
void GrGLGpu::deleteSync(GrGLsync sync) { … }
std::unique_ptr<GrSemaphore> GrGLGpu::prepareTextureForCrossContextUsage(GrTexture* texture) { … }
int GrGLGpu::TextureToCopyProgramIdx(GrTexture* texture) { … }
#ifdef SK_ENABLE_DUMP_GPU
#include "src/utils/SkJSONWriter.h"
void GrGLGpu::onDumpJSON(SkJSONWriter* writer) const {
writer->beginObject("GL GPU");
const GrGLubyte* str;
GL_CALL_RET(str, GetString(GR_GL_VERSION));
writer->appendCString("GL_VERSION", (const char*)(str));
GL_CALL_RET(str, GetString(GR_GL_RENDERER));
writer->appendCString("GL_RENDERER", (const char*)(str));
GL_CALL_RET(str, GetString(GR_GL_VENDOR));
writer->appendCString("GL_VENDOR", (const char*)(str));
GL_CALL_RET(str, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
writer->appendCString("GL_SHADING_LANGUAGE_VERSION", (const char*)(str));
writer->appendName("extensions");
glInterface()->fExtensions.dumpJSON(writer);
writer->endObject();
}
#endif