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 | |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 11 | SK_DEFINE_INST_COUNT(GrGLTexID) |
| 12 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 13 | #define GPUGL static_cast<GrGpuGL*>(getGpu()) |
| 14 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 15 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
| 16 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 17 | void GrGLTexture::init(GrGpuGL* gpu, |
| 18 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 19 | const GrGLRenderTarget::Desc* rtDesc) { |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 20 | |
| 21 | GrAssert(0 != textureDesc.fTextureID); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 23 | fTexParams.invalidate(); |
| 24 | fTexParamsTimestamp = GrGpu::kExpiredTimestamp; |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 25 | fTexIDObj = SkNEW_ARGS(GrGLTexID, |
| 26 | (GPUGL->glInterface(), |
| 27 | textureDesc.fTextureID, |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 28 | textureDesc.fIsWrapped)); |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 29 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 30 | if (NULL != rtDesc) { |
robertphillips@google.com | cf9faf6 | 2013-02-05 14:05:06 +0000 | [diff] [blame^] | 31 | GrAssert(kBottomLeft_GrSurfaceOrigin == textureDesc.fOrigin); |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 32 | GrGLIRect vp; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | vp.fLeft = 0; |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 34 | vp.fWidth = textureDesc.fWidth; |
| 35 | vp.fBottom = 0; |
| 36 | vp.fHeight = textureDesc.fHeight; |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 37 | |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 38 | fRenderTarget = SkNEW_ARGS(GrGLRenderTarget, |
| 39 | (gpu, *rtDesc, vp, fTexIDObj, this)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | } |
| 42 | |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 43 | GrGLTexture::GrGLTexture(GrGpuGL* gpu, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 44 | const Desc& textureDesc) |
robertphillips@google.com | cf9faf6 | 2013-02-05 14:05:06 +0000 | [diff] [blame^] | 45 | : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc, textureDesc.fOrigin) { |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 46 | this->init(gpu, textureDesc, NULL); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | GrGLTexture::GrGLTexture(GrGpuGL* gpu, |
| 50 | const Desc& textureDesc, |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 51 | const GrGLRenderTarget::Desc& rtDesc) |
robertphillips@google.com | cf9faf6 | 2013-02-05 14:05:06 +0000 | [diff] [blame^] | 52 | : INHERITED(gpu, textureDesc.fIsWrapped, textureDesc, textureDesc.fOrigin) { |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 53 | this->init(gpu, textureDesc, &rtDesc); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 54 | } |
| 55 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 56 | void GrGLTexture::onRelease() { |
Scroggo | c29d7cd | 2011-06-16 13:14:21 +0000 | [diff] [blame] | 57 | GPUGL->notifyTextureDelete(this); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 58 | if (NULL != fTexIDObj) { |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 59 | fTexIDObj->unref(); |
| 60 | fTexIDObj = NULL; |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 61 | } |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 62 | |
| 63 | INHERITED::onRelease(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 64 | } |
| 65 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 66 | void GrGLTexture::onAbandon() { |
| 67 | if (NULL != fTexIDObj) { |
| 68 | fTexIDObj->abandon(); |
| 69 | } |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 70 | |
| 71 | INHERITED::onAbandon(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | } |
| 73 | |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 74 | GrBackendObject GrGLTexture::getTextureHandle() const { |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 75 | return fTexIDObj->id(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 76 | } |