diff options
author | Greg Daniel <egdaniel@google.com> | 2017-08-04 09:34:44 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-04 19:53:55 +0000 |
commit | 4a081e2475fa69dd55fcace9f8e6d3166ea25ad1 (patch) | |
tree | a42a3b82ab0697237fe66e7dda836d07af8e443d /src/gpu/mtl/GrMtlTexture.mm | |
parent | 21c3fb94deac8527719be74deff9e8fb8a490e23 (diff) |
Add GrMtlTexture classes
Adds support for basic Texture creation.
Bug: skia:
Change-Id: I9a3f15bef1c88054c19e952e231cad94ad69f296
Reviewed-on: https://skia-review.googlesource.com/30781
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/mtl/GrMtlTexture.mm')
-rw-r--r-- | src/gpu/mtl/GrMtlTexture.mm | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/gpu/mtl/GrMtlTexture.mm b/src/gpu/mtl/GrMtlTexture.mm new file mode 100644 index 0000000000..ec7f3b1750 --- /dev/null +++ b/src/gpu/mtl/GrMtlTexture.mm @@ -0,0 +1,78 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrMtlTexture.h" + +#include "GrMtlGpu.h" +#include "GrMtlUtil.h" +#include "GrTexturePriv.h" + +sk_sp<GrMtlTexture> GrMtlTexture::CreateNewTexture(GrMtlGpu* gpu, SkBudgeted budgeted, + const GrSurfaceDesc& desc, int mipLevels) { + MTLPixelFormat format; + if (!GrPixelConfigToMTLFormat(desc.fConfig, &format)) { + return nullptr; + } + + MTLTextureDescriptor* descriptor = [[MTLTextureDescriptor alloc] init]; + descriptor.textureType = MTLTextureType2D; + descriptor.pixelFormat = format; + descriptor.width = desc.fWidth; + descriptor.height = desc.fHeight; + descriptor.depth = 1; + descriptor.mipmapLevelCount = mipLevels; + descriptor.sampleCount = 1; + 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? + descriptor.storageMode = MTLStorageModePrivate; + + MTLTextureUsage texUsage = MTLTextureUsageShaderRead; + if (GrMTLFormatIsSRGB(format, nullptr)) { + texUsage |= MTLTextureUsagePixelFormatView; + } + descriptor.usage = texUsage; + + id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:descriptor]; + + return sk_sp<GrMtlTexture>(new GrMtlTexture(gpu, budgeted, desc, texture, mipLevels > 1)); +} + +// This method parallels GrTextureProxy::highestFilterMode +static inline GrSamplerParams::FilterMode highest_filter_mode(GrPixelConfig config) { + if (GrPixelConfigIsSint(config)) { + // We only ever want to nearest-neighbor sample signed int textures. + return GrSamplerParams::kNone_FilterMode; + } + return GrSamplerParams::kMipMap_FilterMode; +} + +GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu, + SkBudgeted budgeted, + const GrSurfaceDesc& desc, + id<MTLTexture> texture, + bool isMipMapped) + : GrSurface(gpu, desc) + , INHERITED(gpu, desc, kTexture2DSampler_GrSLType, highest_filter_mode(desc.fConfig), + isMipMapped) + , fTexture(texture) { +} + +GrMtlTexture::~GrMtlTexture() { + SkASSERT(nil == fTexture); +} + +GrMtlGpu* GrMtlTexture::getMtlGpu() const { + SkASSERT(!this->wasDestroyed()); + return static_cast<GrMtlGpu*>(this->getGpu()); +} + +GrBackendObject GrMtlTexture::getTextureHandle() const { + void* voidTex = (__bridge_retained void*)fTexture; + return (GrBackendObject)voidTex; +} |