Flutter Engine
 
Loading...
Searching...
No Matches
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
6
7#include <utility>
8
10
11#include "third_party/skia/include/core/SkColorSpace.h"
12#include "third_party/skia/include/core/SkImageInfo.h"
13#include "third_party/skia/include/core/SkSurface.h"
14#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
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 DlISize& size) {
59 TRACE_EVENT0("flutter", "EmbedderSurfaceSoftware::AcquireBackingStore");
60 if (!IsValid()) {
61 FML_LOG(ERROR)
62 << "Could not acquire backing store for the software surface.";
63 return nullptr;
64 }
65
66 if (sk_surface_ != nullptr && //
67 size.width == sk_surface_->width() &&
68 size.height == sk_surface_->height()) {
69 // The old and new surface sizes are the same. Nothing to do here.
70 return sk_surface_;
71 }
72
73 SkImageInfo info = SkImageInfo::MakeN32(
74 size.width, size.height, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());
75 sk_surface_ = SkSurfaces::Raster(info, nullptr);
76
77 if (sk_surface_ == nullptr) {
78 FML_LOG(ERROR) << "Could not create backing store for software rendering.";
79 return nullptr;
80 }
81
82 return sk_surface_;
83}
84
85// |GPUSurfaceSoftwareDelegate|
86bool EmbedderSurfaceSoftware::PresentBackingStore(
87 sk_sp<SkSurface> backing_store) {
88 if (!IsValid()) {
89 FML_LOG(ERROR) << "Tried to present an invalid software surface.";
90 return false;
91 }
92
93 SkPixmap pixmap;
94 if (!backing_store->peekPixels(&pixmap)) {
95 FML_LOG(ERROR) << "Could not peek the pixels of the backing store.";
96 return false;
97 }
98
99 // Some basic sanity checking.
100 uint64_t expected_pixmap_data_size = pixmap.width() * pixmap.height() * 4;
101
102 const size_t pixmap_size = pixmap.computeByteSize();
103
104 if (expected_pixmap_data_size != pixmap_size) {
105 FML_LOG(ERROR) << "Software backing store had unexpected size.";
106 return false;
107 }
108
109 return software_dispatch_table_.software_present_backing_store(
110 pixmap.addr(), //
111 pixmap.rowBytes(), //
112 pixmap.height() //
113 );
114}
115
116} // namespace flutter
EmbedderSurfaceSoftware(SoftwareDispatchTable software_dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
VkSurfaceKHR surface
Definition main.cc:65
#define FML_LOG(severity)
Definition logging.h:101
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
Definition ref_ptr.h:261
std::function< bool(const void *allocation, size_t row_bytes, size_t height)> software_present_backing_store
#define TRACE_EVENT0(category_group, name)