Flutter Engine
The Flutter Engine
GrMtlTexture.mm
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
14
15#if !__has_feature(objc_arc)
16#error This file must be compiled with Arc. Use -fobjc-arc flag
17#endif
18
19GR_NORETAIN_BEGIN
20
22 skgpu::Budgeted budgeted,
23 SkISize dimensions,
25 GrMipmapStatus mipmapStatus,
26 std::string_view label)
27 : GrSurface(gpu, dimensions, GrProtected::kNo, label)
28 , INHERITED(gpu, dimensions, GrProtected::kNo, GrTextureType::k2D, mipmapStatus, label)
29 , fTexture(std::move(texture)) {
30 SkDEBUGCODE(id<MTLTexture> mtlTexture = fTexture->mtlTexture();)
31 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == mtlTexture.mipmapLevelCount));
32 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
33 SkASSERT(SkToBool(mtlTexture.usage & MTLTextureUsageShaderRead));
34 }
35 SkASSERT(!mtlTexture.framebufferOnly);
36 this->registerWithCache(budgeted);
37 if (skgpu::MtlFormatIsCompressed(fTexture->mtlFormat())) {
38 this->setReadOnly();
39 }
40}
41
43 Wrapped,
44 SkISize dimensions,
46 GrMipmapStatus mipmapStatus,
47 GrWrapCacheable cacheable,
48 GrIOType ioType,
49 std::string_view label)
50 : GrSurface(gpu, dimensions, GrProtected::kNo, label)
51 , INHERITED(gpu, dimensions, GrProtected::kNo, GrTextureType::k2D, mipmapStatus, label)
52 , fTexture(std::move(texture)) {
53 SkDEBUGCODE(id<MTLTexture> mtlTexture = fTexture->mtlTexture();)
54 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == mtlTexture.mipmapLevelCount));
55 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
56 SkASSERT(SkToBool(mtlTexture.usage & MTLTextureUsageShaderRead));
57 }
58 SkASSERT(!mtlTexture.framebufferOnly);
59 if (ioType == kRead_GrIOType) {
60 this->setReadOnly();
61 }
62 this->registerWithCacheWrapped(cacheable);
63}
64
66 SkISize dimensions,
68 GrMipmapStatus mipmapStatus,
69 std::string_view label)
70 : GrSurface(gpu, dimensions, GrProtected::kNo, label)
71 , INHERITED(gpu, dimensions, GrProtected::kNo, GrTextureType::k2D, mipmapStatus, label)
72 , fTexture(std::move(texture)) {
73 SkDEBUGCODE(id<MTLTexture> mtlTexture = fTexture->mtlTexture();)
74 SkASSERT((GrMipmapStatus::kNotAllocated == mipmapStatus) == (1 == mtlTexture.mipmapLevelCount));
75 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
76 SkASSERT(SkToBool(mtlTexture.usage & MTLTextureUsageShaderRead));
77 }
78 SkASSERT(!mtlTexture.framebufferOnly);
79}
80
82 skgpu::Budgeted budgeted,
83 SkISize dimensions,
84 MTLPixelFormat format,
85 uint32_t mipLevels,
86 GrMipmapStatus mipmapStatus,
87 std::string_view label) {
89 gpu, dimensions, format, mipLevels, GrRenderable::kNo, /*numSamples=*/1, budgeted);
90
91 if (!texture) {
92 return nullptr;
93 }
94 return sk_sp<GrMtlTexture>(new GrMtlTexture(gpu, budgeted, dimensions, std::move(texture),
95 mipmapStatus, label));
96}
97
99 SkISize dimensions,
100 id<MTLTexture> texture,
101 GrWrapCacheable cacheable,
102 GrIOType ioType) {
103 SkASSERT(nil != texture);
104 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
105 SkASSERT(SkToBool(texture.usage & MTLTextureUsageShaderRead));
106 }
110 /*label=*/"MtlAttachment_MakeWrapped");
111 if (!attachment) {
112 return nullptr;
113 }
114
117 return sk_sp<GrMtlTexture>(
118 new GrMtlTexture(gpu, kWrapped, dimensions, std::move(attachment), mipmapStatus,
119 cacheable, ioType, /*label=*/"MtlTextureWrappedTexture"));
120}
121
123 SkASSERT(nil == fTexture);
124}
125
127 SkASSERT(!this->wasDestroyed());
128 return static_cast<GrMtlGpu*>(this->getGpu());
129}
130
132 skgpu::Mipmapped mipmapped = fTexture->mtlTexture().mipmapLevelCount > 1
135 GrMtlTextureInfo info;
136 info.fTexture.reset(GrRetainPtrFromId(fTexture->mtlTexture()));
137 return GrBackendTextures::MakeMtl(this->width(), this->height(), mipmapped, info);
138}
139
141 return GrBackendFormats::MakeMtl(fTexture->mtlFormat());
142}
143
145 SkASSERT(fTexture);
146 if (!this->getLabel().empty()) {
147 NSString* labelStr = @(this->getLabel().c_str());
148 fTexture->mtlTexture().label = [@"_Skia_" stringByAppendingString:labelStr];
149 }
150}
151
152GR_NORETAIN_END
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SK_ALWAYS_INLINE CF_RETURNS_RETAINED const void * GrRetainPtrFromId(id idObject)
Definition: GrMtlUtil.h:59
GrWrapCacheable
Definition: GrTypesPriv.h:85
GrIOType
Definition: GrTypesPriv.h:402
@ kRead_GrIOType
Definition: GrTypesPriv.h:403
GrMipmapStatus
Definition: GrTypesPriv.h:523
GrTextureType
Definition: GrTypesPriv.h:268
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
std::string getLabel() const
GrGpu * getGpu() const
bool wasDestroyed() const
static sk_sp< GrMtlAttachment > MakeTexture(GrMtlGpu *gpu, SkISize dimensions, MTLPixelFormat format, uint32_t mipLevels, GrRenderable renderable, int numSamples, skgpu::Budgeted budgeted)
MTLPixelFormat mtlFormat() const
static sk_sp< GrMtlAttachment > MakeWrapped(GrMtlGpu *gpu, SkISize dimensions, id< MTLTexture >, UsageFlags attachmentUsages, GrWrapCacheable, std::string_view label)
id< MTLTexture > mtlTexture() const
GrMtlGpu * getMtlGpu() const
~GrMtlTexture() override
static sk_sp< GrMtlTexture > MakeNewTexture(GrMtlGpu *, skgpu::Budgeted budgeted, SkISize dimensions, MTLPixelFormat format, uint32_t mipLevels, GrMipmapStatus, std::string_view label)
Definition: GrMtlTexture.mm:81
GrBackendTexture getBackendTexture() const override
void onSetLabel() override
id< MTLTexture > mtlTexture() const
Definition: GrMtlTexture.h:37
GrMtlAttachment * attachment() const
Definition: GrMtlTexture.h:36
GrBackendFormat backendFormat() const override
static sk_sp< GrMtlTexture > MakeWrappedTexture(GrMtlGpu *, SkISize, id< MTLTexture >, GrWrapCacheable, GrIOType)
Definition: GrMtlTexture.mm:98
GrMtlTexture(GrMtlGpu *, SkISize, sk_sp< GrMtlAttachment >, GrMipmapStatus, std::string_view label)
Definition: GrMtlTexture.mm:65
SkISize dimensions() const
Definition: GrSurface.h:27
int height() const
Definition: GrSurface.h:37
int width() const
Definition: GrSurface.h:32
skgpu::Mipmapped mipmapped() const
Definition: GrTexture.h:62
GrMipmapStatus mipmapStatus() const
Definition: GrTexture.h:66
EMSCRIPTEN_KEEPALIVE void empty()
if(end==-1)
uint32_t uint32_t * format
FlTexture * texture
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)
SK_API GrBackendTexture MakeMtl(int width, int height, skgpu::Mipmapped, const GrMtlTextureInfo &mtlInfo, std::string_view label={})
Budgeted
Definition: GpuTypes.h:35
Mipmapped
Definition: GpuTypes.h:53
bool MtlFormatIsCompressed(MTLPixelFormat mtlFormat)
Definition: MtlUtils.mm:60
Protected
Definition: GpuTypes.h:61
Definition: ref_ptr.h:256
Definition: SkSize.h:16