Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
embedder_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/platform/embedder/embedder_surface_software.h"
6
7#include <utility>
8
9#include "flutter/fml/trace_event.h"
10
15
16namespace flutter {
17
19 SoftwareDispatchTable software_dispatch_table,
20 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
21 : software_dispatch_table_(std::move(software_dispatch_table)),
22 external_view_embedder_(std::move(external_view_embedder)) {
23 if (!software_dispatch_table_.software_present_backing_store) {
24 return;
25 }
26 valid_ = true;
27}
28
30
31// |EmbedderSurface|
32bool EmbedderSurfaceSoftware::IsValid() const {
33 return valid_;
34}
35
36// |EmbedderSurface|
37std::unique_ptr<Surface> EmbedderSurfaceSoftware::CreateGPUSurface() {
38 if (!IsValid()) {
39 return nullptr;
40 }
41 const bool render_to_surface = !external_view_embedder_;
42 auto surface = std::make_unique<GPUSurfaceSoftware>(this, render_to_surface);
43
44 if (!surface->IsValid()) {
45 return nullptr;
46 }
47
48 return surface;
49}
50
51// |EmbedderSurface|
52sk_sp<GrDirectContext> EmbedderSurfaceSoftware::CreateResourceContext() const {
53 return nullptr;
54}
55
56// |GPUSurfaceSoftwareDelegate|
57sk_sp<SkSurface> EmbedderSurfaceSoftware::AcquireBackingStore(
58 const SkISize& size) {
59 TRACE_EVENT0("flutter", "EmbedderSurfaceSoftware::AcquireBackingStore");
60 if (!IsValid()) {
62 << "Could not acquire backing store for the software surface.";
63 return nullptr;
64 }
65
66 if (sk_surface_ != nullptr &&
67 SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
68 // The old and new surface sizes are the same. Nothing to do here.
69 return sk_surface_;
70 }
71
74 sk_surface_ = SkSurfaces::Raster(info, nullptr);
75
76 if (sk_surface_ == nullptr) {
77 FML_LOG(ERROR) << "Could not create backing store for software rendering.";
78 return nullptr;
79 }
80
81 return sk_surface_;
82}
83
84// |GPUSurfaceSoftwareDelegate|
85bool EmbedderSurfaceSoftware::PresentBackingStore(
86 sk_sp<SkSurface> backing_store) {
87 if (!IsValid()) {
88 FML_LOG(ERROR) << "Tried to present an invalid software surface.";
89 return false;
90 }
91
92 SkPixmap pixmap;
93 if (!backing_store->peekPixels(&pixmap)) {
94 FML_LOG(ERROR) << "Could not peek the pixels of the backing store.";
95 return false;
96 }
97
98 // Some basic sanity checking.
99 uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
100
101 const size_t pixmap_size = pixmap.computeByteSize();
102
103 if (expected_pixmap_data_size != pixmap_size) {
104 FML_LOG(ERROR) << "Software backing store had unexpected size.";
105 return false;
106 }
107
108 return software_dispatch_table_.software_present_backing_store(
109 pixmap.addr(), //
110 pixmap.rowBytes(), //
111 pixmap.height() //
112 );
113}
114
115} // namespace flutter
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
static sk_sp< SkColorSpace > MakeSRGB()
size_t rowBytes() const
Definition: SkPixmap.h:145
int width() const
Definition: SkPixmap.h:160
size_t computeByteSize() const
Definition: SkPixmap.h:231
const void * addr() const
Definition: SkPixmap.h:153
int height() const
Definition: SkPixmap.h:166
int width() const
Definition: SkSurface.h:178
bool peekPixels(SkPixmap *pixmap)
Definition: SkSurface.cpp:121
int height() const
Definition: SkSurface.h:184
EmbedderSurfaceSoftware(SoftwareDispatchTable software_dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
VkSurfaceKHR surface
Definition: main.cc:49
#define FML_LOG(severity)
Definition: logging.h:82
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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: ref_ptr.h:256
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
std::function< bool(const void *allocation, size_t row_bytes, size_t height)> software_present_backing_store
#define ERROR(message)
Definition: elf_loader.cc:260
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131