Flutter Engine
 
Loading...
Searching...
No Matches
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
6
7#include <memory>
8
10#include "flutter/fml/logging.h"
11
12#include "third_party/skia/include/core/SkCanvas.h"
13#include "third_party/skia/include/core/SkSurface.h"
14
15namespace flutter {
16
18 bool render_to_surface)
19 : delegate_(delegate),
20 render_to_surface_(render_to_surface),
21 weak_factory_(this) {}
22
24
25// |Surface|
27 return delegate_ != nullptr;
28}
29
30// |Surface|
31std::unique_ptr<SurfaceFrame> GPUSurfaceSoftware::AcquireFrame(
32 const DlISize& logical_size) {
33 SurfaceFrame::FramebufferInfo framebuffer_info;
34 framebuffer_info.supports_readback = true;
35
36 // TODO(38466): Refactor GPU surface APIs take into account the fact that an
37 // external view embedder may want to render to the root surface.
38 if (!render_to_surface_) {
39 return std::make_unique<SurfaceFrame>(
40 nullptr, framebuffer_info,
41 [](const SurfaceFrame& surface_frame, DlCanvas* canvas) {
42 return true;
43 },
44 [](const SurfaceFrame& surface_frame) { return true; }, logical_size);
45 }
46
47 if (!IsValid()) {
48 return nullptr;
49 }
50
51 const auto size = DlISize(logical_size.width, logical_size.height);
52
53 sk_sp<SkSurface> backing_store = delegate_->AcquireBackingStore(size);
54
55 if (backing_store == nullptr) {
56 return nullptr;
57 }
58
59 if (size.width != backing_store->width() ||
60 size.height != backing_store->height()) {
61 return nullptr;
62 }
63
64 // If the surface has been scaled, we need to apply the inverse scaling to the
65 // underlying canvas so that coordinates are mapped to the same spot
66 // irrespective of surface scaling.
67 SkCanvas* canvas = backing_store->getCanvas();
68 canvas->resetMatrix();
69
70 SurfaceFrame::EncodeCallback encode_callback =
71 [self = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
72 DlCanvas* canvas) -> bool {
73 // If the surface itself went away, there is nothing more to do.
74 if (!self || !self->IsValid() || canvas == nullptr) {
75 return false;
76 }
77
78 canvas->Flush();
79 return true;
80 };
81 SurfaceFrame::SubmitCallback submit_callback =
82 [self = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame) {
83 // If the surface itself went away, there is nothing more to do.
84 if (!self || !self->IsValid()) {
85 return false;
86 }
87 return self->delegate_->PresentBackingStore(
88 surface_frame.SkiaSurface());
89 };
90
91 return std::make_unique<SurfaceFrame>(backing_store, framebuffer_info,
92 encode_callback, submit_callback,
93 logical_size);
94}
95
96// |Surface|
98 // This backend does not currently support root surface transformations. Just
99 // return identity.
100 return DlMatrix();
101}
102
103// |Surface|
105 // There is no GrContext associated with a software surface.
106 return nullptr;
107}
108
109} // namespace flutter
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
Interface implemented by all platform surfaces that can present a software backing store to the "scre...
virtual sk_sp< SkSurface > AcquireBackingStore(const DlISize &size)=0
Called when the GPU surface needs a new buffer to render a new frame into.
DlMatrix GetRootTransformation() const override
GrDirectContext * GetContext() override
GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate *delegate, bool render_to_surface)
std::unique_ptr< SurfaceFrame > AcquireFrame(const DlISize &size) override
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
std::function< bool(SurfaceFrame &surface_frame)> SubmitCallback
MockDelegate delegate_
impeller::Matrix DlMatrix
impeller::ISize32 DlISize
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
A 4x4 matrix using column-major storage.
Definition matrix.h:37
Type height
Definition size.h:29
Type width
Definition size.h:28