| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrGLTexture.h" | 8 #include "GrGLTexture.h" |
| 9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
| 10 #include "SkTraceMemoryDump.h" | 10 #include "SkTraceMemoryDump.h" |
| 11 | 11 |
| 12 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | 12 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
| 13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 14 | 14 |
| 15 inline static GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrG
LGpu* gpu) { | 15 inline static GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrG
LGpu* gpu) { |
| 16 if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) { | 16 if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) { |
| 17 SkASSERT(gpu->glCaps().glslCaps()->externalTextureSupport()); | 17 SkASSERT(gpu->glCaps().glslCaps()->externalTextureSupport()); |
| 18 return kSamplerExternal_GrSLType; | 18 return kSamplerExternal_GrSLType; |
| 19 } else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) { | 19 } else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) { |
| 20 SkASSERT(gpu->glCaps().rectangleTextureSupport()); | 20 SkASSERT(gpu->glCaps().rectangleTextureSupport()); |
| 21 return kSampler2DRect_GrSLType; | 21 return kSampler2DRect_GrSLType; |
| 22 } else { | 22 } else { |
| 23 SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D); | 23 SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D); |
| 24 return kSampler2D_GrSLType; | 24 return kSampler2D_GrSLType; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. | 28 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. |
| 29 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc&
idDesc) | 29 GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc&
desc, |
| 30 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 30 const IDDesc& idDesc) |
| 31 , INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false)
{ | 31 : GrSurface(gpu, budgeted, desc) |
| 32 this->init(desc, idDesc); | 32 , INHERITED(gpu, budgeted, desc, sampler_type(idDesc, gpu), false) |
| 33 , fIDDesc(idDesc) { |
| 34 this->init(desc); |
| 35 this->initScratchKeyIfNeeded(); |
| 33 this->registerWithCache(); | 36 this->registerWithCache(); |
| 34 } | 37 } |
| 35 | 38 |
| 36 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc&
idDesc, | 39 GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc&
desc, |
| 37 bool wasMipMapDataProvided) | 40 const IDDesc& idDesc, bool wasMipMapDataProvided) |
| 38 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 41 : GrSurface(gpu, budgeted, desc) |
| 39 , INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), wasMipM
apDataProvided) { | 42 , INHERITED(gpu, budgeted, desc, sampler_type(idDesc, gpu), wasMipMapDataPro
vided) |
| 40 this->init(desc, idDesc); | 43 , fIDDesc(idDesc) { |
| 44 this->init(desc); |
| 45 this->initScratchKeyIfNeeded(); |
| 41 this->registerWithCache(); | 46 this->registerWithCache(); |
| 42 } | 47 } |
| 43 | 48 |
| 44 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc&
idDesc, Derived) | 49 GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc&
desc, |
| 45 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 50 const IDDesc& idDesc, Derived) |
| 46 , INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false)
{ | 51 : GrSurface(gpu, budgeted, desc) |
| 47 this->init(desc, idDesc); | 52 , INHERITED(gpu, budgeted, desc, sampler_type(idDesc, gpu), false) |
| 53 , fIDDesc(idDesc) { |
| 54 this->init(desc); |
| 55 this->initScratchKeyIfNeeded(); |
| 48 } | 56 } |
| 49 | 57 |
| 50 void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { | 58 void GrGLTexture::init(const GrSurfaceDesc& desc) { |
| 51 SkASSERT(0 != idDesc.fInfo.fID); | 59 SkASSERT(0 != fIDDesc.fInfo.fID); |
| 52 fTexParams.invalidate(); | 60 fTexParams.invalidate(); |
| 53 fTexParamsTimestamp = GrGpu::kExpiredTimestamp; | 61 fTexParamsTimestamp = GrGpu::kExpiredTimestamp; |
| 54 fInfo = idDesc.fInfo; | |
| 55 fTextureIDLifecycle = idDesc.fLifeCycle; | |
| 56 } | 62 } |
| 57 | 63 |
| 58 void GrGLTexture::onRelease() { | 64 void GrGLTexture::onRelease() { |
| 59 if (fInfo.fID) { | 65 if (fIDDesc.fInfo.fID) { |
| 60 if (GrGpuResource::kBorrowed_LifeCycle != fTextureIDLifecycle) { | 66 if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fLifeCycle) { |
| 61 if (this->desc().fTextureStorageAllocator.fDeallocateTextureStorage)
{ | 67 if (this->desc().fTextureStorageAllocator.fDeallocateTextureStorage)
{ |
| 62 this->desc().fTextureStorageAllocator.fDeallocateTextureStorage( | 68 this->desc().fTextureStorageAllocator.fDeallocateTextureStorage( |
| 63 this->desc().fTextureStorageAllocator.fCtx, | 69 this->desc().fTextureStorageAllocator.fCtx, |
| 64 reinterpret_cast<GrBackendObject>(&fInfo)); | 70 reinterpret_cast<GrBackendObject>(&fIDDesc.fInfo)); |
| 65 } else { | 71 } else { |
| 66 GL_CALL(DeleteTextures(1, &fInfo.fID)); | 72 GL_CALL(DeleteTextures(1, &fIDDesc.fInfo.fID)); |
| 67 } | 73 } |
| 68 } | 74 } |
| 69 fInfo.fID = 0; | 75 fIDDesc.fInfo.fID = 0; |
| 70 } | 76 } |
| 71 INHERITED::onRelease(); | 77 INHERITED::onRelease(); |
| 72 } | 78 } |
| 73 | 79 |
| 74 void GrGLTexture::onAbandon() { | 80 void GrGLTexture::onAbandon() { |
| 75 fInfo.fTarget = 0; | 81 fIDDesc.fInfo.fTarget = 0; |
| 76 fInfo.fID = 0; | 82 fIDDesc.fInfo.fID = 0; |
| 77 INHERITED::onAbandon(); | 83 INHERITED::onAbandon(); |
| 78 } | 84 } |
| 79 | 85 |
| 86 bool GrGLTexture::refsWrappedResources() const { |
| 87 return fIDDesc.fLifeCycle != GrBackendObjectLifeCycle::kInternal; |
| 88 } |
| 89 |
| 80 GrBackendObject GrGLTexture::getTextureHandle() const { | 90 GrBackendObject GrGLTexture::getTextureHandle() const { |
| 81 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 91 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| 82 return static_cast<GrBackendObject>(this->textureID()); | 92 return static_cast<GrBackendObject>(this->textureID()); |
| 83 #else | 93 #else |
| 84 return reinterpret_cast<GrBackendObject>(&fInfo); | 94 return reinterpret_cast<GrBackendObject>(&fIDDesc.fInfo); |
| 85 #endif | 95 #endif |
| 86 } | 96 } |
| 87 | 97 |
| 98 size_t GrGLTexture::onGpuMemorySize() const { |
| 99 if (GrBackendObjectLifeCycle::kBorrowed != fIDDesc.fLifeCycle) { |
| 100 return this->INHERITED::onGpuMemorySize(); |
| 101 } |
| 102 return 0; |
| 103 } |
| 88 void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, | 104 void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 89 const SkString& dumpName) const { | 105 const SkString& dumpName) const { |
| 90 SkString texture_id; | 106 SkString texture_id; |
| 91 texture_id.appendU32(this->textureID()); | 107 texture_id.appendU32(this->textureID()); |
| 92 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", | 108 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", |
| 93 texture_id.c_str()); | 109 texture_id.c_str()); |
| 94 } | 110 } |
| OLD | NEW |