Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_test_context_metal.cc
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
5#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h"
6
7#include <memory>
8#include <utility>
9
10#include "embedder.h"
11#include "flutter/fml/logging.h"
12#include "flutter/shell/platform/embedder/tests/embedder_test_compositor_metal.h"
13
14namespace flutter {
15namespace testing {
16
18 : EmbedderTestContext(std::move(assets_path)) {
19 metal_context_ = std::make_unique<TestMetalContext>();
20}
21
23
25 FML_CHECK(surface_size_.isEmpty());
26 surface_size_ = surface_size;
27 metal_surface_ = TestMetalSurface::Create(*metal_context_, surface_size_);
28}
29
31 return present_count_;
32}
33
37
39 FML_CHECK(!compositor_) << "Already set up a compositor in this context.";
40 FML_CHECK(metal_surface_)
41 << "Set up the Metal surface before setting up a compositor.";
42 compositor_ = std::make_unique<EmbedderTestCompositorMetal>(
43 surface_size_, metal_surface_->GetGrContext());
44}
45
47 return metal_context_.get();
48}
49
51 return metal_surface_.get();
52}
53
55 PresentCallback present_callback) {
56 present_callback_ = std::move(present_callback);
57}
58
61 [&]() { return metal_surface_->GetRasterSurfaceSnapshot(); });
62 present_count_++;
63 if (present_callback_ != nullptr) {
64 return present_callback_(texture_id);
65 }
66 return metal_context_->Present(texture_id);
67}
68
70 TestExternalTextureCallback external_texture_frame_callback) {
71 external_texture_frame_callback_ = std::move(external_texture_frame_callback);
72}
73
75 int64_t texture_id,
76 size_t w,
77 size_t h,
79 if (external_texture_frame_callback_ != nullptr) {
80 return external_texture_frame_callback_(texture_id, w, h, output);
81 } else {
82 return false;
83 }
84}
85
87 NextDrawableCallback next_drawable_callback) {
88 next_drawable_callback_ = std::move(next_drawable_callback);
89}
90
92 const FlutterFrameInfo* frame_info) {
93 if (next_drawable_callback_ != nullptr) {
94 return next_drawable_callback_(frame_info);
95 }
96
97 auto texture_info = metal_surface_->GetTextureInfo();
100 texture.texture_id = texture_info.texture_id;
101 texture.texture =
102 reinterpret_cast<FlutterMetalTextureHandle>(texture_info.texture);
103 return texture;
104}
105
106} // namespace testing
107} // namespace flutter
Creates a MTLTexture backed SkSurface and context that can be used to render to in unit-tests.
static std::unique_ptr< TestMetalSurface > Create(const TestMetalContext &test_metal_context, SkISize surface_size=SkISize::MakeEmpty())
std::function< bool(int64_t texture_id, size_t w, size_t h, FlutterMetalExternalTexture *output)> TestExternalTextureCallback
std::function< FlutterMetalTexture(const FlutterFrameInfo *frame_info)> NextDrawableCallback
std::function< bool(int64_t texture_id)> PresentCallback
void SetNextDrawableCallback(NextDrawableCallback next_drawable_callback)
void SetPresentCallback(PresentCallback present_callback)
void SetExternalTextureCallback(TestExternalTextureCallback external_texture_frame_callback)
FlutterMetalTexture GetNextDrawable(const FlutterFrameInfo *frame_info)
EmbedderTestContextType GetContextType() const override
bool PopulateExternalTexture(int64_t texture_id, size_t w, size_t h, FlutterMetalExternalTexture *output)
std::unique_ptr< EmbedderTestCompositor > compositor_
void FireRootSurfacePresentCallbackIfPresent(const std::function< sk_sp< SkImage >(void)> &image_callback)
const void * FlutterMetalTextureHandle
Alias for id<MTLTexture>.
Definition embedder.h:600
#define FML_CHECK(condition)
Definition logging.h:85
FlTexture * texture
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
Definition switches.h:59
Definition ref_ptr.h:256
SkScalar w
size_t struct_size
The size of this struct. Must be sizeof(FlutterMetalTexture).
Definition embedder.h:649
bool isEmpty() const
Definition SkSize.h:31
int64_t texture_id