Chromium Code Reviews| Index: src/gpu/gl/GrGLGpu.cpp |
| diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp |
| index 76cb1a068a2bc3dee7ae2df28bc167d1eda2aad9..f784698d1349a86c21fca6cb9c1216bf377d5c5e 100644 |
| --- a/src/gpu/gl/GrGLGpu.cpp |
| +++ b/src/gpu/gl/GrGLGpu.cpp |
| @@ -6,6 +6,7 @@ |
| */ |
| #include "GrGLGpu.h" |
| +#include "GrContext.h" |
| #include "GrGLGLSL.h" |
| #include "GrGLStencilAttachment.h" |
| #include "GrGLTextureRenderTarget.h" |
| @@ -14,6 +15,7 @@ |
| #include "GrPipeline.h" |
| #include "GrPLSGeometryProcessor.h" |
| #include "GrRenderTargetPriv.h" |
| +#include "GrResourceProvider.h" |
| #include "GrSurfacePriv.h" |
| #include "GrTexturePriv.h" |
| #include "GrTypes.h" |
| @@ -594,10 +596,10 @@ GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, |
| switch (ownership) { |
| case kAdopt_GrWrapOwnership: |
| - idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
| + idDesc.fLifeCycle = GrBackendObjectLifeCycle::kAdopted; |
| break; |
| case kBorrow_GrWrapOwnership: |
| - idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
| + idDesc.fLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| break; |
| } |
| @@ -619,13 +621,13 @@ GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, |
| GrGLTexture* texture = nullptr; |
| if (renderTarget) { |
| GrGLRenderTarget::IDDesc rtIDDesc; |
| - if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_LifeCycle, |
| - idDesc.fInfo, &rtIDDesc)) { |
| + if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, |
| + GrBackendObjectLifeCycle::kBorrowed, &rtIDDesc)) { |
| return nullptr; |
| } |
| - texture = new GrGLTextureRenderTarget(this, surfDesc, idDesc, rtIDDesc); |
| + texture = new GrGLTextureRenderTarget(this, SkBudgeted::kNo, surfDesc, idDesc, rtIDDesc); |
| } else { |
| - texture = new GrGLTexture(this, surfDesc, idDesc); |
| + texture = new GrGLTexture(this, SkBudgeted::kNo, surfDesc, idDesc); |
| } |
| if (nullptr == texture) { |
| return nullptr; |
| @@ -638,14 +640,12 @@ GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe |
| GrWrapOwnership ownership) { |
| GrGLRenderTarget::IDDesc idDesc; |
| idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); |
| - idDesc.fMSColorRenderbufferID = 0; |
| - idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| switch (ownership) { |
| case kAdopt_GrWrapOwnership: |
| - idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
| + idDesc.fRTFBOLifeCycle = GrBackendObjectLifeCycle::kAdopted; |
| break; |
| case kBorrow_GrWrapOwnership: |
| - idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
| + idDesc.fRTFBOLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| break; |
| } |
| idDesc.fSampleConfig = GrRenderTarget::kUnified_SampleConfig; |
| @@ -658,50 +658,70 @@ GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe |
| desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()); |
| desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
| - return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencilBits); |
| + return GrGLRenderTarget::CreateWrapped(this, SkBudgeted::kNo, desc, idDesc, wrapDesc.fStencilBits); |
| } |
| GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc, |
| GrWrapOwnership ownership) { |
|
Kimmo Kinnunen
2016/03/18 20:02:19
This is the implementation.
|
| + // NOTE: the potential backing color renderbuffer is not initialized with |
| + // the backend texture contents, so blended rendering and pixel reading might |
| + // not be correct, since wrapped render targets are not cleared. |
| + GrGLTextureInfo texInfo; |
| #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| if (!desc.fTextureHandle) { |
| return nullptr; |
| } |
| + texInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); |
| + // We only support GL_TEXTURE_2D at the moment. |
| + texInfo.fTarget = GR_GL_TEXTURE_2D; |
| #else |
| const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle); |
| if (!info || !info->fID) { |
| return nullptr; |
| } |
| + texInfo = *info; |
| #endif |
| - GrGLTexture::IDDesc idDesc; |
| - GrSurfaceDesc surfDesc; |
| - |
| -#ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| - idDesc.fInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); |
| - // We only support GL_TEXTURE_2D at the moment. |
| - idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; |
| -#else |
| - idDesc.fInfo = *info; |
| -#endif |
| - |
| - if (GR_GL_TEXTURE_RECTANGLE != idDesc.fInfo.fTarget && |
| - GR_GL_TEXTURE_2D != idDesc.fInfo.fTarget) { |
| + if (GR_GL_TEXTURE_RECTANGLE != texInfo.fTarget && |
| + GR_GL_TEXTURE_2D != texInfo.fTarget) { |
| // Only texture rectangle and texture 2d are supported. We do not check whether texture |
| // rectangle is supported by Skia - if the caller provided us with a texture rectangle, |
| // we assume the necessary support exists. |
| return nullptr; |
| } |
| + GrBackendObjectLifeCycle texLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| switch (ownership) { |
| case kAdopt_GrWrapOwnership: |
| - idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
| + texLifeCycle = GrBackendObjectLifeCycle::kAdopted; |
| break; |
| case kBorrow_GrWrapOwnership: |
| - idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
| + texLifeCycle = GrBackendObjectLifeCycle::kBorrowed; |
| break; |
| } |
| + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| + GrUniqueKey key; |
| + GrUniqueKey::Builder builder(&key, kDomain, 3); |
| + builder[0] = desc.fWidth; |
| + builder[1] = desc.fHeight; |
| + builder[2] = desc.fConfig | (desc.fFlags << 5) | (desc.fSampleCnt << 6) | (desc.fOrigin << 14) |
| + | (ownership << 15) | ((texInfo.fTarget == GR_GL_TEXTURE_2D) << 17); |
| + builder.finish(); |
| + |
| + GrGLRenderTarget *rt = static_cast<GrGLRenderTarget*>( |
| + getContext()->resourceProvider()->findAndRefRenderTargetByUniqueKey(key)); |
| + if (rt) { |
| + fStats.incRenderTargetBinds(); |
| + GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->textureFBOID())); |
| + GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| + GR_GL_COLOR_ATTACHMENT0, |
| + texInfo.fTarget, |
| + texInfo.fID, 0)); |
| + return rt; |
| + } |
| + |
| + GrSurfaceDesc surfDesc; |
| surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
| surfDesc.fWidth = desc.fWidth; |
| surfDesc.fHeight = desc.fHeight; |
| @@ -718,11 +738,12 @@ GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu |
| } |
| GrGLRenderTarget::IDDesc rtIDDesc; |
| - if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_LifeCycle, |
| - idDesc.fInfo, &rtIDDesc)) { |
| + if (!this->createRenderTargetObjects(surfDesc, texInfo, texLifeCycle, &rtIDDesc)) { |
| return nullptr; |
| } |
| - return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0); |
| + rt = GrGLRenderTarget::CreateWrapped(this, SkBudgeted::kYes, surfDesc, rtIDDesc, 0); |
| + rt->resourcePriv().setUniqueKey(key); |
| + return rt; |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -1436,17 +1457,15 @@ static bool renderbuffer_storage_msaa(const GrGLContext& ctx, |
| } |
| bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, |
| - GrGpuResource::LifeCycle lifeCycle, |
| const GrGLTextureInfo& texInfo, |
| + GrBackendObjectLifeCycle texLifeCycle, |
| GrGLRenderTarget::IDDesc* idDesc) { |
| - idDesc->fMSColorRenderbufferID = 0; |
| - idDesc->fRTFBOID = 0; |
| - idDesc->fTexFBOID = 0; |
| - idDesc->fLifeCycle = lifeCycle; |
| idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps().msFBOType() && |
| desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_SampleConfig : |
| GrRenderTarget::kUnified_SampleConfig; |
| - |
| + idDesc->fTexID = texInfo.fID; |
| + idDesc->fTexLifeCycle = texLifeCycle; |
| + idDesc->fRTFBOLifeCycle = GrBackendObjectLifeCycle::kInternal; |
| GrGLenum status; |
| GrGLenum colorRenderbufferFormat = 0; // suppress warning |
| @@ -1554,12 +1573,11 @@ static size_t as_size_t(int x) { |
| } |
| #endif |
| -static GrGLTexture::IDDesc generate_gl_texture(const GrGLInterface* interface, |
| - GrGpuResource::LifeCycle lifeCycle) { |
| +static GrGLTexture::IDDesc generate_gl_texture(const GrGLInterface* interface) { |
| GrGLTexture::IDDesc idDesc; |
| idDesc.fInfo.fID = 0; |
| GR_GL_CALL(interface, GenTextures(1, &idDesc.fInfo.fID)); |
| - idDesc.fLifeCycle = lifeCycle; |
| + idDesc.fLifeCycle = GrBackendObjectLifeCycle::kInternal; |
| // When we create the texture, we only |
| // create GL_TEXTURE_2D at the moment. |
| // External clients can do something different. |
| @@ -1594,7 +1612,7 @@ static void set_initial_texture_params(const GrGLInterface* interface, |
| } |
| GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
| - GrGpuResource::LifeCycle lifeCycle, |
| + SkBudgeted budgeted, |
| const SkTArray<GrMipLevel>& texels) { |
| // We fail if the MSAA was requested and is not available. |
| if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) { |
| @@ -1605,7 +1623,7 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
| bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| GrGLTexture::IDDesc idDesc; |
| - idDesc.fLifeCycle = lifeCycle; |
| + idDesc.fLifeCycle = GrBackendObjectLifeCycle::kInternal; |
| GrGLTexture::TexParams initialTexParams; |
| if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, &initialTexParams, texels)) { |
| return return_null_texture(); |
| @@ -1617,17 +1635,18 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
| GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); |
| GrGLRenderTarget::IDDesc rtIDDesc; |
| - if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtIDDesc)) { |
| + if (!this->createRenderTargetObjects(desc, idDesc.fInfo, |
| + GrBackendObjectLifeCycle::kBorrowed, &rtIDDesc)) { |
| GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
| return return_null_texture(); |
| } |
| - tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc); |
| + tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc); |
| } else { |
| bool wasMipMapDataProvided = false; |
| if (texels.count() > 1) { |
| wasMipMapDataProvided = true; |
| } |
| - tex = new GrGLTexture(this, desc, idDesc, wasMipMapDataProvided); |
| + tex = new GrGLTexture(this, budgeted, desc, idDesc, wasMipMapDataProvided); |
| } |
| tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| #ifdef TRACE_TEXTURE_CREATION |
| @@ -1638,14 +1657,14 @@ GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
| } |
| GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| - GrGpuResource::LifeCycle lifeCycle, |
| + SkBudgeted budgeted, |
| const SkTArray<GrMipLevel>& texels) { |
| // Make sure that we're not flipping Y. |
| if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
| return return_null_texture(); |
| } |
| - GrGLTexture::IDDesc idDesc = generate_gl_texture(this->glInterface(), lifeCycle); |
| + GrGLTexture::IDDesc idDesc = generate_gl_texture(this->glInterface()); |
| if (!idDesc.fInfo.fID) { |
| return return_null_texture(); |
| } |
| @@ -1662,7 +1681,7 @@ GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| } |
| GrGLTexture* tex; |
| - tex = new GrGLTexture(this, desc, idDesc); |
| + tex = new GrGLTexture(this, budgeted, desc, idDesc); |
| tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| #ifdef TRACE_TEXTURE_CREATION |
| SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", |