reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #include "GrGLTexture.h" |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 9 | #include "GrGLGpu.h" |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 10 | #include "SkTraceMemoryDump.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 12 | #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 13 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 14 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 15 | // Because this class is virtually derived from GrSurface we must explicitly call its constructor. |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 16 | GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc) |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 17 | : GrSurface(gpu, idDesc.fLifeCycle, desc) |
| 18 | , INHERITED(gpu, idDesc.fLifeCycle, desc) { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 19 | this->init(desc, idDesc); |
| 20 | this->registerWithCache(); |
| 21 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 22 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 23 | GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived) |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 24 | : GrSurface(gpu, idDesc.fLifeCycle, desc) |
| 25 | , INHERITED(gpu, idDesc.fLifeCycle, desc) { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 26 | this->init(desc, idDesc); |
| 27 | } |
| 28 | |
| 29 | void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 30 | SkASSERT(0 != idDesc.fInfo.fID); |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 31 | fTexParams.invalidate(); |
| 32 | fTexParamsTimestamp = GrGpu::kExpiredTimestamp; |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 33 | fInfo = idDesc.fInfo; |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 34 | fTextureIDLifecycle = idDesc.fLifeCycle; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 35 | } |
| 36 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 37 | void GrGLTexture::onRelease() { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 38 | if (fInfo.fID) { |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 39 | if (GrGpuResource::kBorrowed_LifeCycle != fTextureIDLifecycle) { |
erikchen | 7fec91c | 2016-02-05 12:10:55 -0800 | [diff] [blame^] | 40 | if (this->desc().fTextureStorageAllocator.fDeallocateTextureStorage) { |
| 41 | this->desc().fTextureStorageAllocator.fDeallocateTextureStorage( |
| 42 | this->desc().fTextureStorageAllocator.fCtx, |
| 43 | reinterpret_cast<GrBackendObject>(&fInfo)); |
| 44 | } else { |
| 45 | GL_CALL(DeleteTextures(1, &fInfo.fID)); |
| 46 | } |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame] | 47 | } |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 48 | fInfo.fID = 0; |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame] | 49 | } |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 50 | INHERITED::onRelease(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 53 | void GrGLTexture::onAbandon() { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 54 | fInfo.fTarget = 0; |
| 55 | fInfo.fID = 0; |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 56 | INHERITED::onAbandon(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | } |
| 58 | |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 59 | GrBackendObject GrGLTexture::getTextureHandle() const { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 60 | #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 61 | return static_cast<GrBackendObject>(this->textureID()); |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 62 | #else |
| 63 | return reinterpret_cast<GrBackendObject>(&fInfo); |
| 64 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | } |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 66 | |
| 67 | void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 68 | const SkString& dumpName) const { |
| 69 | SkString texture_id; |
| 70 | texture_id.appendU32(this->textureID()); |
| 71 | traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", |
| 72 | texture_id.c_str()); |
| 73 | } |