aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-10-12 12:27:11 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-12 17:02:41 +0000
commit177e695589edb1f776cc5c28b9d3eee244d48284 (patch)
treeeaa617f0300127c65a90a6aea03dc85f7d136d46 /src/gpu
parent18e5cbbe65cc70c6818cc6b135ff45f4653f960b (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')
-rw-r--r--src/gpu/GrBackendSurface.cpp17
-rw-r--r--src/gpu/GrGpu.h8
-rw-r--r--src/gpu/gl/GrGLGpu.cpp39
-rw-r--r--src/gpu/gl/GrGLGpu.h3
-rw-r--r--src/gpu/gl/GrGLTexture.cpp9
-rw-r--r--src/gpu/gl/GrGLTexture.h5
-rw-r--r--src/gpu/gl/GrGLTextureRenderTarget.cpp11
-rw-r--r--src/gpu/gl/GrGLTextureRenderTarget.h6
-rw-r--r--src/gpu/mock/GrMockGpu.cpp3
-rw-r--r--src/gpu/mock/GrMockGpu.h2
-rw-r--r--src/gpu/mtl/GrMtlGpu.h3
-rw-r--r--src/gpu/vk/GrVkGpu.cpp21
-rw-r--r--src/gpu/vk/GrVkGpu.h3
13 files changed, 99 insertions, 31 deletions
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 04216b7508..67cc634ce0 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -19,6 +19,7 @@ GrBackendTexture::GrBackendTexture(int width,
: fWidth(width)
, fHeight(height)
, fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
+ , fMipMapped(GrBoolToMipMapped(vkInfo.fLevelCount > 1))
, fBackend(kVulkan_GrBackend)
, fVkInfo(vkInfo) {}
#endif
@@ -27,9 +28,17 @@ GrBackendTexture::GrBackendTexture(int width,
int height,
GrPixelConfig config,
const GrGLTextureInfo& glInfo)
+ : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {}
+
+GrBackendTexture::GrBackendTexture(int width,
+ int height,
+ GrPixelConfig config,
+ GrMipMapped mipMapped,
+ const GrGLTextureInfo& glInfo)
: fWidth(width)
, fHeight(height)
, fConfig(config)
+ , fMipMapped(mipMapped)
, fBackend(kOpenGL_GrBackend)
, fGLInfo(glInfo) {}
@@ -37,9 +46,17 @@ GrBackendTexture::GrBackendTexture(int width,
int height,
GrPixelConfig config,
const GrMockTextureInfo& mockInfo)
+ : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {}
+
+GrBackendTexture::GrBackendTexture(int width,
+ int height,
+ GrPixelConfig config,
+ GrMipMapped mipMapped,
+ const GrMockTextureInfo& mockInfo)
: fWidth(width)
, fHeight(height)
, fConfig(config)
+ , fMipMapped(mipMapped)
, fBackend(kMock_GrBackend)
, fMockInfo(mockInfo) {}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index ef99a4801e..676b3b0811 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -465,9 +465,11 @@ public:
/** Creates a texture directly in the backend API without wrapping it in a GrTexture. This is
only to be used for testing (particularly for testing the methods that import an externally
created texture into Skia. Must be matched with a call to deleteTestingOnlyTexture(). */
- virtual GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
- GrPixelConfig config,
- bool isRenderTarget = false) = 0;
+ virtual GrBackendObject createTestingOnlyBackendTexture(
+ void* pixels, int w, int h,
+ GrPixelConfig config,
+ bool isRenderTarget = false,
+ GrMipMapped mipMapped = GrMipMapped::kNo) = 0;
/** Check a handle represents an actual texture in the backend API that has not been freed. */
virtual bool isTestingOnlyBackendTexture(GrBackendObject) const = 0;
/** If ownership of the backend texture has been transferred pass true for abandonTexture. This
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());
}
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index a3af0ae8db..0fef2afb05 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -165,7 +165,8 @@ public:
GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
GrPixelConfig config,
- bool isRenderTarget = false) override;
+ bool isRenderTarget,
+ GrMipMapped mipMapped) override;
bool isTestingOnlyBackendTexture(GrBackendObject) const override;
void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index aa918d5ed7..b5c8c697e1 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -57,10 +57,11 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc&
this->registerWithCache(budgeted);
}
-GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const IDDesc& idDesc)
+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), GrMipMapsStatus::kNotAllocated) {
+ highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) {
this->init(desc, idDesc);
this->registerWithCacheWrapped();
}
@@ -112,7 +113,7 @@ void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
}
sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
- const IDDesc& idDesc) {
- return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, idDesc));
+ GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc) {
+ return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, mipMapsStatus, idDesc));
}
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 8ab6805738..bb46d8d9b6 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -67,7 +67,8 @@ public:
bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; }
- static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
+ static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus,
+ const IDDesc&);
protected:
// Constructor for subclasses.
@@ -75,7 +76,7 @@ protected:
enum Wrapped { kWrapped };
// Constructor for instances wrapping backend objects.
- GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&);
+ GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&);
void init(const GrSurfaceDesc&, const IDDesc&);
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp
index c5a75be872..c4a0456171 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -27,9 +27,10 @@ GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
const GrSurfaceDesc& desc,
const GrGLTexture::IDDesc& texIDDesc,
- const GrGLRenderTarget::IDDesc& rtIDDesc)
+ const GrGLRenderTarget::IDDesc& rtIDDesc,
+ GrMipMapsStatus mipMapsStatus)
: GrSurface(gpu, desc)
- , GrGLTexture(gpu, desc, texIDDesc, GrMipMapsStatus::kNotAllocated)
+ , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
, GrGLRenderTarget(gpu, desc, rtIDDesc) {
this->registerWithCacheWrapped();
}
@@ -70,11 +71,11 @@ bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
}
sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
- GrGLGpu* gpu, const GrSurfaceDesc& desc,
- const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc)
+ GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc,
+ const GrGLRenderTarget::IDDesc& rtIDDesc, GrMipMapsStatus mipMapsStatus)
{
return sk_sp<GrGLTextureRenderTarget>(
- new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc));
+ new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, mipMapsStatus));
}
size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index 6621f9c004..4a6cae0b97 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -37,7 +37,8 @@ public:
static sk_sp<GrGLTextureRenderTarget> MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
const GrGLTexture::IDDesc& texIDDesc,
- const GrGLRenderTarget::IDDesc& rtIDDesc);
+ const GrGLRenderTarget::IDDesc& rtIDDesc,
+ GrMipMapsStatus);
protected:
void onAbandon() override {
GrGLRenderTarget::onAbandon();
@@ -54,7 +55,8 @@ private:
GrGLTextureRenderTarget(GrGLGpu* gpu,
const GrSurfaceDesc& desc,
const GrGLTexture::IDDesc& texIDDesc,
- const GrGLRenderTarget::IDDesc& rtIDDesc);
+ const GrGLRenderTarget::IDDesc& rtIDDesc,
+ GrMipMapsStatus);
size_t onGpuMemorySize() const override;
};
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index 9730ddaefe..a21991fabe 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -91,7 +91,8 @@ GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(const GrR
}
GrBackendObject GrMockGpu::createTestingOnlyBackendTexture(void* pixels, int w, int h,
- GrPixelConfig config, bool isRT) {
+ GrPixelConfig config, bool isRT,
+ GrMipMapped) {
auto info = new GrMockTextureInfo;
info->fID = NextExternalTextureID();
fOutstandingTestingOnlyTextureIDs.add(info->fID);
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 5efe3b796e..574906ea3d 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -132,7 +132,7 @@ private:
void clearStencil(GrRenderTarget*, int clearValue) override {}
GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, GrPixelConfig,
- bool isRT) override;
+ bool isRT, GrMipMapped) override;
bool isTestingOnlyBackendTexture(GrBackendObject) const override;
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index 17949488cc..fb2c368102 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -144,7 +144,8 @@ private:
void clearStencil(GrRenderTarget* target, int clearValue) override {}
GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
- GrPixelConfig config, bool isRT) override {
+ GrPixelConfig config, bool isRT,
+ GrMipMapped) override {
return 0;
}
bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 2119199f65..1a9bd2f254 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1175,7 +1175,8 @@ bool copy_testing_data(GrVkGpu* gpu, void* srcData, const GrVkAlloc& alloc,
GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, int h,
GrPixelConfig config,
- bool isRenderTarget) {
+ bool isRenderTarget,
+ GrMipMapped mipMapped) {
VkFormat pixelFormat;
if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
@@ -1191,8 +1192,14 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i
return 0;
}
+ // Currently we don't support uploading pixel data when mipped.
+ if (srcData && GrMipMapped::kYes == mipMapped) {
+ return 0;
+ }
+
if (fVkCaps->isConfigTexturableLinearly(config) &&
- (!isRenderTarget || fVkCaps->isConfigRenderableLinearly(config, false))) {
+ (!isRenderTarget || fVkCaps->isConfigRenderableLinearly(config, false)) &&
+ GrMipMapped::kNo == mipMapped) {
linearTiling = true;
}
@@ -1217,6 +1224,12 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i
return 0;
}
+ // Figure out the number of mip levels.
+ uint32_t mipLevels = 1;
+ if (GrMipMapped::kYes == mipMapped) {
+ mipLevels = SkMipMap::ComputeLevelCount(w, h) + 1;
+ }
+
const VkImageCreateInfo imageCreateInfo = {
VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // sType
nullptr, // pNext
@@ -1224,7 +1237,7 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i
VK_IMAGE_TYPE_2D, // VkImageType
pixelFormat, // VkFormat
{ (uint32_t) w, (uint32_t) h, 1 }, // VkExtent3D
- 1, // mipLevels
+ mipLevels, // mipLevels
1, // arrayLayers
vkSamples, // samples
imageTiling, // VkImageTiling
@@ -1414,7 +1427,7 @@ GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i
info->fImageTiling = imageTiling;
info->fImageLayout = initialLayout;
info->fFormat = pixelFormat;
- info->fLevelCount = 1;
+ info->fLevelCount = mipLevels;
return (GrBackendObject)info;
}
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 3850af623d..1d2aca3673 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -87,7 +87,8 @@ public:
GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
GrPixelConfig config,
- bool isRenderTarget) override;
+ bool isRenderTarget,
+ GrMipMapped) override;
bool isTestingOnlyBackendTexture(GrBackendObject id) const override;
void deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandonTexture) override;