aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLGpu.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-12-12 13:01:25 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-12 18:45:09 +0000
commitd21b2a5d5c5dca87b7df02713782e722a2c0ae92 (patch)
treed2f24173bbc6840e56f455d518b69ffc02e3c948 /src/gpu/gl/GrGLGpu.cpp
parentf3506fa87d0090bd01688e5d26f062fe2bdb801c (diff)
Remove GrBackendObject from tests (except image_from_yuv_textures)
This sets the stage for landing https://skia-review.googlesource.com/c/skia/+/82823 (Update SkImage::MakeFromYUVTexturesCopy to GrBackendTexture) Change-Id: I2c62f23dc447b9ad55c0b5f06bcd6d7ca0ec4d2b Reviewed-on: https://skia-review.googlesource.com/83920 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/gl/GrGLGpu.cpp')
-rw-r--r--src/gpu/gl/GrGLGpu.cpp99
1 files changed, 89 insertions, 10 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index ddb80b4b62..c114c6c2ed 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -4387,9 +4387,9 @@ void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) {
}
}
-GrBackendObject GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h,
- GrPixelConfig config, bool /*isRT*/,
- GrMipMapped mipMapped) {
+GrBackendObject GrGLGpu::createTestingOnlyBackendObject(void* pixels, int w, int h,
+ GrPixelConfig config, bool /*isRT*/,
+ GrMipMapped mipMapped) {
if (!this->caps()->isConfigTexturable(config)) {
return reinterpret_cast<GrBackendObject>(nullptr);
}
@@ -4450,20 +4450,99 @@ GrBackendObject GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, in
return reinterpret_cast<GrBackendObject>(info.release());
}
-bool GrGLGpu::isTestingOnlyBackendTexture(GrBackendObject id) const {
- GrGLuint texID = reinterpret_cast<const GrGLTextureInfo*>(id)->fID;
+void GrGLGpu::deleteTestingOnlyBackendObject(GrBackendObject id, bool abandonTexture) {
+ std::unique_ptr<const GrGLTextureInfo> info(reinterpret_cast<const GrGLTextureInfo*>(id));
+ GrGLuint texID = info->fID;
+
+ if (!abandonTexture) {
+ GL_CALL(DeleteTextures(1, &texID));
+ }
+}
+
+GrBackendTexture GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h,
+ GrPixelConfig config, bool /*isRT*/,
+ GrMipMapped mipMapped) {
+ if (!this->caps()->isConfigTexturable(config)) {
+ return GrBackendTexture(); // invalid
+ }
+
+ // Currently we don't support uploading pixel data when mipped.
+ if (pixels && GrMipMapped::kYes == mipMapped) {
+ return GrBackendTexture(); // invalid
+ }
+
+ GrGLTextureInfo info;
+ info.fTarget = GR_GL_TEXTURE_2D;
+ info.fID = 0;
+ GL_CALL(GenTextures(1, &info.fID));
+ GL_CALL(ActiveTexture(GR_GL_TEXTURE0));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1));
+ GL_CALL(BindTexture(info.fTarget, info.fID));
+ fHWBoundTextureUniqueIDs[0].makeInvalid();
+ GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_MAG_FILTER, GR_GL_NEAREST));
+ GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST));
+ GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_WRAP_S, GR_GL_CLAMP_TO_EDGE));
+ GL_CALL(TexParameteri(info.fTarget, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE));
+
+ GrGLenum internalFormat;
+ GrGLenum externalFormat;
+ GrGLenum externalType;
+
+ if (!this->glCaps().getTexImageFormats(config, config, &internalFormat, &externalFormat,
+ &externalType)) {
+ return GrBackendTexture(); // invalid
+ }
+
+ this->unbindCpuToGpuXferBuffer();
+
+ // Figure out the number of mip levels.
+ int mipLevels = 1;
+ if (GrMipMapped::kYes == mipMapped) {
+ mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1;
+ }
+
+ size_t bpp = GrBytesPerPixel(config);
+ size_t baseLayerSize = bpp * w * h;
+ SkAutoMalloc defaultStorage(baseLayerSize);
+ if (!pixels) {
+ // Fill in the texture with all zeros so we don't have random garbage
+ pixels = defaultStorage.get();
+ memset(pixels, 0, baseLayerSize);
+ }
+
+ int width = w;
+ int height = h;
+ for (int i = 0; i < mipLevels; ++i) {
+ GL_CALL(TexImage2D(info.fTarget, i, internalFormat, width, height, 0, externalFormat,
+ externalType, pixels));
+ width = SkTMax(1, width / 2);
+ height = SkTMax(1, height / 2);
+ }
+
+ return GrBackendTexture(w, h, config, mipMapped, info);
+}
+
+bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
+ SkASSERT(kOpenGL_GrBackend == tex.backend());
+
+ const GrGLTextureInfo* info = tex.getGLTextureInfo();
+ if (!info) {
+ return false;
+ }
GrGLboolean result;
- GL_CALL_RET(result, IsTexture(texID));
+ GL_CALL_RET(result, IsTexture(info->fID));
return (GR_GL_TRUE == result);
}
-void GrGLGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandonTexture) {
- std::unique_ptr<const GrGLTextureInfo> info(reinterpret_cast<const GrGLTextureInfo*>(id));
- GrGLuint texID = info->fID;
+void GrGLGpu::deleteTestingOnlyBackendTexture(GrBackendTexture* tex, bool abandonTexture) {
+ SkASSERT(kOpenGL_GrBackend == tex->backend());
+
+ const GrGLTextureInfo* info = tex->getGLTextureInfo();
+ if (info && !abandonTexture) {
+ GrGLuint texID = info->fID;
- if (!abandonTexture) {
GL_CALL(DeleteTextures(1, &texID));
}
}