79#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
80#define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X)
82#define GL_ALLOC_CALL(call) \
84 if (this->glCaps().skipErrorChecks()) { \
85 GR_GL_CALL(this->glInterface(), call); \
86 return static_cast<GrGLenum>(GR_GL_NO_ERROR); \
88 this->clearErrorsAndCheckForOOM(); \
89 GR_GL_CALL_NOERRCHECK(this->glInterface(), call); \
90 return this->getErrorAndCheckForOOM(); \
179 SK_ABORT(
"Unexpected GL texture target.");
186bool GrGLGpu::TextureUnitBindings::hasBeenModified(
GrGLenum target)
const {
192 fTargetBindings[targetIndex].fBoundResourceID = resourceID;
193 fTargetBindings[targetIndex].fHasBeenModified =
true;
196void GrGLGpu::TextureUnitBindings::invalidateForScratchUse(
GrGLenum target) {
200void GrGLGpu::TextureUnitBindings::invalidateAllTargets(
bool markUnmodified) {
201 for (
auto& targetBinding : fTargetBindings) {
202 targetBinding.fBoundResourceID.makeInvalid();
203 if (markUnmodified) {
204 targetBinding.fHasBeenModified =
false;
214 case GrSamplerState::Filter::kLinear:
return GR_GL_LINEAR;
222 case GrSamplerState::MipmapMode::kNone:
224 case GrSamplerState::MipmapMode::kNearest:
230 case GrSamplerState::MipmapMode::kLinear:
281 fTextureUnitStates = std::make_unique<UnitState[]>(fNumTextureUnits);
285 if (!fNumTextureUnits) {
292 if (unitIdx >= fNumTextureUnits) {
298 const Sampler* sampler = fSamplers.
find(
key);
318 float maxAniso = std::min(
static_cast<GrGLfloat>(
state.maxAniso()),
326 if (!fTextureUnitStates[unitIdx].fKnown ||
327 fTextureUnitStates[unitIdx].fSamplerIDIfKnown != sampler->id()) {
329 fTextureUnitStates[unitIdx].fSamplerIDIfKnown = sampler->id();
330 fTextureUnitStates[unitIdx].fKnown =
true;
335 if (!fTextureUnitStates[unitIdx].fKnown ||
336 fTextureUnitStates[unitIdx].fSamplerIDIfKnown != 0) {
338 fTextureUnitStates[unitIdx].fSamplerIDIfKnown = 0;
339 fTextureUnitStates[unitIdx].fKnown =
true;
344 std::fill_n(fTextureUnitStates.get(), fNumTextureUnits, UnitState{});
348 fSamplers.
foreach([](uint32_t*
key, Sampler* sampler) { sampler->abandon(); });
349 fTextureUnitStates.reset();
350 fNumTextureUnits = 0;
354 if (!fNumTextureUnits) {
361 std::fill_n(fTextureUnitStates.get(), fNumTextureUnits, UnitState{});
368 Sampler(
const Sampler&) =
delete;
370 Sampler(Sampler&& that) {
372 fInterface = that.fInterface;
380 GR_GL_CALL(fInterface, DeleteSamplers(1, &fID));
386 void abandon() { fID = 0; }
398 static constexpr int kMaxSamplers = 32;
401 std::unique_ptr<UnitState[]> fTextureUnitStates;
403 int fNumTextureUnits;
411#if !defined(SK_DISABLE_LEGACY_GL_MAKE_NATIVE_INTERFACE)
433GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx,
GrDirectContext* dContext)
435 , fGLContext(
std::move(ctx))
436 , fProgramCache(new ProgramCache(dContext->
priv().
options().fRuntimeProgramCacheSize))
440 , fStencilClearFBOID(0)
441 , fFinishCallbacks(this) {
450 fHWTextureUnitBindings.
reset(this->numTextureUnits());
465 fHWBufferState[i].invalidate();
468 if (this->
glCaps().useSamplerObjects()) {
469 fSamplerObjectCache = std::make_unique<SamplerObjectCache>(
this);
476 fCopyProgramArrayBuffer.
reset();
477 fMipmapProgramArrayBuffer.
reset();
479 fProgramCache->
reset();
495 if (fStencilClearFBOID) {
499 for (
size_t i = 0; i < std::size(fCopyPrograms); ++i) {
500 if (0 != fCopyPrograms[i].
fProgram) {
505 for (
size_t i = 0; i < std::size(fMipmapPrograms); ++i) {
506 if (0 != fMipmapPrograms[i].
fProgram) {
511 fSamplerObjectCache.reset();
513 fFinishCallbacks.
callAll(
true);
528 if (fStencilClearFBOID) {
531 for (
size_t i = 0; i < std::size(fCopyPrograms); ++i) {
536 for (
size_t i = 0; i < std::size(fMipmapPrograms); ++i) {
542 if (fSamplerObjectCache) {
543 fSamplerObjectCache->release();
547 fProgramCache->abandon();
549 if (fSamplerObjectCache) {
550 fSamplerObjectCache->abandon();
555 fProgramCache->
reset();
556 fProgramCache.
reset();
561 fStencilClearFBOID = 0;
562 fCopyProgramArrayBuffer.
reset();
563 for (
size_t i = 0; i < std::size(fCopyPrograms); ++i) {
564 fCopyPrograms[i].fProgram = 0;
566 fMipmapProgramArrayBuffer.
reset();
567 for (
size_t i = 0; i < std::size(fMipmapPrograms); ++i) {
568 fMipmapPrograms[i].fProgram = 0;
575 return fProgramCache.
get();
579 return fProgramCache;
602 if (!this->
glCaps().isCoreProfile()) {
613 if (this->
glCaps().imagingSupport() && !this->
glCaps().isCoreProfile()) {
618 fHWWireframeEnabled = kUnknown_TriState;
627 this->
glCaps().fbFetchRequiresEnablePerSample()) {
632 fHWWriteToColor = kUnknown_TriState;
637 fHWClearColor[0] = fHWClearColor[1] = fHWClearColor[2] = fHWClearColor[3] =
SK_FloatNaN;
641 if (this->
glCaps().clientCanDisableMultisample()) {
646 fHWConservativeRasterEnabled = kUnknown_TriState;
649 fHWActiveTextureUnitIdx = -1;
653 for (
int s = 0;
s < this->numTextureUnits(); ++
s) {
654 fHWTextureUnitBindings[
s].invalidateAllTargets(
false);
656 if (fSamplerObjectCache) {
657 fSamplerObjectCache->invalidateBindings();
662 fHWBlendState.invalidate();
666 fHWScissorSettings.invalidate();
667 fHWWindowRectsState.invalidate();
673 fHWStencilTestEnabled = kUnknown_TriState;
678 fHWVertexArrayState.invalidate();
686 fHWSRGBFramebuffer = kUnknown_TriState;
687 fBoundDrawFramebuffer = 0;
692 if (this->
caps()->writePixelsRowBytesSupport() ||
693 this->
caps()->transferPixelsToRowBytesSupport()) {
696 if (this->
glCaps().readPixelsRowBytesSupport()) {
699 if (this->
glCaps().packFlipYSupport()) {
708 ++fResetTimestampForTextureParameters;
714 bool skipRectTexSupportCheck =
false) {
720 desc->fSize = {backendTex.
width(), backendTex.
height()};
721 desc->fTarget =
info.fTarget;
722 desc->fID =
info.fID;
724 desc->fIsProtected =
info.fProtected;
751 return glTextureData->info().refParameters();
781 texture->baseLevelWasBoundToFBO();
788 bool skipRectTexSupportCheck =
false) {
794 desc->fSize = {backendTex.
width(), backendTex.
height()};
795 desc->fTarget =
info.fTarget;
796 desc->fID =
info.fID;
798 desc->fIsProtected =
info.fProtected;
869 if (!this->createRenderTargetObjects(desc, sampleCnt, &rtIDs)) {
885 texRT->baseLevelWasBoundToFBO();
895 if (backendRT.
isProtected() && !this->glCaps().supportsProtectedContent()) {
907 if (sampleCount <= 1) {
925 "GLGpu_WrapBackendRenderTarget");
947 bool prepForTexSampling) {
954 this->bindTextureToScratchUnit(glTex->target(), glTex->textureID());
958 if (mipLevelCount && this->
glCaps().mipmapLevelControlSupport()) {
959 auto params = glTex->parameters();
961 int maxLevel = glTex->maxMipmapLevel();
962 if (
params->nonsamplerState().fBaseMipMapLevel != 0) {
966 if (
params->nonsamplerState().fMaxMipmapLevel != maxLevel) {
970 params->set(
nullptr, nonsamplerState, fResetTimestampForTextureParameters);
973 if (this->
glCaps().flushBeforeWritePixels()) {
978 return this->uploadColorTypeTexData(glTex->format(),
996 auto glSrc =
static_cast<const GrGLBuffer*
>(src.get());
997 auto glDst =
static_cast<const GrGLBuffer*
>(dst.get());
1029 static_assert(
sizeof(
int) ==
sizeof(int32_t),
"");
1033 SkASSERT(!transferBuffer->isMapped());
1034 SkASSERT(!transferBuffer->isCpuBuffer());
1041 const size_t trimRowBytes = rect.width() * bpp;
1042 const void* pixels = (
void*)
offset;
1046 bool restoreGLRowLength =
false;
1047 if (trimRowBytes != rowBytes) {
1051 restoreGLRowLength =
true;
1059 textureFormat, textureColorType, bufferColorType, &externalFormat, &externalType);
1060 if (!externalFormat || !externalType) {
1075 if (restoreGLRowLength) {
1088 auto* glBuffer =
static_cast<GrGLBuffer*
>(transferBuffer.
get());
1095 auto offsetAsPtr =
reinterpret_cast<void*
>(
offset);
1096 return this->readOrTransferPixelsFrom(
surface,
1110 auto* xferBufferState = this->hwBufferState(
type);
1111 if (!xferBufferState->fBufferZeroKnownBound) {
1112 GL_CALL(BindBuffer(xferBufferState->fGLTarget, 0));
1113 xferBufferState->fBoundBufferUniqueID.makeInvalid();
1114 xferBufferState->fBufferZeroKnownBound =
true;
1118bool GrGLGpu::uploadColorTypeTexData(
GrGLFormat textureFormat,
1125 int mipLevelCount) {
1137 textureFormat, textureColorType, srcColorType, &externalFormat, &externalType);
1138 if (!externalFormat || !externalType) {
1141 this->uploadTexData(texDims,
target, dstRect, externalFormat, externalType, bpp, texels,
1146bool GrGLGpu::uploadColorToTex(
GrGLFormat textureFormat,
1149 std::array<float, 4>
color,
1150 uint32_t levelMask) {
1152 GrGLenum externalFormat, externalType;
1159 std::unique_ptr<char[]> pixelStorage;
1163 levels.
resize(numLevels);
1165 for (
int i = 0; i < numLevels; ++i, levelDims = {std::max(levelDims.width() >> 1, 1),
1166 std::max(levelDims.height() >> 1, 1)}) {
1167 if (levelMask & (1 << i)) {
1168 if (!pixelStorage) {
1171 size_t rb = ii.minRowBytes();
1172 pixelStorage.reset(
new char[rb * levelDims.height()]);
1178 levels[i] = {pixelStorage.get(), levelDims.width()*bpp,
nullptr};
1186void GrGLGpu::uploadTexData(
SkISize texDims,
1193 int mipLevelCount) {
1202 bool restoreGLRowLength =
false;
1208 for (
int level = 0;
level < mipLevelCount; ++
level, dims = {std::max(dims.width() >> 1, 1),
1209 std::max(dims.height() >> 1, 1)}) {
1210 if (!texels[level].fPixels) {
1213 const size_t trimRowBytes = dims.
width() * bpp;
1219 restoreGLRowLength =
true;
1221 SkASSERT(rowBytes == trimRowBytes);
1224 GL_CALL(TexSubImage2D(
target, level, dstRect.
x(), dstRect.
y(), dims.width(), dims.height(),
1225 externalFormat, externalType, texels[level].fPixels));
1227 if (restoreGLRowLength) {
1245 if (!internalFormat) {
1251 bool useTexStorage =
caps.formatSupportsTexStorage(
format);
1253 int numMipLevels = 1;
1254 if (mipmapped == skgpu::Mipmapped::kYes) {
1263 if (useTexStorage) {
1272 for (
int level = 0;
level < numMipLevels; ++
level) {
1285 &((
const char*)data)[
offset]));
1292 dimensions = {std::max(1, dimensions.
width()/2), std::max(1, dimensions.
height()/2)};
1297 for (
int level = 0;
level < numMipLevels; ++
level) {
1301 const char* rawLevelData = &((
const char*)data)[
offset];
1316 dimensions = {std::max(1, dimensions.
width()/2), std::max(1, dimensions.
height()/2)};
1357 GL_CALL(DeleteRenderbuffers(1, &rtIDs->fMSColorRenderbufferID));
1360 this->deleteFramebuffer(rtIDs->fMultisampleFBOID);
1363 this->deleteFramebuffer(rtIDs->fSingleSampleFBOID);
1367 GrGLenum colorRenderbufferFormat = 0;
1387 if (sampleCount <= 1) {
1389 }
else if (this->
glCaps().usesImplicitMSAAResolve()) {
1404#if defined(__has_feature)
1405#define IS_TSAN __has_feature(thread_sanitizer)
1415 if (!this->renderbufferStorageMSAA(*fGLContext, sampleCount, colorRenderbufferFormat,
1416 desc.fSize.width(),
desc.fSize.height())) {
1426 if (!this->
glCaps().skipErrorChecks()) {
1432 if (this->
glCaps().rebindColorAttachmentAfterCheckFramebufferStatus()) {
1454 if (!this->
glCaps().skipErrorChecks()) {
1460 if (this->
glCaps().rebindColorAttachmentAfterCheckFramebufferStatus()) {
1479 cleanupOnFail.clear();
1511 int renderTargetSampleCnt,
1515 uint32_t levelClearMask,
1516 std::string_view label) {
1517 if (isProtected == GrProtected::kYes && !this->
glCaps().supportsProtectedContent()) {
1527 texDesc.
fSize = dimensions;
1528 switch (
format.textureType()) {
1536 if (mipLevelCount > 1 || !this->
glCaps().rectangleTextureSupport()) {
1548 texDesc.
fID = this->createTexture(dimensions, texDesc.
fFormat, texDesc.
fTarget, renderable,
1549 &initialState, mipLevelCount, texDesc.
fIsProtected, label);
1555 if (renderable == GrRenderable::kYes) {
1560 if (!this->createRenderTargetObjects(texDesc, renderTargetSampleCnt, &rtIDDesc)) {
1564 tex = sk_make_sp<GrGLTextureRenderTarget>(
this,
1566 renderTargetSampleCnt,
1571 tex->baseLevelWasBoundToFBO();
1573 tex = sk_make_sp<GrGLTexture>(
this, budgeted, texDesc, mipmapStatus, label);
1577 fResetTimestampForTextureParameters);
1578 if (levelClearMask) {
1579 if (this->
glCaps().clearTextureSupport()) {
1580 GrGLenum externalFormat, externalType;
1584 for (
int i = 0; i < mipLevelCount; ++i) {
1585 if (levelClearMask & (1U << i)) {
1586 GL_CALL(ClearTexImage(tex->textureID(), i, externalFormat, externalType,
1590 }
else if (this->
glCaps().canFormatBeFBOColorAttachment(
1592 !this->
glCaps().performColorClearsAsDraws()) {
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)) {
1600 kDst_TempFBOTarget);
1607 this->bindTextureToScratchUnit(texDesc.
fTarget, tex->textureID());
1608 std::array<float, 4> zeros = {};
1609 this->uploadColorToTex(texDesc.
fFormat,
1626 if (isProtected == GrProtected::kYes && !this->
glCaps().supportsProtectedContent()) {
1633 desc.fSize = dimensions;
1637 desc.fIsProtected = isProtected;
1638 desc.fID = this->createCompressedTexture2D(desc.fSize, compression, desc.fFormat,
1639 mipmapped, desc.fIsProtected, &initialState);
1645 if (!this->uploadCompressedTexData(compression, desc.fFormat, dimensions, mipmapped,
1647 GL_CALL(DeleteTextures(1, &desc.fID));
1655 GrMipmapStatus mipmapStatus = mipmapped == skgpu::Mipmapped::kYes
1659 auto tex = sk_make_sp<GrGLTexture>(
this, budgeted, desc, mipmapStatus,
1660 "GLGpuCreateCompressedTexture");
1663 fResetTimestampForTextureParameters);
1671 if (isProtected == GrProtected::kYes && !this->
glCaps().supportsProtectedContent()) {
1689 info.fProtected = isProtected;
1690 info.fID = this->createCompressedTexture2D(dimensions, compression, glFormat,
1691 mipmapped,
info.fProtected, &initialState);
1699 auto parameters = sk_make_sp<GrGLTextureParameters>();
1702 fResetTimestampForTextureParameters);
1705 dimensions.
width(), dimensions.
height(), mipmapped,
info, std::move(parameters));
1723 backendTexture.
hasMipmaps() ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
1725 this->bindTextureToScratchUnit(
info.fTarget,
info.fID);
1729 if (backendTexture.
hasMipmaps() && this->glCaps().mipmapLevelControlSupport()) {
1732 if (
params->nonsamplerState().fBaseMipMapLevel != 0) {
1738 if (
params->nonsamplerState().fMaxMipmapLevel != (numMipLevels - 1)) {
1742 params->set(
nullptr, nonsamplerState, fResetTimestampForTextureParameters);
1745 bool result = this->uploadCompressedTexData(compression,
1754 this->bindTextureToScratchUnit(
info.fTarget, 0);
1760 static const int kSize = 16;
1763 if (!this->
glCaps().hasStencilFormatBeenDeterminedForFormat(
format)) {
1765 int firstWorkingStencilFormatIndex = -1;
1781 GL_CALL(GenFramebuffers(1, &fb));
1790 GL_CALL(GenRenderbuffers(1, &sbRBID));
1796 for (
int i = 0; i < stencilFmtCnt && sbRBID; ++i) {
1816 firstWorkingStencilFormatIndex = i;
1829 GL_CALL(DeleteRenderbuffers(1, &sbRBID));
1831 GL_CALL(DeleteTextures(1, &colorID));
1834 fGLContext->caps()->setStencilFormatIndexForFormat(
format, firstWorkingStencilFormatIndex);
1840 const std::string khr_debug_label = label.empty() ?
"Skia" : std::string(label);
1846GrGLuint GrGLGpu::createCompressedTexture2D(
1870 if (GrProtected::kYes == isProtected) {
1871 if (this->
glCaps().supportsProtectedContent()) {
1874 GL_CALL(DeleteTextures(1, &
id));
1889 std::string_view label) {
1900 this->bindTextureToScratchUnit(
target,
id);
1904 if (GrRenderable::kYes == renderable && this->
glCaps().textureUsageSupport()) {
1915 if (GrProtected::kYes == isProtected) {
1916 if (this->
glCaps().supportsProtectedContent()) {
1919 GL_CALL(DeleteTextures(1, &
id));
1926 bool success =
false;
1927 if (internalFormat) {
1929 auto levelCount = std::max(mipLevelCount, 1);
1934 GrGLenum externalFormat, externalType;
1937 if (externalFormat && externalType) {
1942 const int twoToTheMipLevel = 1 <<
level;
1943 const int currentWidth = std::max(1, dimensions.
width() / twoToTheMipLevel);
1944 const int currentHeight = std::max(1, dimensions.
height() / twoToTheMipLevel);
1946 currentHeight, 0, externalFormat, externalType,
1956 GL_CALL(DeleteTextures(1, &
id));
1961 SkISize dimensions,
int numStencilSamples) {
1993 if (kYes_TriState != fHWScissorSettings.fEnabled) {
1995 fHWScissorSettings.fEnabled = kYes_TriState;
1998 if (kNo_TriState != fHWScissorSettings.fEnabled) {
2000 fHWScissorSettings.fEnabled = kNo_TriState;
2006 SkASSERT(fHWScissorSettings.fEnabled == TriState::kYes_TriState);
2008 if (fHWScissorSettings.fRect != nativeScissor) {
2009 GL_CALL(Scissor(nativeScissor.fX, nativeScissor.fY, nativeScissor.fWidth,
2010 nativeScissor.fHeight));
2011 fHWScissorSettings.fRect = nativeScissor;
2017 if (fHWViewport != nativeViewport) {
2018 GL_CALL(Viewport(nativeViewport.fX, nativeViewport.fY,
2019 nativeViewport.fWidth, nativeViewport.fHeight));
2020 fHWViewport = nativeViewport;
2032 if (!this->
caps()->maxWindowRectangles() ||
2033 fHWWindowRectsState.knownEqualTo(origin, rt->
width(), rt->
height(), windowState)) {
2044 for (
int i = 0; i < numWindows; ++i) {
2049 GL_CALL(WindowRectangles(glmode, numWindows, glwindows->
asInts()));
2051 fHWWindowRectsState.set(origin, rt->
width(), rt->
height(), windowState);
2055void GrGLGpu::disableWindowRectangles() {
2057 if (!this->
caps()->maxWindowRectangles() || fHWWindowRectsState.knownDisabled()) {
2061 fHWWindowRectsState.setDisabled();
2092 this->flushStencil(stencil, programInfo.
origin());
2095 glRT, programInfo.
origin());
2101 this->flushRenderTarget(glRT, useMultisampleFBO);
2112 SkASSERT((program == fHWProgram) == (fHWProgramID == program->programID()));
2113 if (program == fHWProgram) {
2116 auto id = program->programID();
2119 fHWProgram = std::move(program);
2125 if (fHWProgramID ==
id) {
2135 SkASSERT(fHWWriteToColor != kUnknown_TriState);
2136 if (fHWWriteToColor == kYes_TriState) {
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();
2159 bufferState->fBoundBufferUniqueID) {
2162 bufferState->fBufferZeroKnownBound =
false;
2163 bufferState->fBoundBufferUniqueID = glBuffer->
uniqueID();
2166 return bufferState->fGLTarget;
2170 std::array<float, 4>
color,
2172 bool useMultisampleFBO,
2177 SkASSERT(!scissor.
enabled() || !this->caps()->performPartialClearsAsDraws());
2183 this->flushRenderTarget(glRT, useMultisampleFBO);
2184 this->flushScissor(scissor, glRT->
height(), origin);
2185 this->disableWindowRectangles();
2186 this->flushColorWrite(
true);
2187 this->flushClearColor(
color);
2204 SkASSERT(!fIsExecutingCommandBuffer_DebugOnly);
2208 this->flushRenderTarget(rt, useMultisampleFBO);
2209 SkDEBUGCODE(fIsExecutingCommandBuffer_DebugOnly =
true);
2216 GL_CALL(StartTiling(nativeBounds.fX, nativeBounds.fY, nativeBounds.fWidth,
2217 nativeBounds.fHeight, preserveMask));
2223 this->flushClearColor(colorLoadStore.
fClearColor);
2224 this->flushColorWrite(
true);
2228 SkASSERT(!this->
caps()->performStencilClearsAsDraws());
2229 GL_CALL(StencilMask(0xffffffff));
2235 this->disableWindowRectangles();
2246 SkASSERT(fIsExecutingCommandBuffer_DebugOnly);
2250 if (rt->
uniqueID() != fHWBoundRenderTargetUniqueID ||
2251 useMultisampleFBO != fHWBoundFramebufferIsMSAA) {
2268 if (!discardAttachments.
empty()) {
2271 discardAttachments.
begin()));
2275 discardAttachments.
begin()));
2285 GL_CALL(EndTiling(preserveMask));
2288 SkDEBUGCODE(fIsExecutingCommandBuffer_DebugOnly =
false);
2295 SkASSERT(!this->
caps()->performStencilClearsAsDraws());
2296 SkASSERT(!scissor.
enabled() || !this->caps()->performPartialClearsAsDraws());
2309 GrGLint clipStencilMask = (1 << (stencilBitCount - 1));
2316 static const GrGLint clipStencilMask = ~0;
2319 if (insideStencilMask) {
2320 value = (1 << (stencilBitCount - 1));
2325 this->flushRenderTarget(glRT, useMultisampleFBO);
2327 this->flushScissor(scissor, glRT->
height(), origin);
2328 this->disableWindowRectangles();
2330 GL_CALL(StencilMask((uint32_t) clipStencilMask));
2341 int rowWidthInPixels) {
2352 format, surfaceColorType, dstColorType, &externalFormat, &externalType);
2353 if (!externalFormat || !externalType) {
2359 constexpr bool useMultisampleFBO =
false;
2360 if (renderTarget->
numSamples() > 1 && renderTarget->
isFBO0(useMultisampleFBO)) {
2363 this->flushRenderTarget(renderTarget, useMultisampleFBO);
2371 if (rowWidthInPixels !=
rect.width()) {
2385 if (rowWidthInPixels !=
rect.width()) {
2390 if (!renderTarget) {
2409 if (rowBytes ==
SkToSizeT(rect.width()*bytesPerPixel)) {
2410 rowPixelWidth = rect.width();
2412 SkASSERT(!(rowBytes % bytesPerPixel));
2413 rowPixelWidth = rowBytes / bytesPerPixel;
2416 return this->readOrTransferPixelsFrom(
surface,
2426 bool useMultisampleFBO,
2434 if (!fCachedOpsRenderPass) {
2435 fCachedOpsRenderPass = std::make_unique<GrGLOpsRenderPass>(
this);
2437 if (useMultisampleFBO && rt->
numSamples() == 1) {
2440 if (!glRT->ensureDynamicMSAAAttachment()) {
2441 SkDebugf(
"WARNING: Failed to make dmsaa attachment. Render pass will be dropped.");
2445 fCachedOpsRenderPass->set(rt, useMultisampleFBO, bounds, origin, colorInfo, stencilInfo);
2446 return fCachedOpsRenderPass.get();
2452 if (fHWBoundRenderTargetUniqueID != rtID ||
2453 fHWBoundFramebufferIsMSAA != useMultisampleFBO ||
2454 target->mustRebind(useMultisampleFBO)) {
2455 target->bind(useMultisampleFBO);
2462 if (!this->
glCaps().skipErrorChecks() &&
2463 !this->
glCaps().rebindColorAttachmentAfterCheckFramebufferStatus()) {
2467 SkDebugf(
"GrGLGpu::flushRenderTargetNoColorWrites glCheckFramebufferStatus %x\n",
2472 fHWBoundRenderTargetUniqueID = rtID;
2473 fHWBoundFramebufferIsMSAA = useMultisampleFBO;
2478 if (this->
caps()->workarounds().force_update_scissor_state_when_binding_fbo0) {
2480 if (!fHWScissorSettings.fRect.isInvalid()) {
2484 if (fHWScissorSettings.fEnabled == kYes_TriState) {
2487 }
else if (fHWScissorSettings.fEnabled == kNo_TriState) {
2493 if (this->
glCaps().srgbWriteControl()) {
2494 this->flushFramebufferSRGB(this->
caps()->isFormatSRGB(
target->backendFormat()));
2497 if (this->
glCaps().shouldQueryImplementationReadSupport(
target->format())) {
2506void GrGLGpu::flushFramebufferSRGB(
bool enable) {
2507 if (enable && kYes_TriState != fHWSRGBFramebuffer) {
2509 fHWSRGBFramebuffer = kYes_TriState;
2510 }
else if (!enable && kNo_TriState != fHWSRGBFramebuffer) {
2512 fHWSRGBFramebuffer = kNo_TriState;
2519 if (this->
glCaps().requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() &&
2524 fLastPrimitiveType = primitiveType;
2526 switch (primitiveType) {
2538 SK_ABORT(
"invalid GrPrimitiveType");
2545 ResolveDirection::kMSAAToSingle);
2553 bool invalidateReadBufferAfterBlit) {
2564 SkASSERT(resolveDirection != ResolveDirection::kSingleToMSAA);
2572 this->disableWindowRectangles();
2573 GL_CALL(ResolveMultisampleFramebuffer());
2577 int l = resolveRect.
x();
2578 int b = resolveRect.
y();
2579 int r = resolveRect.
x() + resolveRect.
width();
2580 int t = resolveRect.
y() + resolveRect.
height();
2584 this->disableWindowRectangles();
2589 invalidateReadBufferAfterBlit) {
2592 bool readBufferIsMSAA = resolveDirection == ResolveDirection::kMSAAToSingle;
2600 rt->
bind(readBufferIsMSAA);
2629 return gTable[(
int)op];
2646 GR_GL_CALL(gl, StencilFunc(glFunc, ref, mask));
2650 GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask));
2651 GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask));
2659 this->disableStencil();
2660 }
else if (fHWStencilSettings != stencilSettings ||
2661 (stencilSettings.
isTwoSided() && fHWStencilOrigin != origin)) {
2662 if (kYes_TriState != fHWStencilTestEnabled) {
2665 fHWStencilTestEnabled = kYes_TriState;
2676 fHWStencilSettings = stencilSettings;
2677 fHWStencilOrigin = origin;
2681void GrGLGpu::disableStencil() {
2682 if (kNo_TriState != fHWStencilTestEnabled) {
2685 fHWStencilTestEnabled = kNo_TriState;
2690void GrGLGpu::flushConservativeRasterState(
bool enabled) {
2691 if (this->
caps()->conservativeRasterSupport()) {
2693 if (kYes_TriState != fHWConservativeRasterEnabled) {
2695 fHWConservativeRasterEnabled = kYes_TriState;
2698 if (kNo_TriState != fHWConservativeRasterEnabled) {
2700 fHWConservativeRasterEnabled = kNo_TriState;
2706void GrGLGpu::flushWireframeState(
bool enabled) {
2707 if (this->
caps()->wireframeSupport()) {
2708 if (this->
caps()->wireframeMode() || enabled) {
2709 if (kYes_TriState != fHWWireframeEnabled) {
2711 fHWWireframeEnabled = kYes_TriState;
2714 if (kNo_TriState != fHWWireframeEnabled) {
2716 fHWWireframeEnabled = kNo_TriState;
2730 this->flushBlendAndColorWrite(preserveDstBlend, swizzle);
2744 if (kNo_TriState != fHWBlendState.fEnabled) {
2751 SkASSERT(this->
caps()->advancedBlendEquationSupport());
2755 fHWBlendState.fEquation = blendEquation;
2762 if (this->
glCaps().mustResetBlendFuncBetweenDualSourceAndDisable() &&
2773 fHWBlendState.fEnabled = kNo_TriState;
2776 if (kYes_TriState != fHWBlendState.fEnabled) {
2779 fHWBlendState.fEnabled = kYes_TriState;
2782 if (fHWBlendState.fEquation != equation) {
2784 fHWBlendState.fEquation = equation;
2788 SkASSERT(this->
caps()->advancedBlendEquationSupport());
2795 if (fHWBlendState.fSrcCoeff != srcCoeff || fHWBlendState.fDstCoeff != dstCoeff) {
2798 fHWBlendState.fSrcCoeff = srcCoeff;
2799 fHWBlendState.fDstCoeff = dstCoeff;
2804 if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blendConst) {
2805 GL_CALL(BlendColor(blendConst.
fR, blendConst.
fG, blendConst.
fB, blendConst.
fA));
2806 fHWBlendState.fConstColor = blendConst;
2807 fHWBlendState.fConstColorValid =
true;
2820 if (!this->
caps()->npotTextureTileSupport()) {
2834 if (fHWTextureUnitBindings[unitIdx].boundID(
target) != textureID) {
2835 this->setTextureUnit(unitIdx);
2837 fHWTextureUnitBindings[unitIdx].setBoundID(
target, textureID);
2840 if (samplerState.
mipmapped() == skgpu::Mipmapped::kYes) {
2841 if (!this->
caps()->mipmapSupport() ||
texture->mipmapped() == skgpu::Mipmapped::kNo) {
2847 GrSamplerState::MipmapMode::kNone);
2853 auto timestamp =
texture->parameters()->resetTimestamp();
2854 bool setAll = timestamp < fResetTimestampForTextureParameters;
2857 if (this->
glCaps().useSamplerObjects()) {
2858 fSamplerObjectCache->bindSampler(unitIdx, samplerState);
2859 if (this->
glCaps().mustSetAnyTexParameterToEnableMipmapping()) {
2860 if (samplerState.
mipmapped() == skgpu::Mipmapped::kYes) {
2864 texture->parameters()->samplerOverriddenState();
2865 this->setTextureUnit(unitIdx);
2867 newSamplerState = oldSamplerState;
2869 samplerStateToRecord = &newSamplerState;
2873 if (fSamplerObjectCache) {
2874 fSamplerObjectCache->unbindSampler(unitIdx);
2877 texture->parameters()->samplerOverriddenState();
2878 samplerStateToRecord = &newSamplerState;
2888 this->glCaps().maxTextureMaxAnisotropy());
2891 newSamplerState.
fMinLOD = -1000.f;
2892 newSamplerState.
fMaxLOD = 1000.f;
2895 this->setTextureUnit(unitIdx);
2899 this->setTextureUnit(unitIdx);
2902 if (this->
glCaps().mipmapLodControlSupport()) {
2903 if (setAll || newSamplerState.
fMinLOD != oldSamplerState.
fMinLOD) {
2904 this->setTextureUnit(unitIdx);
2907 if (setAll || newSamplerState.
fMaxLOD != oldSamplerState.
fMaxLOD) {
2908 this->setTextureUnit(unitIdx);
2912 if (setAll || newSamplerState.
fWrapS != oldSamplerState.
fWrapS) {
2913 this->setTextureUnit(unitIdx);
2916 if (setAll || newSamplerState.
fWrapT != oldSamplerState.
fWrapT) {
2917 this->setTextureUnit(unitIdx);
2920 if (this->
glCaps().clampToBorderSupport()) {
2923 this->setTextureUnit(unitIdx);
2924 static const GrGLfloat kTransparentBlack[4] = {0.f, 0.f, 0.f, 0.f};
2928 if (this->
caps()->anisoSupport()) {
2942 texture->parameters()->nonsamplerState();
2943 if (this->
glCaps().textureSwizzleSupport()) {
2951 this->setTextureUnit(unitIdx);
2966 if (this->
glCaps().mipmapLevelControlSupport() &&
2968 !this->glCaps().dontSetBaseOrMaxLevelForExternalTextures())) {
2970 this->setTextureUnit(unitIdx);
2975 this->setTextureUnit(unitIdx);
2980 texture->parameters()->set(samplerStateToRecord, newNonsamplerState,
2981 fResetTimestampForTextureParameters);
2987 for (
int i = 0; i < this->numTextureUnits(); ++i) {
2988 this->setTextureUnit(i);
2989 for (
auto target : kTargets) {
2990 if (fHWTextureUnitBindings[i].hasBeenModified(
target)) {
2994 fHWTextureUnitBindings[i].invalidateAllTargets(
true);
2998void GrGLGpu::flushColorWrite(
bool writeColor) {
3000 if (kNo_TriState != fHWWriteToColor) {
3003 fHWWriteToColor = kNo_TriState;
3006 if (kYes_TriState != fHWWriteToColor) {
3008 fHWWriteToColor = kYes_TriState;
3013void GrGLGpu::flushClearColor(std::array<float, 4>
color) {
3015 if (this->
glCaps().clearToBoundaryValuesIsBroken() &&
3016 (1 == r || 0 == r) && (1 == g || 0 == g) && (1 ==
b || 0 ==
b) && (1 ==
a || 0 ==
a)) {
3017 static const GrGLfloat safeAlpha1 = nextafter(1.f, 2.f);
3018 static const GrGLfloat safeAlpha0 = nextafter(0.f, -1.f);
3019 a = (1 ==
a) ? safeAlpha1 : safeAlpha0;
3021 if (r != fHWClearColor[0] || g != fHWClearColor[1] ||
3022 b != fHWClearColor[2] ||
a != fHWClearColor[3]) {
3024 fHWClearColor[0] = r;
3025 fHWClearColor[1] = g;
3026 fHWClearColor[2] =
b;
3027 fHWClearColor[3] =
a;
3031void GrGLGpu::setTextureUnit(
int unit) {
3032 SkASSERT(unit >= 0 && unit < this->numTextureUnits());
3033 if (unit != fHWActiveTextureUnitIdx) {
3035 fHWActiveTextureUnitIdx = unit;
3041 int lastUnitIdx = this->numTextureUnits() - 1;
3042 if (lastUnitIdx != fHWActiveTextureUnitIdx) {
3044 fHWActiveTextureUnitIdx = lastUnitIdx;
3048 fHWTextureUnitBindings[lastUnitIdx].invalidateForScratchUse(
target);
3058 int dstSampleCnt = 0;
3059 int srcSampleCnt = 0;
3081 dstTexTypePtr = &dstTexType;
3085 srcTexTypePtr = &srcTexType;
3088 return caps.
canCopyAsBlit(dstFormat, dstSampleCnt, dstTexTypePtr,
3089 srcFormat, srcSampleCnt, srcTexTypePtr,
3090 src->getBoundsRect(),
true, srcRect, dstRect);
3121 dstTexTypePtr = &dstTexType;
3125 srcTexTypePtr = &srcTexType;
3129 srcFormat, srcHasMSAARenderBuffer, srcTexTypePtr);
3133 TempFBOTarget tempFBOTarget) {
3135 if (!rt || mipLevel > 0) {
3141 tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTempDstFBOID;
3143 if (0 == *tempFBOID) {
3151 if (mipLevel == 0) {
3152 texture->baseLevelWasBoundToFBO();
3161 if (mipLevel > 0 || !
surface->asRenderTarget()) {
3172void GrGLGpu::onFBOChanged() {
3173 if (this->
caps()->workarounds().flush_on_framebuffer_change) {
3174 this->flush(FlushType::kForce);
3177 if (fIsExecutingCommandBuffer_DebugOnly) {
3178 SkDebugf(
"WARNING: GL FBO binding changed while executing a command buffer. "
3179 "This will severely hurt performance.\n");
3187 fBoundDrawFramebuffer = fboid;
3189 this->onFBOChanged();
3196 if (fboid == fBoundDrawFramebuffer &&
3197 this->
caps()->workarounds().unbind_attachments_on_bound_render_fbo_delete) {
3210 GL_CALL(DeleteFramebuffers(1, &fboid));
3213 if (fboid == fBoundDrawFramebuffer) {
3214 this->onFBOChanged();
3223 bool preferCopy =
SkToBool(dst->asRenderTarget());
3224 bool scalingCopy = dstRect.
size() != srcRect.
size();
3227 this->
glCaps().canCopyAsDraw(dstFormat,
SkToBool(src->asTexture()), scalingCopy)) {
3229 bool drawToMultisampleFBO = dstRT && dstRT->
numSamples() > 1;
3230 if (this->copySurfaceAsDraw(dst, drawToMultisampleFBO, src, srcRect, dstRect, filter)) {
3237 this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstRect.
topLeft());
3242 return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstRect, filter);
3246 this->
glCaps().canCopyAsDraw(dstFormat,
SkToBool(src->asTexture()), scalingCopy)) {
3248 bool drawToMultisampleFBO = dstRT && dstRT->
numSamples() > 1;
3249 if (this->copySurfaceAsDraw(dst, drawToMultisampleFBO, src, srcRect, dstRect, filter)) {
3257bool GrGLGpu::createCopyProgram(
GrTexture* srcTex) {
3260 int progIdx = TextureToCopyProgramIdx(srcTex);
3264 if (!fCopyProgramArrayBuffer) {
3275 if (fCopyProgramArrayBuffer) {
3277 vdata, 0,
sizeof(vdata),
false);
3280 if (!fCopyProgramArrayBuffer) {
3286 if (!fCopyPrograms[progIdx].
fProgram) {
3301 vshaderTxt.
appendf(
"#extension %s : require\n", extension);
3303 vTexCoord.addModifier(
"noperspective");
3306 aVertex.appendDecl(shaderCaps, &vshaderTxt);
3308 uTexCoordXform.appendDecl(shaderCaps, &vshaderTxt);
3310 uPosXform.appendDecl(shaderCaps, &vshaderTxt);
3312 vTexCoord.appendDecl(shaderCaps, &vshaderTxt);
3318 "v_texCoord = half2(a_vertex.xy * u_texCoordXform.xy + u_texCoordXform.zw);"
3319 "sk_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;"
3320 "sk_Position.zw = half2(0, 1);"
3327 fshaderTxt.
appendf(
"#extension %s : require\n", extension);
3331 vTexCoord.appendDecl(shaderCaps, &fshaderTxt);
3333 uTexture.appendDecl(shaderCaps, &fshaderTxt);
3338 "sk_FragColor = sample(u_texture, v_texCoord);"
3341 std::string vertexSkSL{vshaderTxt.
c_str(), vshaderTxt.
size()};
3342 std::string fragmentSkSL{fshaderTxt.
c_str(), fshaderTxt.
size()};
3355 fProgramCache->stats(),
3371 fProgramCache->stats(),
3394 GetUniformLocation(fCopyPrograms[progIdx].
fProgram,
"u_texture"));
3396 GetUniformLocation(fCopyPrograms[progIdx].
fProgram,
"u_posXform"));
3398 GetUniformLocation(fCopyPrograms[progIdx].
fProgram,
"u_texCoordXform"));
3400 GL_CALL(BindAttribLocation(fCopyPrograms[progIdx].
fProgram, 0,
"a_vertex"));
3408bool GrGLGpu::createMipmapProgram(
int progIdx) {
3409 const bool oddWidth =
SkToBool(progIdx & 0x2);
3410 const bool oddHeight =
SkToBool(progIdx & 0x1);
3411 const int numTaps = (oddWidth ? 2 : 1) * (oddHeight ? 2 : 1);
3417 if (!fMipmapPrograms[progIdx].
fProgram) {
3437 vshaderTxt.
appendf(
"#extension %s : require\n", extension);
3445 aVertex.appendDecl(shaderCaps, &vshaderTxt);
3447 uTexCoordXform.appendDecl(shaderCaps, &vshaderTxt);
3449 for (
int i = 0; i < numTaps; ++i) {
3450 vTexCoords[i].
appendDecl(shaderCaps, &vshaderTxt);
3457 "sk_Position.xy = a_vertex * half2(2) - half2(1);"
3458 "sk_Position.zw = half2(0, 1);"
3462 if (oddWidth && oddHeight) {
3464 "v_texCoord0 = a_vertex.xy * u_texCoordXform.yw;"
3465 "v_texCoord1 = a_vertex.xy * u_texCoordXform.yw + half2(u_texCoordXform.x, 0);"
3466 "v_texCoord2 = a_vertex.xy * u_texCoordXform.yw + half2(0, u_texCoordXform.z);"
3467 "v_texCoord3 = a_vertex.xy * u_texCoordXform.yw + u_texCoordXform.xz;"
3469 }
else if (oddWidth) {
3471 "v_texCoord0 = a_vertex.xy * half2(u_texCoordXform.y, 1);"
3472 "v_texCoord1 = a_vertex.xy * half2(u_texCoordXform.y, 1) + half2(u_texCoordXform.x, 0);"
3474 }
else if (oddHeight) {
3476 "v_texCoord0 = a_vertex.xy * half2(1, u_texCoordXform.w);"
3477 "v_texCoord1 = a_vertex.xy * half2(1, u_texCoordXform.w) + half2(0, u_texCoordXform.z);"
3481 "v_texCoord0 = a_vertex.xy;"
3490 fshaderTxt.
appendf(
"#extension %s : require\n", extension);
3493 for (
int i = 0; i < numTaps; ++i) {
3495 vTexCoords[i].
appendDecl(shaderCaps, &fshaderTxt);
3498 uTexture.appendDecl(shaderCaps, &fshaderTxt);
3505 if (oddWidth && oddHeight) {
3507 "sk_FragColor = (sample(u_texture, v_texCoord0) + "
3508 "sample(u_texture, v_texCoord1) + "
3509 "sample(u_texture, v_texCoord2) + "
3510 "sample(u_texture, v_texCoord3)) * 0.25;"
3512 }
else if (oddWidth || oddHeight) {
3514 "sk_FragColor = (sample(u_texture, v_texCoord0) + "
3515 "sample(u_texture, v_texCoord1)) * 0.5;"
3519 "sk_FragColor = sample(u_texture, v_texCoord0);"
3525 std::string vertexSkSL{vshaderTxt.
c_str(), vshaderTxt.
size()};
3526 std::string fragmentSkSL{fshaderTxt.
c_str(), fshaderTxt.
size()};
3540 fProgramCache->stats(),
3555 fProgramCache->stats(),
3577 GetUniformLocation(fMipmapPrograms[progIdx].
fProgram,
"u_texture"));
3579 GetUniformLocation(fMipmapPrograms[progIdx].
fProgram,
"u_texCoordXform"));
3581 GL_CALL(BindAttribLocation(fMipmapPrograms[progIdx].
fProgram, 0,
"a_vertex"));
3589bool GrGLGpu::copySurfaceAsDraw(
GrSurface* dst,
bool drawToMultisampleFBO,
GrSurface* src,
3599 this->flushRenderTarget(dstRT, drawToMultisampleFBO);
3604 if (!this->
glCaps().isFormatRenderable(dstTex->format(), 1)) {
3610 int progIdx = TextureToCopyProgramIdx(srcTex);
3611 if (!fCopyPrograms[progIdx].
fProgram) {
3612 if (!this->createCopyProgram(srcTex)) {
3613 SkDebugf(
"Failed to create copy program.\n");
3621 fHWVertexArrayState.setVertexArrayID(
this, 0);
3627 int dw =
dst->width();
3628 int dh =
dst->height();
3637 int sw =
src->width();
3638 int sh =
src->height();
3648 sx1 - sx0, sy1 - sy0, sx0, sy0));
3651 this->flushConservativeRasterState(
false);
3652 this->flushWireframeState(
false);
3654 this->disableWindowRectangles();
3655 this->disableStencil();
3656 if (this->
glCaps().srgbWriteControl()) {
3657 this->flushFramebufferSRGB(
true);
3675 this->bindTextureToScratchUnit(dstTex->
target(), dstTex->
textureID());
3677 dstPoint.
fX, dstPoint.
fY,
3703 this->disableWindowRectangles();
3739 this->bindTextureToScratchUnit(
target, glTex->textureID());
3740 GL_CALL(GenerateMipmap(glTex->target()));
3750 if (0 == fTempDstFBOID) {
3751 GL_CALL(GenFramebuffers(1, &fTempDstFBOID));
3758 this->setTextureUnit(0);
3763 if (!fMipmapProgramArrayBuffer) {
3774 fMipmapProgramArrayBuffer->
updateData(vdata, 0,
3779 if (!fMipmapProgramArrayBuffer) {
3783 fHWVertexArrayState.setVertexArrayID(
this, 0);
3793 this->disableWindowRectangles();
3794 this->disableStencil();
3800 std::unique_ptr<GrSemaphore> semaphore;
3801 for (
GrGLint level = 1; level < levelCount; ++level) {
3803 int progIdx = TextureSizeToMipmapProgramIdx(
width,
height);
3804 if (!fMipmapPrograms[progIdx].
fProgram) {
3805 if (!this->createMipmapProgram(progIdx)) {
3806 SkDebugf(
"Failed to create mipmap program.\n");
3808 glTex->textureParamsModified();
3814 if (this->
glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusSync &&
3821 const float invWidth = 1.0f /
width;
3822 const float invHeight = 1.0f /
height;
3824 invWidth, (
width - 1) * invWidth, invHeight, (
height - 1) * invHeight));
3834 if (this->
glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusMaxLevel) {
3839 glTex->textureID(), level));
3847 if (this->
glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusSync &&
3848 level < levelCount-1) {
3862 if (this->
glCaps().regenerateMipmapType() == RegenerateMipmapType::kBasePlusMaxLevel) {
3865 glTex->parameters()->set(
nullptr, nonsamplerState, fResetTimestampForTextureParameters);
3889 this->
caps()->blendEquationSupport());
3901 std::string_view label) {
3909 int numMipLevels = 1;
3910 if (mipmapped == skgpu::Mipmapped::kYes) {
3923 switch (
format.textureType()) {
3931 if (!this->
glCaps().rectangleTextureSupport() || mipmapped == skgpu::Mipmapped::kYes) {
3938 info.fID = this->createTexture(dimensions, glFormat,
info.fTarget, renderable, &initialState,
3939 numMipLevels, isProtected, label);
3943 info.fProtected = isProtected;
3946 this->bindTextureToScratchUnit(
info.fTarget, 0);
3948 auto parameters = sk_make_sp<GrGLTextureParameters>();
3951 fResetTimestampForTextureParameters);
3954 dimensions.
width(), dimensions.
height(), mipmapped,
info, std::move(parameters), label);
3959 std::array<float, 4>
color) {
3965 int numMipLevels = 1;
3973 this->bindTextureToScratchUnit(
info.fTarget,
info.fID);
3977 if (numMipLevels && this->
glCaps().mipmapLevelControlSupport()) {
3980 if (
params->nonsamplerState().fBaseMipMapLevel != 0) {
3984 if (
params->nonsamplerState().fMaxMipmapLevel != (numMipLevels - 1)) {
3988 params->set(
nullptr, nonsamplerState, fResetTimestampForTextureParameters);
3991 uint32_t levelMask = (1 << numMipLevels) - 1;
3992 bool result = this->uploadColorToTex(glFormat,
3999 this->bindTextureToScratchUnit(
info.fTarget, 0);
4016 desc, programInfo, &stat);
4024#if defined(GR_TEST_UTILS)
4026bool GrGLGpu::isTestingOnlyBackendTexture(
const GrBackendTexture& tex)
const {
4044 if (dimensions.
width() > this->caps()->maxRenderTargetSize() ||
4045 dimensions.
height() > this->caps()->maxRenderTargetSize()) {
4048 if (isProtected == GrProtected::kYes && !this->
glCaps().supportsProtectedContent()) {
4061 bool useTexture =
false;
4062 if (sampleCnt > 1 && !this->
glCaps().usesMSAARenderBuffers()) {
4069 if (sampleCnt > 1) {
4074 int sFormatIdx = this->getCompatibleStencilIndex(
format);
4075 if (sFormatIdx < 0) {
4083 info.fProtected = isProtected;
4085 auto deleteIDs = [&](
bool saveFBO =
false) {
4088 GL_CALL(DeleteTextures(1, &colorID));
4090 GL_CALL(DeleteRenderbuffers(1, &colorID));
4094 GL_CALL(DeleteRenderbuffers(1, &stencilID));
4096 if (!saveFBO &&
info.fFBOID) {
4102 GL_CALL(GenTextures(1, &colorID));
4104 GL_CALL(GenRenderbuffers(1, &colorID));
4106 GL_CALL(GenRenderbuffers(1, &stencilID));
4107 if (!stencilID || !colorID) {
4132 if (sampleCnt == 1) {
4142 if (sampleCnt == 1) {
4146 if (!this->renderbufferStorageMSAA(this->
glContext(), sampleCnt, renderBufferFormat,
4157 if (sampleCnt == 1) {
4161 if (!this->renderbufferStorageMSAA(this->
glContext(), sampleCnt,
4193 dimensions.
width(), dimensions.
height(), sampleCnt, stencilBits,
info);
4217 if (!fCoreProfileVertexArray) {
4224 attribState = fCoreProfileVertexArray->bindWithIndexBuffer(gpu, ibuf);
4226 attribState = fCoreProfileVertexArray->bind(gpu);
4233 this->setVertexArrayID(gpu, 0);
4236 if (fDefaultVertexArrayAttribState.count() != attrCount) {
4237 fDefaultVertexArrayAttribState.resize(attrCount);
4239 attribState = &fDefaultVertexArrayAttribState;
4246 fFinishCallbacks.
add(finishedProc, finishedContext);
4249void GrGLGpu::flush(
FlushType flushType) {
4250 if (fNeedsGLFlush || flushType == FlushType::kForce) {
4252 fNeedsGLFlush =
false;
4258 (!fFinishCallbacks.
empty() && !this->glCaps().fenceSyncSupport())) {
4260 fFinishCallbacks.
callAll(
true);
4264 fFinishCallbacks.
check();
4266 if (!this->
glCaps().skipErrorChecks()) {
4275 if (fStagingBufferManager) {
4276 fStagingBufferManager->detachBuffers();
4282 SkASSERT(fCachedOpsRenderPass.get() == renderPass);
4283 fCachedOpsRenderPass->reset();
4287 if (!this->
glCaps().fenceSyncSupport()) {
4294 GL_CALL(GenFences(1, &fence));
4296 sync =
reinterpret_cast<GrGLsync>(
static_cast<intptr_t
>(fence));
4300 this->setNeedsFlush();
4304bool GrGLGpu::waitSync(
GrGLsync sync, uint64_t timeout,
bool flush) {
4306 GrGLuint nvFence =
static_cast<GrGLuint>(
reinterpret_cast<intptr_t
>(sync));
4309 this->flush(FlushType::kForce);
4318 GL_CALL(FinishFence(nvFence));
4329 if (!this->
glCaps().fenceSyncSupport()) {
4332 return this->waitSync(fence, 0,
false);
4336 if (this->
glCaps().fenceSyncSupport()) {
4359 this->setNeedsFlush();
4370 fFinishCallbacks.
check();
4382#if GR_GL_CHECK_ERROR
4387 GrGLenum error = this->fGLContext->glInterface()->fFunctions.fGetError();
4397 GL_CALL(DeleteFences(1, &nvFence));
4405 std::unique_ptr<GrSemaphore> semaphore = this->
makeSemaphore(
true);
4409 this->flush(FlushType::kForce);
4423 SK_ABORT(
"Unexpected samper type");
4427#ifdef SK_ENABLE_DUMP_GPU
4442 writer->
appendCString(
"GL_SHADING_LANGUAGE_VERSION", (
const char*)(str));
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
int GrBackendFormatStencilBits(const GrBackendFormat &format)
bool GrClearImage(const GrImageInfo &dstInfo, void *dst, size_t dstRB, std::array< float, 4 > color)
#define GL_ALLOC_CALL(call)
#define GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM
#define GR_GL_OUT_OF_MEMORY
#define GR_GL_ONE_MINUS_SRC1_COLOR
#define GR_GL_TRIANGLE_STRIP
#define GR_GL_TEXTURE_MAX_LOD
#define GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM
#define GR_GL_COLOR_TABLE
#define GR_GL_UNPACK_ROW_LENGTH
#define GR_GL_NEAREST_MIPMAP_LINEAR
#define GR_GL_IMPLEMENTATION_COLOR_READ_TYPE
#define GR_GL_FRONT_AND_BACK
#define GR_GL_ONE_MINUS_SRC1_ALPHA
#define GR_GL_PIXEL_PACK_BUFFER
#define GR_GL_POINT_SMOOTH
#define GR_GL_POLYGON_STIPPLE
#define GR_GL_DRAW_FRAMEBUFFER
#define GR_GL_POLYGON_SMOOTH
#define GR_GL_LINEAR_MIPMAP_NEAREST
#define GR_GL_TEXTURE_BASE_LEVEL
#define GR_GL_TIMEOUT_IGNORED
#define GR_GL_MULTISAMPLE
#define GR_GL_COLOR_LOGIC_OP
#define GR_GL_CLAMP_TO_EDGE
#define GR_GL_READ_FRAMEBUFFER
#define GR_GL_TEXTURE_MAX_ANISOTROPY
#define GR_GL_DRAW_INDIRECT_BUFFER
#define GR_GL_TEXTURE_SWIZZLE_B
#define GR_GL_ALL_COMPLETED
#define GR_GL_ONE_MINUS_DST_ALPHA
#define GR_GL_TEXTURE_WRAP_T
#define GR_GL_LINE_SMOOTH
#define GR_GL_HSL_SATURATION
#define GR_GL_STENCIL_BUFFER_BIT
#define GR_GL_TEXTURE_USAGE
#define GR_GL_ELEMENT_ARRAY_BUFFER
#define GR_GL_INDEX_LOGIC_OP
#define GR_GL_TEXTURE_MAG_FILTER
#define GR_GL_POLYGON_OFFSET_FILL
#define GR_GL_PACK_ROW_LENGTH
#define GR_GL_ALREADY_SIGNALED
#define GR_GL_TEXTURE_SWIZZLE_RGBA
#define GR_GL_CONSTANT_COLOR
#define GR_GL_SHADING_LANGUAGE_VERSION
#define GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT
#define GR_GL_RENDERBUFFER
#define GR_GL_FUNC_REVERSE_SUBTRACT
#define GR_GL_FRAMEBUFFER_ATTACHMENT
#define GR_GL_FRAGMENT_SHADER
#define GR_GL_ONE_MINUS_CONSTANT_COLOR
#define GR_GL_TEXTURE_SWIZZLE_A
#define GR_GL_UNPACK_ALIGNMENT
#define GR_GL_STENCIL_ATTACHMENT
#define GR_GL_NEAREST_MIPMAP_NEAREST
#define GR_GL_LINEAR_MIPMAP_LINEAR
#define GR_GL_STENCIL_TEST
#define GR_GL_DEPTH_ATTACHMENT
#define GR_GL_ONE_MINUS_DST_COLOR
#define GR_GL_FRAMEBUFFER_COMPLETE
#define GR_GL_VERTEX_PROGRAM_POINT_SIZE
#define GR_GL_TEXTURE_PROTECTED_EXT
#define GR_GL_TEXTURE_RECTANGLE
#define GR_GL_SCISSOR_TEST
#define GR_GL_TEXTURE_BORDER_COLOR
#define GR_GL_PIXEL_UNPACK_BUFFER
#define GR_GL_TEXTURE_WRAP_S
#define GR_GL_FUNC_SUBTRACT
#define GR_GL_TEXTURE_MIN_LOD
#define GR_GL_CLAMP_TO_BORDER
#define GR_GL_COLOR_BUFFER_BIT
#define GR_GL_FETCH_PER_SAMPLE
#define GR_GL_TEXTURE_SWIZZLE_R
#define GR_GL_SYNC_FLUSH_COMMANDS_BIT
#define GR_GL_TEXTURE_MAX_LEVEL
#define GR_GL_VERTEX_SHADER
#define GR_GL_CONDITION_SATISFIED
#define GR_GL_FRAMEBUFFER_SRGB
#define GR_GL_COLOR_BUFFER_BIT0
#define GR_GL_TEXTURE_SWIZZLE_G
#define GR_GL_ARRAY_BUFFER
#define GR_GL_ONE_MINUS_SRC_COLOR
#define GR_GL_MIRRORED_REPEAT
#define GR_GL_HSL_LUMINOSITY
#define GR_GL_SYNC_GPU_COMMANDS_COMPLETE
#define GR_GL_TEXTURE_EXTERNAL
#define GR_GL_TEXTURE_MIN_FILTER
#define GR_GL_ONE_MINUS_SRC_ALPHA
#define GR_GL_PACK_ALIGNMENT
#define GR_GL_CONSERVATIVE_RASTERIZATION
#define GR_GL_PACK_REVERSE_ROW_ORDER
#define GR_GL_FRAMEBUFFER
#define GR_GL_COLOR_ATTACHMENT0
static bool check_compressed_backend_texture(const GrBackendTexture &backendTex, const GrGLCaps &caps, GrGLTexture::Desc *desc, bool skipRectTexSupportCheck=false)
static GrGLenum wrap_mode_to_gl_wrap(GrSamplerState::WrapMode wrapMode, const GrCaps &caps)
static sk_sp< GrTexture > return_null_texture()
static int gl_target_to_binding_index(GrGLenum target)
static sk_sp< GrGLTextureParameters > get_gl_texture_params(const GrBackendTexture &backendTex)
static const GrGLenum gXfermodeCoeff2Blend[]
static bool can_blit_framebuffer_for_copy_surface(const GrSurface *dst, const GrSurface *src, const SkIRect &srcRect, const SkIRect &dstRect, const GrGLCaps &caps)
static bool check_backend_texture(const GrBackendTexture &backendTex, const GrGLCaps &caps, GrGLTexture::Desc *desc, bool skipRectTexSupportCheck=false)
static void set_khr_debug_label(GrGLGpu *gpu, const GrGLuint id, std::string_view label)
static GrGLenum filter_to_gl_min_filter(GrSamplerState::Filter filter, GrSamplerState::MipmapMode mm)
static bool rt_has_msaa_render_buffer(const GrGLRenderTarget *rt, const GrGLCaps &glCaps)
static bool check_write_and_transfer_input(GrGLTexture *glTex)
static GrGLTextureParameters::SamplerOverriddenState set_initial_texture_params(const GrGLInterface *interface, const GrGLCaps &caps, GrGLenum target)
static const GrGLenum gXfermodeEquation2Blend[]
static void cleanup_program(GrGLGpu *gpu, GrGLuint *programID, GrGLuint *vshader, GrGLuint *fshader)
static bool can_copy_texsubimage(const GrSurface *dst, const GrSurface *src, const GrGLCaps &caps)
static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter)
static bool use_tiled_rendering(const GrGLCaps &glCaps, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
SK_API sk_sp< const GrGLInterface > GrGLMakeNativeInterface()
static void cleanup_program(GrGLGpu *gpu, GrGLuint programID, const SkTDArray< GrGLuint > &shaderIDs)
#define GL_CALL_RET(R, X)
bool GrGLCheckLinkStatus(const GrGLGpu *gpu, GrGLuint programID, bool shaderWasCached, GrContextOptions::ShaderErrorHandler *errorHandler, const std::string *sksl[kGrShaderTypeCount], const std::string glsl[kGrShaderTypeCount])
GrGLuint GrGLCompileAndAttachShader(const GrGLContext &glCtx, GrGLuint programId, GrGLenum type, const std::string &glsl, bool shaderWasCached, GrThreadSafePipelineBuilder::Stats *stats, GrContextOptions::ShaderErrorHandler *errorHandler)
unsigned char GrGLboolean
unsigned int GrGLbitfield
#define GR_IS_GR_GL(standard)
struct __GLsync * GrGLsync
#define GR_IS_GR_GL_ES(standard)
bool GrGLFormatIsCompressed(GrGLFormat format)
GrGLenum GrToGLStencilFunc(GrStencilTest test)
static constexpr int GrGLFormatStencilBits(GrGLFormat format)
static constexpr GrGLFormat GrGLFormatFromGLEnum(GrGLenum glFormat)
#define GR_GL_CALL(IFACE, X)
#define GR_GL_GetIntegerv(gl, e, p)
static constexpr GrGLenum GrGLFormatToEnum(GrGLFormat format)
static constexpr bool GrGLFormatIsPackedDepthStencil(GrGLFormat format)
static constexpr int kGrStencilOpCount
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
#define GrCapsDebugf(caps,...)
@ kBorrow_GrWrapOwnership
static const constexpr int kGrGpuBufferTypeCount
static constexpr bool GrIsPrimTypeLines(GrPrimitiveType type)
@ kStatic_GrAccessPattern
@ kFloat2_GrVertexAttribType
static const int kGrShaderTypeCount
@ kTopLeft_GrSurfaceOrigin
void * GrGpuFinishedContext
void(* GrGpuFinishedProc)(GrGpuFinishedContext finishedContext)
@ kProgram_GrGLBackendState
@ kTextureBinding_GrGLBackendState
@ kVertex_GrGLBackendState
@ kBlend_GrGLBackendState
@ kMSAAEnable_GrGLBackendState
@ kPixelStore_GrGLBackendState
@ kStencil_GrGLBackendState
@ kRenderTarget_GrGLBackendState
static SkSLType SkSLCombinedSamplerTypeForTextureType(GrTextureType type)
@ kTexture_GrXferBarrierType
@ kBlend_GrXferBarrierType
#define SkAssertResult(cond)
#define SK_ABORT(message,...)
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
constexpr float SK_FloatNaN
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
constexpr bool SkIsPow2(T value)
static bool contains(const SkRect &r, SkPoint p)
sk_sp< T > sk_ref_sp(T *obj)
#define RENDERENGINE_ABORTF(...)
@ kTextureExternalSampler
constexpr size_t SkToSizeT(S x)
constexpr int SkToInt(S x)
static constexpr bool SkToBool(const T &x)
constexpr unsigned SkToUInt(S x)
Type::kYUV Type::kRGBA() int(0.7 *637)
GrBackendFormat getBackendFormat() const
GrBackendApi backend() const
SkISize dimensions() const
static const GrBackendFormatData * GetBackendData(const GrBackendFormat &format)
SkISize dimensions() const
GrBackendFormat getBackendFormat() const
std::string_view getLabel() const
GrBackendApi backend() const
GrContextOptions::ShaderErrorHandler * getShaderErrorHandler() const
virtual bool isCpuBuffer() const =0
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
const GrShaderCaps * shaderCaps() const
bool anisoSupport() const
bool supportsProtectedContent() const
int maxVertexAttributes() const
maximum number of attribute values per vertex
bool clampToBorderSupport() const
@ kAdvanced_BlendEquationSupport
virtual bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const =0
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
bool writePixelsRowBytesSupport() const
GrDirectContextPriv priv()
static sk_sp< GrGLAttachment > MakeStencil(GrGLGpu *gpu, SkISize dimensions, int sampleCnt, GrGLFormat format)
static sk_sp< GrGLAttachment > MakeMSAA(GrGLGpu *gpu, SkISize dimensions, int sampleCnt, GrGLFormat format)
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)
static sk_sp< GrGLBuffer > Make(GrGLGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern)
GrGLuint bufferID() const
void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum *externalFormat, GrGLenum *externalType) const
GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const
@ kES_EXT_MsToTexture_MSFBOType
@ kES_IMG_MsToTexture_MSFBOType
bool isCoreProfile() const
void didQueryImplementationReadSupport(GrGLFormat format, GrGLenum readFormat, GrGLenum readType) const
float maxTextureMaxAnisotropy() const
MSFBOType msFBOType() const
void getTexSubImageExternalFormatAndType(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum *externalFormat, GrGLenum *externalType) const
bool usesMSAARenderBuffers() const
InvalidateFBType invalidateFBType() const
bool rectangleTextureSupport() const
Are textures with GL_TEXTURE_RECTANGLE type supported.
bool debugSupport() const
Is there support for GL_KHR_debug?
bool doManualMipmapping() const
bool framebufferResolvesMustBeFullSize() const
void getTexSubImageDefaultFormatTypeAndColorType(GrGLFormat format, GrGLenum *externalFormat, GrGLenum *externalType, GrColorType *colorType) const
GrGLFormat getFormatFromColorType(GrColorType colorType) const
int getStencilFormatIndexForFormat(GrGLFormat format) const
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
bool canCopyTexSubImage(GrGLFormat dstFormat, bool dstHasMSAARenderBuffer, const GrTextureType *dstTypeIfTexture, GrGLFormat srcFormat, bool srcHasMSAARenderBuffer, const GrTextureType *srcTypeIfTexture) const
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &format) const override
bool canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, const GrTextureType *dstTypeIfTexture, GrGLFormat srcFormat, int srcSampleCnt, const GrTextureType *srcTypeIfTexture, const SkRect &srcBounds, bool srcBoundsExact, const SkIRect &srcRect, const SkIRect &dstRect) const
bool tiledRenderingSupport() const
void getTexImageExternalFormatAndType(GrGLFormat surfaceFormat, GrGLenum *externalFormat, GrGLenum *externalType) const
@ kDiscard_InvalidateFBType
@ kInvalidate_InvalidateFBType
const skia_private::TArray< GrGLFormat, true > & stencilFormats() const
GrGLenum getTexImageOrStorageInternalFormat(GrGLFormat format) const
const GrGLCaps * caps() const
static std::unique_ptr< GrGLContext > Make(sk_sp< const GrGLInterface >, const GrContextOptions &)
void dumpJSON(SkJSONWriter *) const
void add(GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
void callAll(bool doDelete)
void invalidateBindings()
void bindSampler(int unitIdx, GrSamplerState state)
void unbindSampler(int unitIdx)
SamplerObjectCache(GrGLGpu *gpu)
GrGLStandard glStandard() const
void flushScissorRect(const SkIRect &scissor, int rtHeight, GrSurfaceOrigin)
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
const GrGLCaps & glCaps() const
void clear(const GrScissorState &, std::array< float, 4 > color, GrRenderTarget *, bool useMultisampleFBO, GrSurfaceOrigin)
void addFinishedProc(GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext) override
GrThreadSafePipelineBuilder * pipelineBuilder() override
void invalidateBoundRenderTarget()
void deleteSync(GrGLsync)
void bindVertexArray(GrGLuint id)
bool onUpdateCompressedBackendTexture(const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t length) override
void clearErrorsAndCheckForOOM()
GrOpsRenderPass * onGetOpsRenderPass(GrRenderTarget *, bool useMultisampleFBO, GrAttachment *, GrSurfaceOrigin, const SkIRect &, const GrOpsRenderPass::LoadAndStoreInfo &, const GrOpsRenderPass::StencilLoadAndStoreInfo &, const skia_private::TArray< GrSurfaceProxy *, true > &sampledProxies, GrXferBarrierFlags renderPassXferBarriers) override
void bindTexture(int unitIdx, GrSamplerState samplerState, const skgpu::Swizzle &, GrGLTexture *)
GrBackendTexture onCreateBackendTexture(SkISize dimensions, const GrBackendFormat &, GrRenderable, skgpu::Mipmapped, GrProtected, std::string_view label) override
void bindFramebuffer(GrGLenum fboTarget, GrGLuint fboid)
void deleteBackendTexture(const GrBackendTexture &) override
bool onTransferPixelsFrom(GrSurface *, SkIRect, GrColorType surfaceColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer >, size_t offset) override
bool onTransferPixelsTo(GrTexture *, SkIRect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer >, size_t offset, size_t rowBytes) override
sk_sp< GrTexture > onWrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable) override
sk_sp< GrAttachment > makeMSAAAttachment(SkISize dimensions, const GrBackendFormat &format, int numSamples, GrProtected isProtected, GrMemoryless) override
void clearStencilClip(const GrScissorState &, bool insideStencilMask, GrRenderTarget *, bool useMultisampleFBO, GrSurfaceOrigin)
bool onCopySurface(GrSurface *dst, const SkIRect &dstRect, GrSurface *src, const SkIRect &srcRect, GrSamplerState::Filter) override
bool onRegenerateMipMapLevels(GrTexture *) override
sk_sp< GrAttachment > makeStencilAttachment(const GrBackendFormat &colorFormat, SkISize dimensions, int numStencilSamples) override
GrGLenum prepareToDraw(GrPrimitiveType primitiveType)
const GrGLInterface * glInterface() const
sk_sp< GrRenderTarget > onWrapBackendRenderTarget(const GrBackendRenderTarget &) override
void flushProgram(sk_sp< GrGLProgram >)
sk_sp< GrTexture > onCreateTexture(SkISize dimensions, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, skgpu::Budgeted, GrProtected, int mipLevelCount, uint32_t levelClearMask, std::string_view label) override
bool onClearBackendTexture(const GrBackendTexture &, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color) override
void didDrawTo(GrRenderTarget *)
void onResolveRenderTarget(GrRenderTarget *target, const SkIRect &resolveRect) override
GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer *)
sk_sp< GrTexture > onWrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType) override
void deleteFramebuffer(GrGLuint fboid)
void finishOutstandingGpuWork() override
void resolveRenderFBOs(GrGLRenderTarget *, const SkIRect &resolveRect, ResolveDirection, bool invalidateReadBufferAfterBlit=false)
void beginCommandBuffer(GrGLRenderTarget *, bool useMultisampleFBO, const SkIRect &bounds, GrSurfaceOrigin, const GrOpsRenderPass::LoadAndStoreInfo &colorLoadStore, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
bool compile(const GrProgramDesc &, const GrProgramInfo &) override
void flushViewport(const SkIRect &viewport, int rtHeight, GrSurfaceOrigin)
void xferBarrier(GrRenderTarget *, GrXferBarrierType) override
bool flushGLState(GrRenderTarget *, bool useMultisampleFBO, const GrProgramInfo &)
void checkFinishProcs() override
void deleteFence(GrGLsync)
sk_sp< GrThreadSafePipelineBuilder > refPipelineBuilder() override
GrGLint fTexCoordXformUniform
void disconnect(DisconnectType) override
void onResetContext(uint32_t resetBits) override
std::unique_ptr< GrSemaphore > makeSemaphore(bool isOwned) override
std::unique_ptr< GrSemaphore > wrapBackendSemaphore(const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership) override
void insertSemaphore(GrSemaphore *semaphore) override
void endCommandBuffer(GrGLRenderTarget *, bool useMultisampleFBO, const GrOpsRenderPass::LoadAndStoreInfo &colorLoadStore, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
bool onTransferFromBufferToBuffer(sk_sp< GrGpuBuffer > src, size_t srcOffset, sk_sp< GrGpuBuffer > dst, size_t dstOffset, size_t size) override
std::unique_ptr< GrSemaphore > prepareTextureForCrossContextUsage(GrTexture *) override
void waitSemaphore(GrSemaphore *semaphore) override
void onResetTextureBindings() override
GrGLenum getErrorAndCheckForOOM()
void submit(GrOpsRenderPass *renderPass) override
sk_sp< GrTexture > onCreateCompressedTexture(SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, const void *data, size_t dataSize) override
const GrGLContextInfo & ctxInfo() const
bool onSubmitToGpu(GrSyncCpu sync) override
GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, const GrBackendFormat &, skgpu::Mipmapped, GrProtected) override
sk_sp< GrGpuBuffer > onCreateBuffer(size_t size, GrGpuBufferType, GrAccessPattern) override
void willExecute() override
sk_sp< GrTexture > onWrapCompressedBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable) override
static std::unique_ptr< GrGpu > Make(sk_sp< const GrGLInterface >, const GrContextOptions &, GrDirectContext *)
const GrGLContext & glContext() const
void updateUniforms(const GrRenderTarget *, const GrProgramInfo &)
void bindForPixelOps(GrGLenum fboTarget)
bool glRTFBOIDis0() const
void bindForResolve(ResolveDirection)
void bind(bool useMultisampleFBO)
bool isFBO0(bool multisample) const
static sk_sp< GrGLRenderTarget > MakeWrapped(GrGLGpu *, const SkISize &, GrGLFormat, int sampleCount, const IDs &, int stencilBits, skgpu::Protected, std::string_view label)
GrGLFormat format() const
static std::unique_ptr< GrGLSemaphore > Make(GrGLGpu *gpu, bool isOwned)
void setSync(const GrGLsync &sync)
static sk_sp< GrGLTextureRenderTarget > MakeWrapped(GrGLGpu *gpu, int sampleCount, const GrGLTexture::Desc &, sk_sp< GrGLTextureParameters >, const GrGLRenderTarget::IDs &, GrWrapCacheable, GrMipmapStatus, std::string_view label)
GrGLuint textureID() const
GrGLFormat format() const
static sk_sp< GrGLTexture > MakeWrapped(GrGLGpu *, GrMipmapStatus, const Desc &, sk_sp< GrGLTextureParameters >, GrWrapCacheable, GrIOType, std::string_view label)
size_t size() const final
bool updateData(const void *src, size_t offset, size_t size, bool preserve)
UniqueID uniqueID() const
void incStencilAttachmentCreates()
const GrCaps * caps() const
GrDirectContext * getContext()
void didWriteToSurface(GrSurface *surface, GrSurfaceOrigin origin, const SkIRect *bounds, uint32_t mipLevels=1) const
bool checkAndResetOOMed()
virtual void disconnect(DisconnectType)
void initCaps(sk_sp< const GrCaps > caps)
void handleDirtyContext()
const skgpu::Swizzle & writeSwizzle() const
bool hasStencilClip() const
bool isScissorTestEnabled() const
bool usesConservativeRaster() const
const GrWindowRectsState & getWindowRectsState() const
const GrXferProcessor & getXferProcessor() const
GrSurfaceOrigin origin() const
const GrPipeline & pipeline() const
const GrUserStencilSettings * userStencilSettings() const
bool isStencilEnabled() const
bool requiresManualMSAAResolve() const
GrAttachment * getStencilAttachment(bool useMSAASurface) const
int numStencilBits(bool useMSAASurface) const
constexpr skgpu::Mipmapped mipmapped() const
constexpr WrapMode wrapModeX() const
constexpr Filter filter() const
constexpr bool isRepeatedX() const
constexpr MipmapMode mipmapMode() const
constexpr bool isRepeatedY() const
constexpr WrapMode wrapModeY() const
bool set(const SkIRect &rect)
const SkIRect & rect() const
void addModifier(const char *modifier)
void setTypeModifier(TypeModifier type)
void appendDecl(const GrShaderCaps *, SkString *out) const
void reset(const GrUserStencilSettings &, bool hasStencilClip, int numStencilBits)
const Face & postOriginCCWFace(GrSurfaceOrigin origin) const
const Face & singleSidedFace() const
const Face & postOriginCWFace(GrSurfaceOrigin origin) const
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
virtual GrTexture * asTexture()
GrTextureType textureType() const
const SkIRect * data() const
static constexpr int kMaxWindows
const GrWindowRectangles & windows() const
skgpu::BlendInfo getBlendInfo() const
void beginObject(const char *name=nullptr, bool multiline=true)
void appendName(const char *name)
void appendCString(const char *value)
V * insert(const K &key, V value)
static int ComputeLevelCount(int baseWidth, int baseHeight)
void append(const char text[])
const char * c_str() const
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
void reset(T *ptr=nullptr)
constexpr std::array< float, 4 > applyTo(std::array< float, 4 > color) const
static constexpr Swizzle RGBA()
void reset(size_t count=0)
void resize(size_t count)
static constexpr int kSize
const EmbeddedViewParams * params
FlutterSemanticsFlag flags
FlPixelBufferTexturePrivate * priv
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
SK_API bool GetGLFramebufferInfo(const GrBackendRenderTarget &, GrGLFramebufferInfo *)
SK_API GrBackendTexture MakeGL(int width, int height, skgpu::Mipmapped, const GrGLTextureInfo &glInfo, std::string_view label={})
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)
sk_sp< SkBlender > blender SkRect rect
static constexpr bool BlendCoeffRefsConstant(const BlendCoeff coeff)
static constexpr bool BlendEquationIsAdvanced(BlendEquation equation)
static constexpr bool BlendShouldDisable(BlendEquation equation, BlendCoeff srcCoeff, BlendCoeff dstCoeff)
static const int kBlendEquationCnt
bool SkSLToGLSL(const SkSL::ShaderCaps *caps, const std::string &sksl, SkSL::ProgramKind programKind, const SkSL::ProgramSettings &settings, std::string *glsl, SkSL::ProgramInterface *outInterface, ShaderErrorHandler *errorHandler)
static constexpr bool BlendCoeffRefsSrc2(const BlendCoeff coeff)
GrGLExtensions fExtensions
int fTotalMemorySamplesPerPixel
GrGLuint fMultisampleFBOID
GrBackendObjectOwnership fRTFBOOwnership
GrGLuint fSingleSampleFBOID
GrGLuint fMSColorRenderbufferID
skgpu::Protected fIsProtected
GrBackendObjectOwnership fOwnership
const int * asInts() const
void setRelativeTo(GrSurfaceOrigin org, int rtHeight, const SkIRect &devRect)
static GrNativeRect MakeRelativeTo(GrSurfaceOrigin origin, int rtHeight, SkIRect devRect)
std::array< float, 4 > fClearColor
const char * noperspectiveInterpolationExtensionString() const
constexpr int32_t x() const
constexpr int32_t y() const
static bool Intersects(const SkIRect &a, const SkIRect &b)
int32_t fBottom
larger y-axis bounds
constexpr SkISize size() const
constexpr int32_t height() const
int32_t fTop
smaller y-axis bounds
static constexpr SkIRect MakeSize(const SkISize &size)
constexpr int32_t width() const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
constexpr SkIPoint topLeft() const
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
int32_t fLeft
smaller x-axis bounds
bool contains(int32_t x, int32_t y) const
int32_t fRight
larger x-axis bounds
constexpr int32_t width() const
constexpr int32_t height() const
bool fExternalTextureSupport
bool fNoPerspectiveInterpolationSupport
skgpu::BlendCoeff fDstBlend
SkPMColor4f fBlendConstant
skgpu::BlendCoeff fSrcBlend
#define TRACE_EVENT0(category_group, name)