Flutter Engine
 
Loading...
Searching...
No Matches
android_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#include <vector>
9
10#include "flutter/fml/logging.h"
16
17#include "third_party/skia/include/core/SkImage.h"
18#include "third_party/skia/include/core/SkSurface.h"
19
20namespace flutter {
21
22namespace {
23
24bool GetSkColorType(int32_t buffer_format,
25 SkColorType* color_type,
26 SkAlphaType* alpha_type) {
27 switch (buffer_format) {
28 case WINDOW_FORMAT_RGB_565:
29 *color_type = kRGB_565_SkColorType;
30 *alpha_type = kOpaque_SkAlphaType;
31 return true;
32 case WINDOW_FORMAT_RGBA_8888:
33 *color_type = kRGBA_8888_SkColorType;
34 *alpha_type = kPremul_SkAlphaType;
35 return true;
36 default:
37 return false;
38 }
39}
40
41} // anonymous namespace
42
44 GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_,
45 &target_alpha_type_);
46}
47
49
51 return true;
52}
53
55 // Resource Context always not available on software backend.
56 return false;
57}
58
62
64 // The software AndroidSurface neither uses any passed in Skia context
65 // nor does it interact with the AndroidContext's raster Skia context.
66 GrDirectContext* gr_context) {
67 if (!IsValid()) {
68 return nullptr;
69 }
70
71 auto surface =
72 std::make_unique<GPUSurfaceSoftware>(this, true /* render to surface */);
73
74 if (!surface->IsValid()) {
75 return nullptr;
76 }
77
78 return surface;
79}
80
82 const DlISize& size) {
83 TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::AcquireBackingStore");
84 if (!IsValid()) {
85 return nullptr;
86 }
87
88 if (sk_surface_ != nullptr && //
89 sk_surface_->width() == size.width &&
90 sk_surface_->height() == size.height) {
91 // The old and new surface sizes are the same. Nothing to do here.
92 return sk_surface_;
93 }
94
95 SkImageInfo image_info =
96 SkImageInfo::Make(size.width, size.height, target_color_type_,
97 target_alpha_type_, SkColorSpace::MakeSRGB());
98
99 sk_surface_ = SkSurfaces::Raster(image_info);
100
101 return sk_surface_;
102}
103
105 sk_sp<SkSurface> backing_store) {
106 TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::PresentBackingStore");
107 if (!IsValid() || backing_store == nullptr) {
108 return false;
109 }
110
111 SkPixmap pixmap;
112 if (!backing_store->peekPixels(&pixmap)) {
113 return false;
114 }
115
116 ANativeWindow_Buffer native_buffer;
117 if (ANativeWindow_lock(native_window_->handle(), &native_buffer, nullptr)) {
118 return false;
119 }
120
121 SkColorType color_type;
122 SkAlphaType alpha_type;
123 if (GetSkColorType(native_buffer.format, &color_type, &alpha_type)) {
124 SkImageInfo native_image_info = SkImageInfo::Make(
125 native_buffer.width, native_buffer.height, color_type, alpha_type);
126
127 std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(
128 native_image_info, native_buffer.bits,
129 native_buffer.stride * SkColorTypeBytesPerPixel(color_type));
130
131 if (canvas) {
132 SkBitmap bitmap;
133 if (bitmap.installPixels(pixmap)) {
134 canvas->drawImageRect(
135 bitmap.asImage(),
136 SkRect::MakeIWH(native_buffer.width, native_buffer.height),
137 SkSamplingOptions());
138 }
139 }
140 }
141
142 ANativeWindow_unlockAndPost(native_window_->handle());
143
144 return true;
145}
146
148
150 return true;
151}
152
155 const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
156 native_window_ = std::move(window);
157 if (!(native_window_ && native_window_->IsValid())) {
158 return false;
159 }
160 int32_t window_format = ANativeWindow_getFormat(native_window_->handle());
161 if (window_format < 0) {
162 return false;
163 }
164 if (!GetSkColorType(window_format, &target_color_type_,
165 &target_alpha_type_)) {
166 return false;
167 }
168 return true;
169}
170
171} // namespace flutter
sk_sp< SkSurface > AcquireBackingStore(const DlISize &size) override
Called when the GPU surface needs a new buffer to render a new frame into.
bool PresentBackingStore(sk_sp< SkSurface > backing_store) override
Called by the platform when a frame has been rendered into the backing store and the platform must di...
bool OnScreenSurfaceResize(const DlISize &size) override
bool SetNativeWindow(fml::RefPtr< AndroidNativeWindow > window, const std::shared_ptr< PlatformViewAndroidJNI > &jni_facade) override
std::unique_ptr< Surface > CreateGPUSurface(GrDirectContext *gr_context) override
GLFWwindow * window
Definition main.cc:60
VkSurfaceKHR surface
Definition main.cc:65
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
uint32_t color_type
uint32_t alpha_type
#define TRACE_EVENT0(category_group, name)