Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
snapshot_controller_impeller.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/common/snapshot_controller_impeller.h"
6
7#include <algorithm>
8
9#include "flutter/flow/surface.h"
10#include "flutter/fml/trace_event.h"
11#include "flutter/impeller/display_list/dl_dispatcher.h"
12#include "flutter/impeller/display_list/dl_image_impeller.h"
13#include "flutter/impeller/geometry/size.h"
14#include "flutter/shell/common/snapshot_controller.h"
15
16namespace flutter {
17
19 sk_sp<DisplayList> display_list,
20 SkISize size) {
24 .SetIfTrue([&] {
25 // Do nothing.
26 })
27 .SetIfFalse(
28 [&] { result = DoMakeRasterSnapshot(display_list, size); }));
29
30 return result;
31}
32
33sk_sp<DlImage> SnapshotControllerImpeller::DoMakeRasterSnapshot(
34 const sk_sp<DisplayList>& display_list,
35 SkISize size) {
36 TRACE_EVENT0("flutter", __FUNCTION__);
37 impeller::DlDispatcher dispatcher;
38 display_list->Dispatch(dispatcher);
39 impeller::Picture picture = dispatcher.EndRecordingAsPicture();
40 auto context = GetDelegate().GetAiksContext();
41 if (context) {
42 auto max_size = context->GetContext()
43 ->GetResourceAllocator()
44 ->GetMaxTextureSizeSupported();
45 double scale_factor_x =
46 static_cast<double>(max_size.width) / static_cast<double>(size.width());
47 double scale_factor_y = static_cast<double>(max_size.height) /
48 static_cast<double>(size.height());
49 double scale_factor =
50 std::min(1.0, std::min(scale_factor_x, scale_factor_y));
51
52 auto render_target_size = impeller::ISize(size.width(), size.height());
53
54 // Scale down the render target size to the max supported by the
55 // GPU if necessary. Exceeding the max would otherwise cause a
56 // null result.
57 if (scale_factor < 1.0) {
58 render_target_size.width *= scale_factor;
59 render_target_size.height *= scale_factor;
60 }
61
62 std::shared_ptr<impeller::Image> image =
63 picture.ToImage(*context, render_target_size);
64 if (image) {
65 return impeller::DlImageImpeller::Make(image->GetTexture(),
67 }
68 }
69
70 return nullptr;
71}
72
74 const std::shared_ptr<impeller::RuntimeStage>& runtime_stage) {
76 runtime_effect.SetRuntimeStage(runtime_stage);
77 auto context = GetDelegate().GetAiksContext();
78 if (!context) {
79 return;
80 }
81 runtime_effect.BootstrapShader(context->GetContentContext());
82}
83
88
89} // namespace flutter
sk_sp< DlImage > MakeRasterSnapshot(sk_sp< DisplayList > display_list, SkISize size) override
sk_sp< SkImage > ConvertToRasterImage(sk_sp< SkImage > image) override
void CacheRuntimeStage(const std::shared_ptr< impeller::RuntimeStage > &runtime_stage) override
virtual std::shared_ptr< const fml::SyncSwitch > GetIsGpuDisabledSyncSwitch() const =0
virtual std::shared_ptr< impeller::AiksContext > GetAiksContext() const =0
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
bool BootstrapShader(const ContentContext &renderer) const
Load the runtime effect and ensure a default PSO is initialized.
void SetRuntimeStage(std::shared_ptr< RuntimeStage > runtime_stage)
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
#define FML_UNREACHABLE()
Definition logging.h:109
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
TSize< int64_t > ISize
Definition size.h:138
Represents the 2 code paths available when calling |SyncSwitchExecute|.
Definition sync_switch.h:35
#define TRACE_EVENT0(category_group, name)