diff options
author | Greg Daniel <egdaniel@google.com> | 2017-10-12 12:27:11 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-12 17:02:41 +0000 |
commit | 177e695589edb1f776cc5c28b9d3eee244d48284 (patch) | |
tree | eaa617f0300127c65a90a6aea03dc85f7d136d46 /src/gpu/gl/GrGLGpu.cpp | |
parent | 18e5cbbe65cc70c6818cc6b135ff45f4653f960b (diff) |
Add flag on GrBackendTexture to say whether texture is mipped or not
Bug: skia:
Change-Id: Ia684e3daf779ec2feaaec64c04dabf5cb03cd07a
Reviewed-on: https://skia-review.googlesource.com/57821
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/gl/GrGLGpu.cpp')
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 86aa76f981..3d347eca10 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -551,7 +551,10 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe surfDesc.fConfig = backendTex.config(); surfDesc.fSampleCnt = 0; - return GrGLTexture::MakeWrapped(this, surfDesc, idDesc); + GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kValid + : GrMipMapsStatus::kNotAllocated; + + return GrGLTexture::MakeWrapped(this, surfDesc, mipMapsStatus, idDesc); } sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, @@ -585,8 +588,12 @@ sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, &rtIDDesc)) { return nullptr; } + + GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kDirty + : GrMipMapsStatus::kNotAllocated; + sk_sp<GrGLTextureRenderTarget> texRT( - GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc)); + GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc, mipMapsStatus)); texRT->baseLevelWasBoundToFBO(); return std::move(texRT); } @@ -4230,10 +4237,17 @@ void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { } GrBackendObject GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h, - GrPixelConfig config, bool /*isRT*/) { + GrPixelConfig config, bool /*isRT*/, + GrMipMapped mipMapped) { if (!this->caps()->isConfigTexturable(config)) { - return false; + return reinterpret_cast<GrBackendObject>(nullptr); + } + + // Currently we don't support uploading pixel data when mipped. + if (pixels && GrMipMapped::kYes == mipMapped) { + return reinterpret_cast<GrBackendObject>(nullptr); } + std::unique_ptr<GrGLTextureInfo> info = skstd::make_unique<GrGLTextureInfo>(); info->fTarget = GR_GL_TEXTURE_2D; info->fID = 0; @@ -4257,8 +4271,21 @@ GrBackendObject GrGLGpu::createTestingOnlyBackendTexture(void* pixels, int w, in } this->unbindCpuToGpuXferBuffer(); - GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, w, h, 0, externalFormat, - externalType, pixels)); + + // Figure out the number of mip levels. + int mipLevels = 1; + if (GrMipMapped::kYes == mipMapped) { + mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1; + } + + int width = w; + int height = h; + for (int i = 0; i < mipLevels; ++i) { + GL_CALL(TexImage2D(info->fTarget, 0, internalFormat, width, height, 0, externalFormat, + externalType, pixels)); + width = SkTMax(1, width / 2); + height = SkTMax(1, height / 2); + } return reinterpret_cast<GrBackendObject>(info.release()); } |