aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLTexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/gl/GrGLTexture.cpp')
-rw-r--r--src/gpu/gl/GrGLTexture.cpp77
1 files changed, 48 insertions, 29 deletions
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 2d674f4756..f0fafabcba 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -15,18 +15,30 @@
#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
-static inline GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, GrPixelConfig config,
- const GrGLGpu* gpu) {
- if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) {
- SkASSERT(gpu->caps()->shaderCaps()->externalTextureSupport());
- return kTextureExternalSampler_GrSLType;
- } else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) {
- SkASSERT(gpu->glCaps().rectangleTextureSupport());
- return kTexture2DRectSampler_GrSLType;
- } else {
- SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D);
- return kTexture2DSampler_GrSLType;
+static inline GrTextureType texture_type_from_target(GrGLenum target) {
+ switch (target) {
+ case GR_GL_TEXTURE_2D:
+ return GrTextureType::k2D;
+ case GR_GL_TEXTURE_RECTANGLE:
+ return GrTextureType::kRectangle;
+ case GR_GL_TEXTURE_EXTERNAL:
+ return GrTextureType::kExternal;
}
+ SK_ABORT("Unexpected texture target");
+ return GrTextureType::k2D;
+}
+
+static inline GrGLenum target_from_texture_type(GrTextureType type) {
+ switch (type) {
+ case GrTextureType::k2D:
+ return GR_GL_TEXTURE_2D;
+ case GrTextureType::kRectangle:
+ return GR_GL_TEXTURE_RECTANGLE;
+ case GrTextureType::kExternal:
+ return GR_GL_TEXTURE_EXTERNAL;
+ }
+ SK_ABORT("Unexpected texture type");
+ return GR_GL_TEXTURE_2D;
}
// This method parallels GrTextureProxy::highestFilterMode
@@ -42,27 +54,27 @@ static inline GrSamplerState::Filter highest_filter_mode(const GrGLTexture::IDDe
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
const IDDesc& idDesc, GrMipMapsStatus mipMapsStatus)
- : GrSurface(gpu, desc)
- , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
- highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
+ : GrSurface(gpu, desc)
+ , INHERITED(gpu, desc, texture_type_from_target(idDesc.fInfo.fTarget),
+ highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
this->init(desc, idDesc);
this->registerWithCache(budgeted);
}
GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc,
GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc)
- : GrSurface(gpu, desc)
- , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
- highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
+ : GrSurface(gpu, desc)
+ , INHERITED(gpu, desc, texture_type_from_target(idDesc.fInfo.fTarget),
+ highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
this->init(desc, idDesc);
this->registerWithCacheWrapped();
}
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
GrMipMapsStatus mipMapsStatus)
- : GrSurface(gpu, desc)
- , INHERITED(gpu, desc, sampler_type(idDesc, desc.fConfig, gpu),
- highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
+ : GrSurface(gpu, desc)
+ , INHERITED(gpu, desc, texture_type_from_target(idDesc.fInfo.fTarget),
+ highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
this->init(desc, idDesc);
}
@@ -75,30 +87,38 @@ void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
}
fTexParams.invalidate();
fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
- fInfo = idDesc.fInfo;
+ fID = idDesc.fInfo.fID;
+ fFormat = idDesc.fInfo.fFormat;
fTextureIDOwnership = idDesc.fOwnership;
}
+GrGLenum GrGLTexture::target() const {
+ return target_from_texture_type(this->texturePriv().textureType());
+}
+
void GrGLTexture::onRelease() {
- if (fInfo.fID) {
+ if (fID) {
if (GrBackendObjectOwnership::kBorrowed != fTextureIDOwnership) {
- GL_CALL(DeleteTextures(1, &fInfo.fID));
+ GL_CALL(DeleteTextures(1, &fID));
}
- fInfo.fID = 0;
+ fID = 0;
}
this->invokeReleaseProc();
INHERITED::onRelease();
}
void GrGLTexture::onAbandon() {
- fInfo.fTarget = 0;
- fInfo.fID = 0;
+ fID = 0;
this->invokeReleaseProc();
INHERITED::onAbandon();
}
GrBackendTexture GrGLTexture::getBackendTexture() const {
- return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), fInfo);
+ GrGLTextureInfo info;
+ info.fTarget = target_from_texture_type(this->texturePriv().textureType());
+ info.fID = fID;
+ info.fFormat = fFormat;
+ return GrBackendTexture(this->width(), this->height(), this->texturePriv().mipMapped(), info);
}
sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
@@ -108,8 +128,7 @@ sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& d
bool GrGLTexture::onStealBackendTexture(GrBackendTexture* backendTexture,
SkImage::BackendTextureReleaseProc* releaseProc) {
- *backendTexture = GrBackendTexture(this->width(), this->height(),
- this->texturePriv().mipMapped(), fInfo);
+ *backendTexture = this->getBackendTexture();
// Set the release proc to a no-op function. GL doesn't require any special cleanup.
*releaseProc = [](GrBackendTexture){};