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" |
| 9 | #include "GrGpuGL.h" |
| 10 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 11 | #define GPUGL static_cast<GrGpuGL*>(this->getGpu()) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 12 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 13 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 14 | // Because this class is virtually derived from GrSurface we must explicitly call its constructor. |
| 15 | GrGLTexture::GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc) |
| 16 | : GrSurface(gpu, idDesc.fIsWrapped, desc) |
| 17 | , INHERITED(gpu, idDesc.fIsWrapped, desc) { |
| 18 | this->init(desc, idDesc); |
| 19 | this->registerWithCache(); |
| 20 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 21 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 22 | GrGLTexture::GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived) |
| 23 | : GrSurface(gpu, idDesc.fIsWrapped, desc) |
| 24 | , INHERITED(gpu, idDesc.fIsWrapped, desc) { |
| 25 | this->init(desc, idDesc); |
| 26 | } |
| 27 | |
| 28 | void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 29 | SkASSERT(0 != idDesc.fTextureID); |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 30 | fTexParams.invalidate(); |
| 31 | fTexParamsTimestamp = GrGpu::kExpiredTimestamp; |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame^] | 32 | fTextureID = idDesc.fTextureID; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 33 | } |
| 34 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 35 | void GrGLTexture::onRelease() { |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame^] | 36 | if (fTextureID) { |
| 37 | if (!this->isWrapped()) { |
| 38 | GL_CALL(DeleteTextures(1, &fTextureID)); |
| 39 | } |
| 40 | fTextureID = 0; |
| 41 | } |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 42 | INHERITED::onRelease(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | } |
| 44 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 45 | void GrGLTexture::onAbandon() { |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame^] | 46 | fTextureID = 0; |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 47 | INHERITED::onAbandon(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | } |
| 49 | |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 50 | GrBackendObject GrGLTexture::getTextureHandle() const { |
commit-bot@chromium.org | 59e16e4 | 2013-07-17 21:39:58 +0000 | [diff] [blame] | 51 | return static_cast<GrBackendObject>(this->textureID()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 52 | } |