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