blob: 864547ae26045ee043ec5187f2d9b52f30bec78a [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "GrGLTexture.h"
jvanverth39edf762014-12-22 11:44:19 -08009#include "GrGLGpu.h"
ericrk0a5fa482015-09-15 14:16:10 -070010#include "SkTraceMemoryDump.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000011
bsalomon861e1032014-12-16 07:33:49 -080012#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
bsalomon@google.com0b77d682011-08-19 13:28:54 +000013#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
14
bsalomon37dd3312014-11-03 08:47:23 -080015// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
bsalomon861e1032014-12-16 07:33:49 -080016GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
bsalomon5236cf42015-01-14 10:42:08 -080017 : GrSurface(gpu, idDesc.fLifeCycle, desc)
18 , INHERITED(gpu, idDesc.fLifeCycle, desc) {
bsalomon37dd3312014-11-03 08:47:23 -080019 this->init(desc, idDesc);
20 this->registerWithCache();
21}
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000022
bsalomon861e1032014-12-16 07:33:49 -080023GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived)
bsalomon5236cf42015-01-14 10:42:08 -080024 : GrSurface(gpu, idDesc.fLifeCycle, desc)
25 , INHERITED(gpu, idDesc.fLifeCycle, desc) {
bsalomon37dd3312014-11-03 08:47:23 -080026 this->init(desc, idDesc);
27}
28
29void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
bsalomon091f60c2015-11-10 11:54:56 -080030 SkASSERT(0 != idDesc.fInfo.fID);
bsalomon@google.com80d09b92011-11-05 21:21:13 +000031 fTexParams.invalidate();
32 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
bsalomon091f60c2015-11-10 11:54:56 -080033 fInfo = idDesc.fInfo;
bsalomon6dc6f5f2015-06-18 09:12:16 -070034 fTextureIDLifecycle = idDesc.fLifeCycle;
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000035}
36
bsalomon@google.com8fe72472011-03-30 21:26:44 +000037void GrGLTexture::onRelease() {
bsalomon091f60c2015-11-10 11:54:56 -080038 if (fInfo.fID) {
bsalomon6dc6f5f2015-06-18 09:12:16 -070039 if (GrGpuResource::kBorrowed_LifeCycle != fTextureIDLifecycle) {
erikchen7fec91c2016-02-05 12:10:55 -080040 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 }
bsalomonbcaefb02014-11-03 11:07:12 -080047 }
bsalomon091f60c2015-11-10 11:54:56 -080048 fInfo.fID = 0;
bsalomonbcaefb02014-11-03 11:07:12 -080049 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000050 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000051}
52
bsalomon@google.com8fe72472011-03-30 21:26:44 +000053void GrGLTexture::onAbandon() {
bsalomon091f60c2015-11-10 11:54:56 -080054 fInfo.fTarget = 0;
55 fInfo.fID = 0;
robertphillips@google.comd3645542012-09-05 18:37:39 +000056 INHERITED::onAbandon();
reed@google.comac10a2d2010-12-22 21:39:39 +000057}
58
bsalomon@google.com08afc842012-10-25 18:56:10 +000059GrBackendObject GrGLTexture::getTextureHandle() const {
bsalomon091f60c2015-11-10 11:54:56 -080060#ifdef SK_IGNORE_GL_TEXTURE_TARGET
commit-bot@chromium.org59e16e42013-07-17 21:39:58 +000061 return static_cast<GrBackendObject>(this->textureID());
bsalomon091f60c2015-11-10 11:54:56 -080062#else
63 return reinterpret_cast<GrBackendObject>(&fInfo);
64#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000065}
ericrk0a5fa482015-09-15 14:16:10 -070066
67void 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}