aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/mtl/GrMtlTexture.mm
diff options
context:
space:
mode:
authorGravatar Timothy Liang <timliang@google.com>2018-07-02 16:03:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-02 20:57:57 +0000
commite886e80e8b204460a78dabf5c671b7f4146d71f7 (patch)
treebec7b602ec3855000e8d64fe8e3e6025ca7578d1 /src/gpu/mtl/GrMtlTexture.mm
parent389abd50fe74c54a11430f5457d2278cda391132 (diff)
implemented wrapped backend texture/rendertarget/textureRT for Metal gpu backend
Bug: skia: Change-Id: I5d84f9f4340023301bf119731d0b544649be7ab0 Reviewed-on: https://skia-review.googlesource.com/137892 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Timothy Liang <timliang@google.com>
Diffstat (limited to 'src/gpu/mtl/GrMtlTexture.mm')
-rw-r--r--src/gpu/mtl/GrMtlTexture.mm37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/gpu/mtl/GrMtlTexture.mm b/src/gpu/mtl/GrMtlTexture.mm
index 90bfcb38fb..87ee28b206 100644
--- a/src/gpu/mtl/GrMtlTexture.mm
+++ b/src/gpu/mtl/GrMtlTexture.mm
@@ -30,6 +30,19 @@ GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu,
}
GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu,
+ Wrapped,
+ const GrSurfaceDesc& desc,
+ id<MTLTexture> texture,
+ GrMipMapsStatus mipMapsStatus)
+ : GrSurface(gpu, desc)
+ , INHERITED(gpu, desc, kTexture2DSampler_GrSLType, highest_filter_mode(desc.fConfig),
+ mipMapsStatus)
+ , fTexture(texture) {
+ SkASSERT((GrMipMapsStatus::kNotAllocated == mipMapsStatus) == (1 == texture.mipmapLevelCount));
+ this->registerWithCacheWrapped();
+}
+
+GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
id<MTLTexture> texture,
GrMipMapsStatus mipMapsStatus)
@@ -47,6 +60,11 @@ sk_sp<GrMtlTexture> GrMtlTexture::CreateNewTexture(GrMtlGpu* gpu, SkBudgeted bud
return nullptr;
}
+ if (desc.fSampleCnt > 1) {
+ SkASSERT(false); // Currently we don't support msaa
+ return nullptr;
+ }
+
MTLTextureDescriptor* descriptor = [[MTLTextureDescriptor alloc] init];
descriptor.textureType = MTLTextureType2D;
descriptor.pixelFormat = format;
@@ -58,7 +76,7 @@ sk_sp<GrMtlTexture> GrMtlTexture::CreateNewTexture(GrMtlGpu* gpu, SkBudgeted bud
descriptor.arrayLength = 1;
// descriptor.resourceOptions This looks to be set by setting cpuCacheMode and storageModes
descriptor.cpuCacheMode = MTLCPUCacheModeWriteCombined;
- // Shared is not available on MacOS. Is there a reason to want managed to allow mapping?
+ // Make all textures have private gpu only access. We can use transfer buffers to copy to them.
descriptor.storageMode = MTLStorageModePrivate;
descriptor.usage = MTLTextureUsageShaderRead;
@@ -70,6 +88,16 @@ sk_sp<GrMtlTexture> GrMtlTexture::CreateNewTexture(GrMtlGpu* gpu, SkBudgeted bud
return sk_sp<GrMtlTexture>(new GrMtlTexture(gpu, budgeted, desc, texture, mipMapsStatus));
}
+sk_sp<GrMtlTexture> GrMtlTexture::MakeWrappedTexture(GrMtlGpu* gpu,
+ const GrSurfaceDesc& desc,
+ id<MTLTexture> texture) {
+ SkASSERT(nil != texture);
+ SkASSERT(MTLTextureUsageShaderRead & texture.usage);
+ GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kValid
+ : GrMipMapsStatus::kNotAllocated;
+ return sk_sp<GrMtlTexture>(new GrMtlTexture(gpu, kWrapped, desc, texture, mipMapsStatus));
+}
+
GrMtlTexture::~GrMtlTexture() {
SkASSERT(nil == fTexture);
}
@@ -80,5 +108,10 @@ GrMtlGpu* GrMtlTexture::getMtlGpu() const {
}
GrBackendTexture GrMtlTexture::getBackendTexture() const {
- return GrBackendTexture(); // invalid
+ GrMipMapped mipMapped = fTexture.mipmapLevelCount > 1 ? GrMipMapped::kYes
+ : GrMipMapped::kNo;
+ GrMtlTextureInfo info;
+ info.fTexture = GrGetPtrFromId(fTexture);
+ return GrBackendTexture(this->width(), this->height(), mipMapped, info);
}
+