Flutter Engine
 
Loading...
Searching...
No Matches
embedder_test_backingstore_producer_metal.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <exception>
8
10#include "third_party/skia/include/core/SkColorSpace.h"
11#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
12#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
13#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlBackendSurface.h"
14#include "third_party/skia/include/gpu/ganesh/mtl/GrMtlTypes.h"
15
16namespace flutter::testing {
17
19 sk_sp<GrDirectContext> context,
21 : EmbedderTestBackingStoreProducer(std::move(context), type),
22 test_metal_context_(std::make_unique<TestMetalContext>()) {}
23
25
27 FlutterBackingStore* backing_store_out) {
28 // TODO(gw280): Use SkSurfaces::RenderTarget instead of generating our
29 // own MTLTexture and wrapping it.
30 auto surface_size = DlISize(config->size.width, config->size.height);
31 auto texture_info = test_metal_context_->CreateMetalTexture(surface_size);
32
33 GrMtlTextureInfo skia_texture_info;
34 skia_texture_info.fTexture.reset(SkCFSafeRetain(texture_info.texture));
35 GrBackendTexture backend_texture = GrBackendTextures::MakeMtl(
36 surface_size.width, surface_size.height, skgpu::Mipmapped::kNo, skia_texture_info);
37
38 sk_sp<SkSurface> surface =
39 SkSurfaces::WrapBackendTexture(context_.get(), backend_texture, kTopLeft_GrSurfaceOrigin, 1,
40 kBGRA_8888_SkColorType, nullptr, nullptr);
41
42 if (!surface) {
43 FML_LOG(ERROR) << "Could not create Skia surface from a Metal texture.";
44 return false;
45 }
46
47 backing_store_out->type = kFlutterBackingStoreTypeMetal;
48 backing_store_out->user_data = surface.get();
49 backing_store_out->metal.texture.texture = texture_info.texture;
50 // The balancing unref is in the destruction callback.
51 surface->ref();
52 backing_store_out->metal.struct_size = sizeof(FlutterMetalBackingStore);
53 backing_store_out->metal.texture.user_data = surface.get();
54 backing_store_out->metal.texture.destruction_callback = [](void* user_data) {
55 reinterpret_cast<SkSurface*>(user_data)->unref();
56 };
57
58 return true;
59}
60
62 const FlutterBackingStore* backing_store) const {
63 FML_LOG(FATAL) << "Unimplemented.";
64 std::terminate();
65}
66
68 const FlutterBackingStore* backing_store) const {
69 FML_LOG(FATAL) << "Unimplemented.";
70 std::terminate();
71}
72
73} // namespace flutter::testing
GLenum type
sk_sp< SkImage > MakeImageSnapshot(const FlutterBackingStore *backing_store) const override
bool Create(const FlutterBackingStoreConfig *config, FlutterBackingStore *backing_store_out) override
EmbedderTestBackingStoreProducerMetal(sk_sp< GrDirectContext > context, RenderTargetType type)
sk_sp< SkSurface > GetSurface(const FlutterBackingStore *backing_store) const override
@ kFlutterBackingStoreTypeMetal
Specifies a Metal backing store. This is backed by a Metal texture.
Definition embedder.h:2055
VkSurfaceKHR surface
Definition main.cc:65
#define FML_LOG(severity)
Definition logging.h:101
impeller::ISize32 DlISize
Definition ref_ptr.h:261
FlutterSize size
The size of the render target the engine expects to render into.
Definition embedder.h:2093
FlutterMetalBackingStore metal
Definition embedder.h:2083
FlutterBackingStoreType type
Specifies the type of backing store.
Definition embedder.h:2071
size_t struct_size
The size of this struct. Must be sizeof(FlutterMetalBackingStore).
Definition embedder.h:1969
FlutterMetalTexture texture
Definition embedder.h:1974
FlutterMetalTextureHandle texture
Definition embedder.h:865
VoidCallback destruction_callback
Definition embedder.h:872
double height
Definition embedder.h:629
double width
Definition embedder.h:628