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" |
Brian Osman | fe3b516 | 2017-03-02 15:09:20 -0500 | [diff] [blame] | 10 | #include "GrSemaphore.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 11 | #include "GrShaderCaps.h" |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 12 | #include "SkTraceMemoryDump.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 14 | #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
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 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 17 | static inline GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, GrPixelConfig config, |
| 18 | const GrGLGpu* gpu) { |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 19 | if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 20 | SkASSERT(gpu->caps()->shaderCaps()->externalTextureSupport()); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 21 | SkASSERT(!GrPixelConfigIsSint(config)); |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 22 | return kTextureExternalSampler_GrSLType; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 23 | } else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) { |
| 24 | SkASSERT(gpu->glCaps().rectangleTextureSupport()); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 25 | SkASSERT(!GrPixelConfigIsSint(config)); |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 26 | return kTexture2DRectSampler_GrSLType; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 27 | } else if (GrPixelConfigIsSint(config)) { |
Brian Salomon | a8f0002 | 2016-11-16 12:55:57 -0500 | [diff] [blame] | 28 | return kITexture2DSampler_GrSLType; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 29 | } else { |
| 30 | SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D); |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 31 | return kTexture2DSampler_GrSLType; |
cdalton | 9c3f143 | 2016-03-11 10:07:37 -0800 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
Robert Phillips | 18166ee | 2017-06-01 12:55:44 -0400 | [diff] [blame] | 35 | // This method parallels GrTextureProxy::highestFilterMode |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 36 | static inline GrSamplerParams::FilterMode highest_filter_mode(const GrGLTexture::IDDesc& idDesc, |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 37 | GrPixelConfig config) { |
| 38 | if (GrPixelConfigIsSint(config)) { |
| 39 | // Integer textures in GL can use GL_NEAREST_MIPMAP_NEAREST. This is a mode we don't support |
| 40 | // and don't currently have a use for. |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 41 | return GrSamplerParams::kNone_FilterMode; |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 42 | } |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 43 | if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE || |
| 44 | idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) { |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 45 | return GrSamplerParams::kBilerp_FilterMode; |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 46 | } |
Brian Salomon | 514baff | 2016-11-17 15:17:07 -0500 | [diff] [blame] | 47 | return GrSamplerParams::kMipMap_FilterMode; |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 48 | } |
| 49 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 50 | // Because this class is virtually derived from GrSurface we must explicitly call its constructor. |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 51 | GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
| 52 | const IDDesc& idDesc) |
| 53 | : GrSurface(gpu, desc) |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 54 | , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu), |
| 55 | highest_filter_mode(idDesc, desc.fConfig), false) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 56 | this->init(desc, idDesc); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 57 | this->registerWithCache(budgeted); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 58 | } |
| 59 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 60 | GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, |
| 61 | const IDDesc& idDesc, |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 62 | bool wasMipMapDataProvided) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 63 | : GrSurface(gpu, desc) |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 64 | , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu), |
| 65 | highest_filter_mode(idDesc, desc.fConfig), |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 66 | wasMipMapDataProvided) { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 67 | this->init(desc, idDesc); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 68 | this->registerWithCache(budgeted); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 69 | } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 70 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 71 | GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const IDDesc& idDesc) |
| 72 | : GrSurface(gpu, desc) |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 73 | , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu), |
| 74 | highest_filter_mode(idDesc, desc.fConfig), false) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 75 | this->init(desc, idDesc); |
| 76 | this->registerWithCacheWrapped(); |
| 77 | } |
| 78 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 79 | GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, |
| 80 | bool wasMipMapDataProvided) |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 81 | : GrSurface(gpu, desc) |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 82 | , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu), |
| 83 | highest_filter_mode(idDesc, desc.fConfig), |
Brian Salomon | 739c5bf | 2016-11-07 09:53:44 -0500 | [diff] [blame] | 84 | wasMipMapDataProvided) { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 85 | this->init(desc, idDesc); |
| 86 | } |
| 87 | |
| 88 | void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 89 | SkASSERT(0 != idDesc.fInfo.fID); |
bsalomon@google.com | 80d09b9 | 2011-11-05 21:21:13 +0000 | [diff] [blame] | 90 | fTexParams.invalidate(); |
| 91 | fTexParamsTimestamp = GrGpu::kExpiredTimestamp; |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 92 | fInfo = idDesc.fInfo; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 93 | fTextureIDOwnership = idDesc.fOwnership; |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 94 | } |
| 95 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 96 | void GrGLTexture::onRelease() { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 97 | if (fInfo.fID) { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 98 | if (GrBackendObjectOwnership::kBorrowed != fTextureIDOwnership) { |
bsalomon | 7e68ab7 | 2016-04-13 14:29:25 -0700 | [diff] [blame] | 99 | GL_CALL(DeleteTextures(1, &fInfo.fID)); |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame] | 100 | } |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 101 | fInfo.fID = 0; |
bsalomon | bcaefb0 | 2014-11-03 11:07:12 -0800 | [diff] [blame] | 102 | } |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 103 | this->invokeReleaseProc(); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 104 | INHERITED::onRelease(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | } |
| 106 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 107 | void GrGLTexture::onAbandon() { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 108 | fInfo.fTarget = 0; |
| 109 | fInfo.fID = 0; |
Greg Daniel | cef213c | 2017-04-21 11:52:27 -0400 | [diff] [blame] | 110 | this->invokeReleaseProc(); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 111 | INHERITED::onAbandon(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 112 | } |
| 113 | |
bsalomon@google.com | 08afc84 | 2012-10-25 18:56:10 +0000 | [diff] [blame] | 114 | GrBackendObject GrGLTexture::getTextureHandle() const { |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 115 | return reinterpret_cast<GrBackendObject>(&fInfo); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 116 | } |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 117 | |
| 118 | void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 119 | const SkString& dumpName) const { |
| 120 | SkString texture_id; |
| 121 | texture_id.appendU32(this->textureID()); |
| 122 | traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", |
| 123 | texture_id.c_str()); |
| 124 | } |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 125 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 126 | sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, |
| 127 | const IDDesc& idDesc) { |
| 128 | return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, idDesc)); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 129 | } |
| 130 | |