|
6 | 6 |
|
7 | 7 | #include "flutter/fml/trace_event.h" |
8 | 8 | #include "impeller/base/validation.h" |
| 9 | +#include "impeller/renderer/backend/metal/formats_mtl.h" |
9 | 10 | #include "impeller/renderer/backend/metal/texture_mtl.h" |
10 | 11 | #include "impeller/renderer/render_target.h" |
11 | 12 |
|
|
27 | 28 | return nullptr; |
28 | 29 | } |
29 | 30 |
|
30 | | - TextureDescriptor msaa_tex_desc; |
31 | | - msaa_tex_desc.type = TextureType::k2DMultisample; |
32 | | - msaa_tex_desc.sample_count = SampleCount::kCount4; |
33 | | - msaa_tex_desc.format = PixelFormat::kB8G8R8A8UNormInt; |
34 | | - msaa_tex_desc.size = { |
| 31 | + const auto color_format = |
| 32 | + FromMTLPixelFormat(current_drawable.texture.pixelFormat); |
| 33 | + |
| 34 | + if (color_format == PixelFormat::kUnknown) { |
| 35 | + VALIDATION_LOG << "Unknown drawable color format."; |
| 36 | + return nullptr; |
| 37 | + } |
| 38 | + |
| 39 | + TextureDescriptor color0_tex_desc; |
| 40 | + color0_tex_desc.type = TextureType::k2DMultisample; |
| 41 | + color0_tex_desc.sample_count = SampleCount::kCount4; |
| 42 | + color0_tex_desc.format = color_format; |
| 43 | + color0_tex_desc.size = { |
35 | 44 | static_cast<ISize::Type>(current_drawable.texture.width), |
36 | 45 | static_cast<ISize::Type>(current_drawable.texture.height)}; |
37 | | - msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget); |
| 46 | + color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget); |
38 | 47 |
|
39 | 48 | auto msaa_tex = context->GetPermanentsAllocator()->CreateTexture( |
40 | | - StorageMode::kDeviceTransient, msaa_tex_desc); |
| 49 | + StorageMode::kDeviceTransient, color0_tex_desc); |
41 | 50 | if (!msaa_tex) { |
42 | | - FML_LOG(ERROR) << "Could not allocate MSAA resolve texture."; |
| 51 | + VALIDATION_LOG << "Could not allocate MSAA resolve texture."; |
43 | 52 | return nullptr; |
44 | 53 | } |
45 | 54 |
|
46 | 55 | msaa_tex->SetLabel("ImpellerOnscreenColor4xMSAA"); |
47 | 56 |
|
48 | | - TextureDescriptor onscreen_tex_desc; |
49 | | - onscreen_tex_desc.format = PixelFormat::kB8G8R8A8UNormInt; |
50 | | - onscreen_tex_desc.size = msaa_tex_desc.size; |
51 | | - onscreen_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget); |
| 57 | + TextureDescriptor color0_resolve_tex_desc; |
| 58 | + color0_resolve_tex_desc.format = color_format; |
| 59 | + color0_resolve_tex_desc.size = color0_tex_desc.size; |
| 60 | + color0_resolve_tex_desc.usage = |
| 61 | + static_cast<uint64_t>(TextureUsage::kRenderTarget); |
52 | 62 |
|
53 | 63 | ColorAttachment color0; |
54 | 64 | color0.texture = msaa_tex; |
55 | 65 | color0.clear_color = Color::DarkSlateGray(); |
56 | 66 | color0.load_action = LoadAction::kClear; |
57 | 67 | color0.store_action = StoreAction::kMultisampleResolve; |
58 | | - color0.resolve_texture = |
59 | | - std::make_shared<TextureMTL>(onscreen_tex_desc, current_drawable.texture); |
| 68 | + color0.resolve_texture = std::make_shared<TextureMTL>( |
| 69 | + color0_resolve_tex_desc, current_drawable.texture); |
60 | 70 |
|
61 | 71 | TextureDescriptor stencil0_tex; |
62 | 72 | stencil0_tex.type = TextureType::k2DMultisample; |
63 | 73 | stencil0_tex.sample_count = SampleCount::kCount4; |
64 | | - stencil0_tex.format = PixelFormat::kS8UInt; |
65 | | - stencil0_tex.size = msaa_tex_desc.size; |
| 74 | + stencil0_tex.format = PixelFormat::kDefaultStencil; |
| 75 | + stencil0_tex.size = color0_tex_desc.size; |
66 | 76 | stencil0_tex.usage = |
67 | 77 | static_cast<TextureUsageMask>(TextureUsage::kRenderTarget); |
68 | 78 | auto stencil_texture = context->GetPermanentsAllocator()->CreateTexture( |
69 | 79 | StorageMode::kDeviceTransient, stencil0_tex); |
| 80 | + |
| 81 | + if (!stencil_texture) { |
| 82 | + VALIDATION_LOG << "Could not create stencil texture."; |
| 83 | + return nullptr; |
| 84 | + } |
70 | 85 | stencil_texture->SetLabel("ImpellerOnscreenStencil"); |
71 | 86 |
|
72 | 87 | StencilAttachment stencil0; |
|
0 commit comments