Flutter Engine
The Flutter Engine
gpu_surface_software.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/gpu/gpu_surface_software.h"
6
7#include <memory>
8
9#include "flutter/fml/logging.h"
10
12
13namespace flutter {
14
16 bool render_to_surface)
17 : delegate_(delegate),
18 render_to_surface_(render_to_surface),
19 weak_factory_(this) {}
20
22
23// |Surface|
25 return delegate_ != nullptr;
26}
27
28// |Surface|
29std::unique_ptr<SurfaceFrame> GPUSurfaceSoftware::AcquireFrame(
30 const SkISize& logical_size) {
31 SurfaceFrame::FramebufferInfo framebuffer_info;
32 framebuffer_info.supports_readback = true;
33
34 // TODO(38466): Refactor GPU surface APIs take into account the fact that an
35 // external view embedder may want to render to the root surface.
36 if (!render_to_surface_) {
37 return std::make_unique<SurfaceFrame>(
38 nullptr, framebuffer_info,
39 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
40 return true;
41 },
42 logical_size);
43 }
44
45 if (!IsValid()) {
46 return nullptr;
47 }
48
49 const auto size = SkISize::Make(logical_size.width(), logical_size.height());
50
51 sk_sp<SkSurface> backing_store = delegate_->AcquireBackingStore(size);
52
53 if (backing_store == nullptr) {
54 return nullptr;
55 }
56
57 if (size != SkISize::Make(backing_store->width(), backing_store->height())) {
58 return nullptr;
59 }
60
61 // If the surface has been scaled, we need to apply the inverse scaling to the
62 // underlying canvas so that coordinates are mapped to the same spot
63 // irrespective of surface scaling.
64 SkCanvas* canvas = backing_store->getCanvas();
65 canvas->resetMatrix();
66
68 [self = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
69 DlCanvas* canvas) -> bool {
70 // If the surface itself went away, there is nothing more to do.
71 if (!self || !self->IsValid() || canvas == nullptr) {
72 return false;
73 }
74
75 canvas->Flush();
76
77 return self->delegate_->PresentBackingStore(surface_frame.SkiaSurface());
78 };
79
80 return std::make_unique<SurfaceFrame>(backing_store, framebuffer_info,
81 on_submit, logical_size);
82}
83
84// |Surface|
86 // This backend does not currently support root surface transformations. Just
87 // return identity.
89 matrix.reset();
90 return matrix;
91}
92
93// |Surface|
95 // There is no GrContext associated with a software surface.
96 return nullptr;
97}
98
99} // namespace flutter
void resetMatrix()
Definition: SkCanvas.cpp:1355
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
int width() const
Definition: SkSurface.h:178
int height() const
Definition: SkSurface.h:184
Developer-facing API for rendering anything within the engine.
Definition: dl_canvas.h:38
Interface implemented by all platform surfaces that can present a software backing store to the "scre...
virtual sk_sp< SkSurface > AcquireBackingStore(const SkISize &size)=0
Called when the GPU surface needs a new buffer to render a new frame into.
SkMatrix GetRootTransformation() const override
GrDirectContext * GetContext() override
GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate *delegate, bool render_to_surface)
std::unique_ptr< SurfaceFrame > AcquireFrame(const SkISize &size) override
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> SubmitCallback
Definition: surface_frame.h:27
MockDelegate delegate_
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37