Support configurable pixel formats for the embedder API sofware rendering backend (flutter/engine#26995)
- add sw rendering pixel format support - add new backing store type that contains struct_size and pixel format - add new public pixel format enum with the common pixel formats supported by skia
This commit is contained in:
@@ -1926,6 +1926,8 @@ FILE: ../../../flutter/shell/platform/embedder/embedder_task_runner.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_task_runner.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_thread_host.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_thread_host.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/pixel_formats.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/pixel_formats.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
|
||||
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/test_utils/key_codes.g.h
|
||||
|
||||
@@ -84,6 +84,7 @@ template("embedder_source_set") {
|
||||
"embedder_task_runner.h",
|
||||
"embedder_thread_host.cc",
|
||||
"embedder_thread_host.h",
|
||||
"pixel_formats.cc",
|
||||
"platform_view_embedder.cc",
|
||||
"platform_view_embedder.h",
|
||||
"vsync_waiter_embedder.cc",
|
||||
|
||||
@@ -55,6 +55,7 @@ extern const intptr_t kPlatformStrongDillSize;
|
||||
#include "flutter/shell/platform/embedder/embedder_struct_macros.h"
|
||||
#include "flutter/shell/platform/embedder/embedder_task_runner.h"
|
||||
#include "flutter/shell/platform/embedder/embedder_thread_host.h"
|
||||
#include "flutter/shell/platform/embedder/pixel_formats.h"
|
||||
#include "flutter/shell/platform/embedder/platform_view_embedder.h"
|
||||
#include "rapidjson/rapidjson.h"
|
||||
#include "rapidjson/writer.h"
|
||||
@@ -695,6 +696,51 @@ static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
|
||||
return surface;
|
||||
}
|
||||
|
||||
static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
|
||||
GrDirectContext* context,
|
||||
const FlutterBackingStoreConfig& config,
|
||||
const FlutterSoftwareBackingStore2* software) {
|
||||
const auto color_info = getSkColorInfo(software->pixel_format);
|
||||
if (!color_info) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto image_info = SkImageInfo::Make(
|
||||
SkISize::Make(config.size.width, config.size.height), *color_info);
|
||||
|
||||
struct Captures {
|
||||
VoidCallback destruction_callback;
|
||||
void* user_data;
|
||||
};
|
||||
auto captures = std::make_unique<Captures>();
|
||||
captures->destruction_callback = software->destruction_callback;
|
||||
captures->user_data = software->user_data;
|
||||
auto release_proc = [](void* pixels, void* context) {
|
||||
auto captures = reinterpret_cast<Captures*>(context);
|
||||
if (captures->destruction_callback) {
|
||||
captures->destruction_callback(captures->user_data);
|
||||
}
|
||||
};
|
||||
|
||||
auto surface = SkSurface::MakeRasterDirectReleaseProc(
|
||||
image_info, // image info
|
||||
const_cast<void*>(software->allocation), // pixels
|
||||
software->row_bytes, // row bytes
|
||||
release_proc, // release proc
|
||||
captures.release() // release context
|
||||
);
|
||||
|
||||
if (!surface) {
|
||||
FML_LOG(ERROR)
|
||||
<< "Could not wrap embedder supplied software render buffer.";
|
||||
if (software->destruction_callback) {
|
||||
software->destruction_callback(software->user_data);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
static sk_sp<SkSurface> MakeSkSurfaceFromBackingStore(
|
||||
GrDirectContext* context,
|
||||
const FlutterBackingStoreConfig& config,
|
||||
@@ -852,6 +898,10 @@ CreateEmbedderRenderTarget(const FlutterCompositor* compositor,
|
||||
render_surface = MakeSkSurfaceFromBackingStore(context, config,
|
||||
&backing_store.software);
|
||||
break;
|
||||
case kFlutterBackingStoreTypeSoftware2:
|
||||
render_surface = MakeSkSurfaceFromBackingStore(context, config,
|
||||
&backing_store.software2);
|
||||
break;
|
||||
case kFlutterBackingStoreTypeMetal:
|
||||
render_surface =
|
||||
MakeSkSurfaceFromBackingStore(context, config, &backing_store.metal);
|
||||
|
||||
@@ -284,6 +284,62 @@ typedef enum {
|
||||
kFlutterOpenGLTargetTypeFramebuffer,
|
||||
} FlutterOpenGLTargetType;
|
||||
|
||||
/// A pixel format to be used for software rendering.
|
||||
///
|
||||
/// A single pixel always stored as a POT number of bytes. (so in practice
|
||||
/// either 1, 2, 4, 8, 16 bytes per pixel)
|
||||
///
|
||||
/// There are two kinds of pixel formats:
|
||||
/// - formats where all components are 8 bits, called array formats
|
||||
/// The component order as specified in the pixel format name is the
|
||||
/// order of the components' bytes in memory, with the leftmost component
|
||||
/// occupying the lowest memory address.
|
||||
///
|
||||
/// - all other formats are called packed formats, and the component order
|
||||
/// as specified in the format name refers to the order in the native type.
|
||||
/// for example, for kRGB565, the R component uses the 5 least significant
|
||||
/// bits of the uint16_t pixel value.
|
||||
///
|
||||
/// Each pixel format in this list is documented with an example on how to get
|
||||
/// the color components from the pixel.
|
||||
/// - for packed formats, p is the pixel value as a word. For example, you can
|
||||
/// get the pixel value for a RGB565 formatted buffer like this:
|
||||
/// uint16_t p = ((const uint16_t*) allocation)[row_bytes * y / bpp + x];
|
||||
/// (with bpp being the bytes per pixel, so 2 for RGB565)
|
||||
///
|
||||
/// - for array formats, p is a pointer to the pixel value. For example, you
|
||||
/// can get the p for a RGBA8888 formatted buffer like this:
|
||||
/// const uint8_t *p = ((const uint8_t*) allocation) + row_bytes*y + x*4;
|
||||
typedef enum {
|
||||
/// pixel with 8 bit grayscale value.
|
||||
/// The grayscale value is the luma value calculated from r, g, b
|
||||
/// according to BT.709. (gray = r*0.2126 + g*0.7152 + b*0.0722)
|
||||
kGray8,
|
||||
|
||||
/// pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word.
|
||||
/// r = p & 0x3F; g = (p>>5) & 0x3F; b = p>>11;
|
||||
kRGB565,
|
||||
|
||||
/// pixel with 4 bits for alpha, red, green, blue; in 16-bit word.
|
||||
/// r = p & 0xF; g = (p>>4) & 0xF; b = (p>>8) & 0xF; a = p>>12;
|
||||
kRGBA4444,
|
||||
|
||||
/// pixel with 8 bits for red, green, blue, alpha.
|
||||
/// r = p[0]; g = p[1]; b = p[2]; a = p[3];
|
||||
kRGBA8888,
|
||||
|
||||
/// pixel with 8 bits for red, green and blue and 8 unused bits.
|
||||
/// r = p[0]; g = p[1]; b = p[2];
|
||||
kRGBX8888,
|
||||
|
||||
/// pixel with 8 bits for blue, green, red and alpha.
|
||||
/// r = p[2]; g = p[1]; b = p[0]; a = p[3];
|
||||
kBGRA8888,
|
||||
|
||||
/// either kBGRA8888 or kRGBA8888 depending on CPU endianess and OS
|
||||
kNative32,
|
||||
} FlutterSoftwarePixelFormat;
|
||||
|
||||
typedef struct {
|
||||
/// Target texture of the active texture unit (example GL_TEXTURE_2D or
|
||||
/// GL_TEXTURE_RECTANGLE).
|
||||
@@ -1121,6 +1177,27 @@ typedef struct {
|
||||
VoidCallback destruction_callback;
|
||||
} FlutterSoftwareBackingStore;
|
||||
|
||||
typedef struct {
|
||||
size_t struct_size;
|
||||
/// A pointer to the raw bytes of the allocation described by this software
|
||||
/// backing store.
|
||||
const void* allocation;
|
||||
/// The number of bytes in a single row of the allocation.
|
||||
size_t row_bytes;
|
||||
/// The number of rows in the allocation.
|
||||
size_t height;
|
||||
/// A baton that is not interpreted by the engine in any way. It will be given
|
||||
/// back to the embedder in the destruction callback below. Embedder resources
|
||||
/// may be associated with this baton.
|
||||
void* user_data;
|
||||
/// The callback invoked by the engine when it no longer needs this backing
|
||||
/// store.
|
||||
VoidCallback destruction_callback;
|
||||
/// The pixel format that the engine should use to render into the allocation.
|
||||
/// In most cases, kR
|
||||
FlutterSoftwarePixelFormat pixel_format;
|
||||
} FlutterSoftwareBackingStore2;
|
||||
|
||||
typedef struct {
|
||||
/// The size of this struct. Must be sizeof(FlutterMetalBackingStore).
|
||||
size_t struct_size;
|
||||
@@ -1212,6 +1289,9 @@ typedef enum {
|
||||
kFlutterBackingStoreTypeMetal,
|
||||
/// Specifies a Vulkan backing store. This is backed by a Vulkan VkImage.
|
||||
kFlutterBackingStoreTypeVulkan,
|
||||
/// Specifies a allocation that the engine should render into using
|
||||
/// software rendering.
|
||||
kFlutterBackingStoreTypeSoftware2,
|
||||
} FlutterBackingStoreType;
|
||||
|
||||
typedef struct {
|
||||
@@ -1231,6 +1311,8 @@ typedef struct {
|
||||
FlutterOpenGLBackingStore open_gl;
|
||||
/// The description of the software backing store.
|
||||
FlutterSoftwareBackingStore software;
|
||||
/// The description of the software backing store.
|
||||
FlutterSoftwareBackingStore2 software2;
|
||||
// The description of the Metal backing store.
|
||||
FlutterMetalBackingStore metal;
|
||||
// The description of the Vulkan backing store.
|
||||
|
||||
@@ -20,7 +20,6 @@ void customEntrypoint() {
|
||||
|
||||
void sayHiFromCustomEntrypoint() native 'SayHiFromCustomEntrypoint';
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void customEntrypoint1() {
|
||||
sayHiFromCustomEntrypoint1();
|
||||
@@ -32,15 +31,11 @@ void sayHiFromCustomEntrypoint1() native 'SayHiFromCustomEntrypoint1';
|
||||
void sayHiFromCustomEntrypoint2() native 'SayHiFromCustomEntrypoint2';
|
||||
void sayHiFromCustomEntrypoint3() native 'SayHiFromCustomEntrypoint3';
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void terminateExitCodeHandler() {
|
||||
final ProcessResult result = Process.runSync(
|
||||
'ls', <String>[]
|
||||
);
|
||||
final ProcessResult result = Process.runSync('ls', <String>[]);
|
||||
}
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void executableNameNotNull() {
|
||||
notifyStringValue(Platform.executable);
|
||||
@@ -54,17 +49,16 @@ void invokePlatformTaskRunner() {
|
||||
PlatformDispatcher.instance.sendPlatformMessage('OhHi', null, null);
|
||||
}
|
||||
|
||||
|
||||
Float64List kTestTransform = () {
|
||||
final Float64List values = Float64List(16);
|
||||
values[0] = 1.0; // scaleX
|
||||
values[4] = 2.0; // skewX
|
||||
values[0] = 1.0; // scaleX
|
||||
values[4] = 2.0; // skewX
|
||||
values[12] = 3.0; // transX
|
||||
values[1] = 4.0; // skewY
|
||||
values[5] = 5.0; // scaleY
|
||||
values[1] = 4.0; // skewY
|
||||
values[5] = 5.0; // scaleY
|
||||
values[13] = 6.0; // transY
|
||||
values[3] = 7.0; // pers0
|
||||
values[7] = 8.0; // pers1
|
||||
values[3] = 7.0; // pers0
|
||||
values[7] = 8.0; // pers1
|
||||
values[15] = 9.0; // pers2
|
||||
return values;
|
||||
}();
|
||||
@@ -73,14 +67,17 @@ void signalNativeTest() native 'SignalNativeTest';
|
||||
void signalNativeCount(int count) native 'SignalNativeCount';
|
||||
void signalNativeMessage(String message) native 'SignalNativeMessage';
|
||||
void notifySemanticsEnabled(bool enabled) native 'NotifySemanticsEnabled';
|
||||
void notifyAccessibilityFeatures(bool reduceMotion) native 'NotifyAccessibilityFeatures';
|
||||
void notifySemanticsAction(int nodeId, int action, List<int> data) native 'NotifySemanticsAction';
|
||||
void notifyAccessibilityFeatures(bool reduceMotion)
|
||||
native 'NotifyAccessibilityFeatures';
|
||||
void notifySemanticsAction(int nodeId, int action, List<int> data)
|
||||
native 'NotifySemanticsAction';
|
||||
|
||||
/// Returns a future that completes when
|
||||
/// `PlatformDispatcher.instance.onSemanticsEnabledChanged` fires.
|
||||
Future<void> get semanticsChanged {
|
||||
final Completer<void> semanticsChanged = Completer<void>();
|
||||
PlatformDispatcher.instance.onSemanticsEnabledChanged = semanticsChanged.complete;
|
||||
PlatformDispatcher.instance.onSemanticsEnabledChanged =
|
||||
semanticsChanged.complete;
|
||||
return semanticsChanged.future;
|
||||
}
|
||||
|
||||
@@ -88,7 +85,8 @@ Future<void> get semanticsChanged {
|
||||
/// `PlatformDispatcher.instance.onAccessibilityFeaturesChanged` fires.
|
||||
Future<void> get accessibilityFeaturesChanged {
|
||||
final Completer<void> featuresChanged = Completer<void>();
|
||||
PlatformDispatcher.instance.onAccessibilityFeaturesChanged = featuresChanged.complete;
|
||||
PlatformDispatcher.instance.onAccessibilityFeaturesChanged =
|
||||
featuresChanged.complete;
|
||||
return featuresChanged.future;
|
||||
}
|
||||
|
||||
@@ -100,8 +98,10 @@ class SemanticsActionData {
|
||||
}
|
||||
|
||||
Future<SemanticsActionData> get semanticsAction {
|
||||
final Completer<SemanticsActionData> actionReceived = Completer<SemanticsActionData>();
|
||||
PlatformDispatcher.instance.onSemanticsAction = (int id, SemanticsAction action, ByteData? args) {
|
||||
final Completer<SemanticsActionData> actionReceived =
|
||||
Completer<SemanticsActionData>();
|
||||
PlatformDispatcher.instance.onSemanticsAction =
|
||||
(int id, SemanticsAction action, ByteData? args) {
|
||||
actionReceived.complete(SemanticsActionData(id, action, args));
|
||||
};
|
||||
return actionReceived.future;
|
||||
@@ -117,11 +117,13 @@ void a11y_main() async {
|
||||
notifySemanticsEnabled(PlatformDispatcher.instance.semanticsEnabled);
|
||||
|
||||
// Return initial state of accessibility features.
|
||||
notifyAccessibilityFeatures(PlatformDispatcher.instance.accessibilityFeatures.reduceMotion);
|
||||
notifyAccessibilityFeatures(
|
||||
PlatformDispatcher.instance.accessibilityFeatures.reduceMotion);
|
||||
|
||||
// Await accessibility features changed from embedder.
|
||||
await accessibilityFeaturesChanged;
|
||||
notifyAccessibilityFeatures(PlatformDispatcher.instance.accessibilityFeatures.reduceMotion);
|
||||
notifyAccessibilityFeatures(
|
||||
PlatformDispatcher.instance.accessibilityFeatures.reduceMotion);
|
||||
|
||||
// Fire semantics update.
|
||||
final SemanticsUpdateBuilder builder = SemanticsUpdateBuilder()
|
||||
@@ -267,7 +269,10 @@ void a11y_main() async {
|
||||
|
||||
// Await semantics action from embedder.
|
||||
final SemanticsActionData data = await semanticsAction;
|
||||
final List<int> actionArgs = <int>[data.args!.getInt8(0), data.args!.getInt8(1)];
|
||||
final List<int> actionArgs = <int>[
|
||||
data.args!.getInt8(0),
|
||||
data.args!.getInt8(1)
|
||||
];
|
||||
notifySemanticsAction(data.id, data.action.index, actionArgs);
|
||||
|
||||
// Await semantics disabled from embedder.
|
||||
@@ -275,10 +280,10 @@ void a11y_main() async {
|
||||
notifySemanticsEnabled(PlatformDispatcher.instance.semanticsEnabled);
|
||||
}
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void platform_messages_response() {
|
||||
PlatformDispatcher.instance.onPlatformMessage = (String name, ByteData? data, PlatformMessageResponseCallback? callback) {
|
||||
PlatformDispatcher.instance.onPlatformMessage =
|
||||
(String name, ByteData? data, PlatformMessageResponseCallback? callback) {
|
||||
callback!(data);
|
||||
};
|
||||
signalNativeTest();
|
||||
@@ -286,7 +291,8 @@ void platform_messages_response() {
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void platform_messages_no_response() {
|
||||
PlatformDispatcher.instance.onPlatformMessage = (String name, ByteData? data, PlatformMessageResponseCallback? callback) {
|
||||
PlatformDispatcher.instance.onPlatformMessage =
|
||||
(String name, ByteData? data, PlatformMessageResponseCallback? callback) {
|
||||
var list = data!.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
||||
signalNativeMessage(utf8.decode(list));
|
||||
// This does nothing because no one is listening on the other side. But complete the loop anyway
|
||||
@@ -399,23 +405,28 @@ void can_composite_platform_views_with_known_scene() {
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
// 10 (Index 0)
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.addPicture(
|
||||
Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
|
||||
builder.pushOffset(20.0, 20.0);
|
||||
// 20 (Index 1)
|
||||
builder.addPlatformView(1, width: size.width, height:size.height); // green - platform
|
||||
// 20 (Index 1)
|
||||
builder.addPlatformView(1,
|
||||
width: size.width, height: size.height); // green - platform
|
||||
builder.pop();
|
||||
|
||||
// 30 (Index 2)
|
||||
builder.addPicture(Offset(30.0, 30.0), CreateColoredBox(blue, size)); // blue - flutter
|
||||
builder.addPicture(
|
||||
Offset(30.0, 30.0), CreateColoredBox(blue, size)); // blue - flutter
|
||||
|
||||
builder.pushOffset(40.0, 40.0);
|
||||
// 40 (Index 3)
|
||||
builder.addPlatformView(2, width: size.width, height:size.height); // magenta - platform
|
||||
// 40 (Index 3)
|
||||
builder.addPlatformView(2,
|
||||
width: size.width, height: size.height); // magenta - platform
|
||||
builder.pop();
|
||||
|
||||
// 50 (Index 4)
|
||||
builder.addPicture(Offset(50.0, 50.0), CreateColoredBox(gray, size)); // gray - flutter
|
||||
builder.addPicture(
|
||||
Offset(50.0, 50.0), CreateColoredBox(gray, size)); // gray - flutter
|
||||
|
||||
builder.pop();
|
||||
|
||||
@@ -437,7 +448,8 @@ void can_composite_platform_views_with_root_layer_only() {
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
// 10 (Index 0)
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.addPicture(
|
||||
Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.pop();
|
||||
|
||||
PlatformDispatcher.instance.views.first.render(builder.build());
|
||||
@@ -458,11 +470,13 @@ void can_composite_platform_views_with_platform_layer_on_bottom() {
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
// 10 (Index 0)
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.addPicture(
|
||||
Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
|
||||
builder.pushOffset(20.0, 20.0);
|
||||
// 20 (Index 1)
|
||||
builder.addPlatformView(1, width: size.width, height:size.height); // green - platform
|
||||
// 20 (Index 1)
|
||||
builder.addPlatformView(1,
|
||||
width: size.width, height: size.height); // green - platform
|
||||
builder.pop();
|
||||
builder.pop();
|
||||
|
||||
@@ -489,15 +503,20 @@ void can_render_scene_without_custom_compositor() {
|
||||
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.addPicture(
|
||||
Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
|
||||
builder.addPicture(Offset(20.0, 20.0), CreateColoredBox(green, size)); // green - flutter
|
||||
builder.addPicture(
|
||||
Offset(20.0, 20.0), CreateColoredBox(green, size)); // green - flutter
|
||||
|
||||
builder.addPicture(Offset(30.0, 30.0), CreateColoredBox(blue, size)); // blue - flutter
|
||||
builder.addPicture(
|
||||
Offset(30.0, 30.0), CreateColoredBox(blue, size)); // blue - flutter
|
||||
|
||||
builder.addPicture(Offset(40.0, 40.0), CreateColoredBox(magenta, size)); // magenta - flutter
|
||||
builder.addPicture(Offset(40.0, 40.0),
|
||||
CreateColoredBox(magenta, size)); // magenta - flutter
|
||||
|
||||
builder.addPicture(Offset(50.0, 50.0), CreateColoredBox(gray, size)); // gray - flutter
|
||||
builder.addPicture(
|
||||
Offset(50.0, 50.0), CreateColoredBox(gray, size)); // gray - flutter
|
||||
|
||||
builder.pop();
|
||||
|
||||
@@ -515,42 +534,34 @@ Picture CreateGradientBox(Size size) {
|
||||
Color.fromARGB(255, 0, 255, 0), // green
|
||||
Color.fromARGB(255, 0, 0, 255), // blue
|
||||
Color.fromARGB(255, 75, 0, 130), // indigo
|
||||
Color.fromARGB(255, 238,130,238), // violet
|
||||
Color.fromARGB(255, 238, 130, 238), // violet
|
||||
];
|
||||
List<double> stops = [
|
||||
(1.0 / 7.0),
|
||||
(2.0 / 7.0),
|
||||
(3.0 / 7.0),
|
||||
(4.0 / 7.0),
|
||||
(5.0 / 7.0),
|
||||
(6.0 / 7.0),
|
||||
(7.0 / 7.0),
|
||||
(1.0 / 7.0),
|
||||
(2.0 / 7.0),
|
||||
(3.0 / 7.0),
|
||||
(4.0 / 7.0),
|
||||
(5.0 / 7.0),
|
||||
(6.0 / 7.0),
|
||||
(7.0 / 7.0),
|
||||
];
|
||||
paint.shader = Gradient.linear(
|
||||
Offset(0.0, 0.0),
|
||||
Offset(size.width, size.height),
|
||||
rainbow, stops);
|
||||
Offset(0.0, 0.0), Offset(size.width, size.height), rainbow, stops);
|
||||
PictureRecorder baseRecorder = PictureRecorder();
|
||||
Canvas canvas = Canvas(baseRecorder);
|
||||
canvas.drawRect(Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint);
|
||||
return baseRecorder.endRecording();
|
||||
}
|
||||
|
||||
void _echoKeyEvent(
|
||||
int change,
|
||||
int timestamp,
|
||||
int physical,
|
||||
int logical,
|
||||
int charCode,
|
||||
bool synthesized)
|
||||
native 'EchoKeyEvent';
|
||||
void _echoKeyEvent(int change, int timestamp, int physical, int logical,
|
||||
int charCode, bool synthesized) native 'EchoKeyEvent';
|
||||
|
||||
// Convert `kind` in enum form to its integer form.
|
||||
//
|
||||
// It performs a reversed mapping from `unserializeKeyEventKind`
|
||||
// in shell/platform/embedder/tests/embedder_unittests.cc.
|
||||
int _serializeKeyEventType(KeyEventType change) {
|
||||
switch(change) {
|
||||
switch (change) {
|
||||
case KeyEventType.up:
|
||||
return 1;
|
||||
case KeyEventType.down:
|
||||
@@ -581,7 +592,8 @@ void key_data_echo() async {
|
||||
// the event data with `_echoKeyEvent`, and returns synthesized as handled.
|
||||
@pragma('vm:entry-point')
|
||||
void key_data_late_echo() async {
|
||||
channelBuffers.setListener('test/starts_echo', (ByteData? data, PlatformMessageResponseCallback callback) {
|
||||
channelBuffers.setListener('test/starts_echo',
|
||||
(ByteData? data, PlatformMessageResponseCallback callback) {
|
||||
PlatformDispatcher.instance.onKeyData = (KeyData data) {
|
||||
_echoKeyEvent(
|
||||
_serializeKeyEventType(data.type),
|
||||
@@ -607,7 +619,8 @@ void render_gradient() {
|
||||
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateGradientBox(size)); // gradient - flutter
|
||||
builder.addPicture(
|
||||
Offset(0.0, 0.0), CreateGradientBox(size)); // gradient - flutter
|
||||
|
||||
builder.pop();
|
||||
|
||||
@@ -625,7 +638,7 @@ void render_texture() {
|
||||
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
builder.addTexture(/*textureId*/1, width: size.width, height: size.height);
|
||||
builder.addTexture(/*textureId*/ 1, width: size.width, height: size.height);
|
||||
|
||||
builder.pop();
|
||||
|
||||
@@ -645,11 +658,13 @@ void render_gradient_on_non_root_backing_store() {
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
|
||||
// Even though this is occluded, add something so it is not elided.
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.addPicture(
|
||||
Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
|
||||
builder.addPlatformView(1, width: 100, height:200); // undefined - platform
|
||||
builder.addPlatformView(1, width: 100, height: 200); // undefined - platform
|
||||
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateGradientBox(size)); // gradient - flutter
|
||||
builder.addPicture(
|
||||
Offset(0.0, 0.0), CreateGradientBox(size)); // gradient - flutter
|
||||
|
||||
builder.pop();
|
||||
|
||||
@@ -669,13 +684,14 @@ void verify_b141980393() {
|
||||
|
||||
SceneBuilder builder = SceneBuilder();
|
||||
|
||||
builder.pushOffset(0.0, // x
|
||||
top_margin // y
|
||||
);
|
||||
builder.pushOffset(
|
||||
0.0, // x
|
||||
top_margin // y
|
||||
);
|
||||
|
||||
// The web view in example.
|
||||
builder.addPlatformView(1337, width: platform_view_size.width,
|
||||
height: platform_view_size.height);
|
||||
builder.addPlatformView(1337,
|
||||
width: platform_view_size.width, height: platform_view_size.height);
|
||||
|
||||
builder.pop();
|
||||
|
||||
@@ -689,16 +705,29 @@ void can_display_platform_view_with_pixel_ratio() {
|
||||
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
|
||||
SceneBuilder builder = SceneBuilder();
|
||||
builder.pushTransform(Float64List.fromList([
|
||||
2.0, 0.0, 0.0, 0.0,
|
||||
0.0, 2.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
2.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
2.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
])); // base
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateGradientBox(Size(400.0, 300.0)));
|
||||
builder.pushOffset(0.0, 20.0); // offset
|
||||
builder.addPlatformView(42, width: 400.0, height: 280.0);
|
||||
builder.pop(); // offset
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateColoredBox(Color.fromARGB(128, 255, 0, 0), Size(400.0, 300.0)));
|
||||
builder.addPicture(Offset(0.0, 0.0),
|
||||
CreateColoredBox(Color.fromARGB(128, 255, 0, 0), Size(400.0, 300.0)));
|
||||
builder.pop(); // base
|
||||
PlatformDispatcher.instance.views.first.render(builder.build());
|
||||
};
|
||||
@@ -707,7 +736,7 @@ void can_display_platform_view_with_pixel_ratio() {
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void can_receive_locale_updates() {
|
||||
PlatformDispatcher.instance.onLocaleChanged = (){
|
||||
PlatformDispatcher.instance.onLocaleChanged = () {
|
||||
signalNativeCount(PlatformDispatcher.instance.locales.length);
|
||||
};
|
||||
signalNativeTest();
|
||||
@@ -721,10 +750,14 @@ void verify_b143464703() {
|
||||
builder.pushOffset(0.0, 0.0); // base
|
||||
|
||||
// Background
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateColoredBox(Color.fromARGB(255, 128, 128, 128), Size(1024.0, 600.0)));
|
||||
builder.addPicture(
|
||||
Offset(0.0, 0.0),
|
||||
CreateColoredBox(
|
||||
Color.fromARGB(255, 128, 128, 128), Size(1024.0, 600.0)));
|
||||
|
||||
builder.pushOpacity(128);
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(Color.fromARGB(255, 0, 0, 255), Size(25.0, 25.0)));
|
||||
builder.addPicture(Offset(10.0, 10.0),
|
||||
CreateColoredBox(Color.fromARGB(255, 0, 0, 255), Size(25.0, 25.0)));
|
||||
builder.pop(); // opacity 128
|
||||
|
||||
// The top bar and the platform view are pushed to the side.
|
||||
@@ -753,7 +786,10 @@ void push_frames_over_and_over() {
|
||||
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
|
||||
SceneBuilder builder = SceneBuilder();
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateColoredBox(Color.fromARGB(255, 128, 128, 128), Size(1024.0, 600.0)));
|
||||
builder.addPicture(
|
||||
Offset(0.0, 0.0),
|
||||
CreateColoredBox(
|
||||
Color.fromARGB(255, 128, 128, 128), Size(1024.0, 600.0)));
|
||||
builder.pushOpacity(128);
|
||||
builder.addPlatformView(42, width: 1024.0, height: 540.0);
|
||||
builder.pop();
|
||||
@@ -765,7 +801,6 @@ void push_frames_over_and_over() {
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
}
|
||||
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void platform_view_mutators() {
|
||||
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
|
||||
@@ -775,7 +810,8 @@ void platform_view_mutators() {
|
||||
|
||||
builder.pushOpacity(128);
|
||||
builder.pushClipRect(Rect.fromLTWH(10.0, 10.0, 800.0 - 20.0, 600.0 - 20.0));
|
||||
builder.pushClipRRect(RRect.fromLTRBR(10.0, 10.0, 800.0 - 10.0, 600.0 - 10.0, Radius.circular(14.0)));
|
||||
builder.pushClipRRect(RRect.fromLTRBR(
|
||||
10.0, 10.0, 800.0 - 10.0, 600.0 - 10.0, Radius.circular(14.0)));
|
||||
builder.addPlatformView(42, width: 800.0, height: 600.0);
|
||||
builder.pop(); // clip rrect
|
||||
builder.pop(); // clip rect
|
||||
@@ -796,7 +832,8 @@ void platform_view_mutators_with_pixel_ratio() {
|
||||
|
||||
builder.pushOpacity(128);
|
||||
builder.pushClipRect(Rect.fromLTWH(5.0, 5.0, 400.0 - 10.0, 300.0 - 10.0));
|
||||
builder.pushClipRRect(RRect.fromLTRBR(5.0, 5.0, 400.0 - 5.0, 300.0 - 5.0, Radius.circular(7.0)));
|
||||
builder.pushClipRRect(RRect.fromLTRBR(
|
||||
5.0, 5.0, 400.0 - 5.0, 300.0 - 5.0, Radius.circular(7.0)));
|
||||
builder.addPlatformView(42, width: 400.0, height: 300.0);
|
||||
builder.pop(); // clip rrect
|
||||
builder.pop(); // clip rect
|
||||
@@ -839,10 +876,10 @@ Picture CreateArcEndCapsPicture() {
|
||||
..strokeJoin = StrokeJoin.miter;
|
||||
|
||||
style.color = Color.fromARGB(255, 255, 0, 0);
|
||||
canvas.drawArc(Rect.fromLTRB(0.0, 0.0, 500.0, 500.0), 1.57, 1.0, false, style);
|
||||
canvas.drawArc(
|
||||
Rect.fromLTRB(0.0, 0.0, 500.0, 500.0), 1.57, 1.0, false, style);
|
||||
|
||||
return baseRecorder.endRecording();
|
||||
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
@@ -879,7 +916,8 @@ void scene_builder_with_complex_clips() {
|
||||
builder.pushClipRect(Rect.fromLTRB(0.0, 0.0, 1024.0, 600.0));
|
||||
builder.addPlatformView(42, width: 1024.0, height: 600.0);
|
||||
|
||||
builder.addPicture(Offset(0.0, 0.0), CreateGradientBox(Size(1024.0, 600.0)));
|
||||
builder.addPicture(
|
||||
Offset(0.0, 0.0), CreateGradientBox(Size(1024.0, 600.0)));
|
||||
PlatformDispatcher.instance.views.first.render(builder.build());
|
||||
};
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
@@ -890,7 +928,9 @@ void sendObjectToNativeCode(dynamic object) native 'SendObjectToNativeCode';
|
||||
@pragma('vm:entry-point')
|
||||
void objects_can_be_posted() {
|
||||
ReceivePort port = ReceivePort();
|
||||
port.listen((dynamic message){ sendObjectToNativeCode(message); });
|
||||
port.listen((dynamic message) {
|
||||
sendObjectToNativeCode(message);
|
||||
});
|
||||
signalNativeCount(port.sendPort.nativePort);
|
||||
}
|
||||
|
||||
@@ -935,7 +975,8 @@ void render_targets_are_recycled() {
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
}
|
||||
|
||||
void nativeArgumentsCallback(List<String> args) native 'NativeArgumentsCallback';
|
||||
void nativeArgumentsCallback(List<String> args)
|
||||
native 'NativeArgumentsCallback';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void custom_logger(List<String> args) {
|
||||
@@ -947,7 +988,8 @@ void dart_entrypoint_args(List<String> args) {
|
||||
nativeArgumentsCallback(args);
|
||||
}
|
||||
|
||||
void snapshotsCallback(Image big_image, Image small_image) native 'SnapshotsCallback';
|
||||
void snapshotsCallback(Image big_image, Image small_image)
|
||||
native 'SnapshotsCallback';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void snapshot_large_scene(int max_size) async {
|
||||
@@ -973,12 +1015,14 @@ void snapshot_large_scene(int max_size) async {
|
||||
double small_width = 128, small_height = 64;
|
||||
recorder = PictureRecorder();
|
||||
{
|
||||
Canvas canvas = Canvas(recorder, Rect.fromLTWH(0, 0, small_width, small_height));
|
||||
Canvas canvas =
|
||||
Canvas(recorder, Rect.fromLTWH(0, 0, small_width, small_height));
|
||||
canvas.scale(small_width / big_image.width);
|
||||
canvas.drawImage(big_image, Offset.zero, Paint());
|
||||
}
|
||||
picture = recorder.endRecording();
|
||||
Image small_image = await picture.toImage(small_width.toInt(), small_height.toInt());
|
||||
Image small_image =
|
||||
await picture.toImage(small_width.toInt(), small_height.toInt());
|
||||
|
||||
snapshotsCallback(big_image, small_image);
|
||||
}
|
||||
@@ -990,7 +1034,8 @@ void invalid_backingstore() {
|
||||
Size size = Size(50.0, 150.0);
|
||||
SceneBuilder builder = SceneBuilder();
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
builder.addPicture(Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.addPicture(
|
||||
Offset(10.0, 10.0), CreateColoredBox(red, size)); // red - flutter
|
||||
builder.pop();
|
||||
PlatformDispatcher.instance.views.first.render(builder.build());
|
||||
};
|
||||
@@ -1002,8 +1047,37 @@ void invalid_backingstore() {
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void can_schedule_frame() {
|
||||
PlatformDispatcher.instance.onBeginFrame = (Duration beginTime){
|
||||
PlatformDispatcher.instance.onBeginFrame = (Duration beginTime) {
|
||||
signalNativeCount(beginTime.inMicroseconds);
|
||||
};
|
||||
signalNativeTest();
|
||||
}
|
||||
|
||||
void drawSolidColor(Color c) {
|
||||
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
|
||||
final SceneBuilder builder = SceneBuilder();
|
||||
builder.pushOffset(0.0, 0.0);
|
||||
builder.addPicture(
|
||||
Offset.zero,
|
||||
CreateColoredBox(
|
||||
c, PlatformDispatcher.instance.views.first.physicalSize));
|
||||
builder.pop();
|
||||
PlatformDispatcher.instance.views.first.render(builder.build());
|
||||
};
|
||||
PlatformDispatcher.instance.scheduleFrame();
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void draw_solid_red() {
|
||||
drawSolidColor(const Color.fromARGB(255, 255, 0, 0));
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void draw_solid_green() {
|
||||
drawSolidColor(const Color.fromARGB(255, 0, 255, 0));
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void draw_solid_blue() {
|
||||
drawSolidColor(const Color.fromARGB(255, 0, 0, 255));
|
||||
}
|
||||
|
||||
40
engine/src/flutter/shell/platform/embedder/pixel_formats.cc
Normal file
40
engine/src/flutter/shell/platform/embedder/pixel_formats.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/platform/embedder/pixel_formats.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
std::optional<SkColorType> getSkColorType(FlutterSoftwarePixelFormat pixfmt) {
|
||||
switch (pixfmt) {
|
||||
case kGray8:
|
||||
return kGray_8_SkColorType;
|
||||
case kRGB565:
|
||||
return kRGB_565_SkColorType;
|
||||
case kRGBA4444:
|
||||
return kARGB_4444_SkColorType;
|
||||
case kRGBA8888:
|
||||
return kRGBA_8888_SkColorType;
|
||||
case kRGBX8888:
|
||||
return kRGB_888x_SkColorType;
|
||||
case kBGRA8888:
|
||||
return kBGRA_8888_SkColorType;
|
||||
case kNative32:
|
||||
return kN32_SkColorType;
|
||||
default:
|
||||
FML_LOG(ERROR) << "Invalid software rendering pixel format";
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<SkColorInfo> getSkColorInfo(FlutterSoftwarePixelFormat pixfmt) {
|
||||
auto ct = getSkColorType(pixfmt);
|
||||
if (!ct) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto at = SkColorTypeIsAlwaysOpaque(*ct) ? kOpaque_SkAlphaType
|
||||
: kPremul_SkAlphaType;
|
||||
|
||||
return SkColorInfo(*ct, at, SkColorSpace::MakeSRGB());
|
||||
}
|
||||
16
engine/src/flutter/shell/platform/embedder/pixel_formats.h
Normal file
16
engine/src/flutter/shell/platform/embedder/pixel_formats.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_COMMON_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_COMMON_H_
|
||||
|
||||
#include <optional>
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
std::optional<SkColorType> getSkColorType(FlutterSoftwarePixelFormat pixfmt);
|
||||
|
||||
std::optional<SkColorInfo> getSkColorInfo(FlutterSoftwarePixelFormat pixfmt);
|
||||
|
||||
#endif
|
||||
@@ -108,6 +108,14 @@ inline bool operator==(const FlutterSoftwareBackingStore& a,
|
||||
a.destruction_callback == b.destruction_callback;
|
||||
}
|
||||
|
||||
inline bool operator==(const FlutterSoftwareBackingStore2& a,
|
||||
const FlutterSoftwareBackingStore2& b) {
|
||||
return a.allocation == b.allocation && a.row_bytes == b.row_bytes &&
|
||||
a.height == b.height && a.user_data == b.user_data &&
|
||||
a.destruction_callback == b.destruction_callback &&
|
||||
a.pixel_format == b.pixel_format;
|
||||
}
|
||||
|
||||
inline bool operator==(const FlutterBackingStore& a,
|
||||
const FlutterBackingStore& b) {
|
||||
if (!(a.struct_size == b.struct_size && a.user_data == b.user_data &&
|
||||
@@ -124,6 +132,8 @@ inline bool operator==(const FlutterBackingStore& a,
|
||||
return a.metal == b.metal;
|
||||
case kFlutterBackingStoreTypeVulkan:
|
||||
return a.vulkan == b.vulkan;
|
||||
case kFlutterBackingStoreTypeSoftware2:
|
||||
return a.software2 == b.software2;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -244,6 +254,8 @@ inline std::string FlutterBackingStoreTypeToString(
|
||||
return "kFlutterBackingStoreTypeMetal";
|
||||
case kFlutterBackingStoreTypeVulkan:
|
||||
return "kFlutterBackingStoreTypeVulkan";
|
||||
case kFlutterBackingStoreTypeSoftware2:
|
||||
return "kFlutterBackingStoreTypeSoftware2";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
@@ -340,6 +352,29 @@ inline std::string FlutterOpenGLTargetTypeToString(
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
inline std::string FlutterSoftwarePixelFormatToString(
|
||||
FlutterSoftwarePixelFormat pixfmt) {
|
||||
switch (pixfmt) {
|
||||
case kGray8:
|
||||
return "kGray8";
|
||||
case kRGB565:
|
||||
return "kRGB565";
|
||||
case kRGBA4444:
|
||||
return "kRGBA4444";
|
||||
case kRGBA8888:
|
||||
return "kRGBA8888";
|
||||
case kRGBX8888:
|
||||
return "kRGBX8888";
|
||||
case kBGRA8888:
|
||||
return "kBGRA8888";
|
||||
case kNative32:
|
||||
return "kNative32";
|
||||
default:
|
||||
FML_LOG(ERROR) << "Invalid software rendering pixel format";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out,
|
||||
const FlutterOpenGLBackingStore& item) {
|
||||
out << "(FlutterOpenGLBackingStore) Type: "
|
||||
@@ -373,6 +408,16 @@ inline std::ostream& operator<<(std::ostream& out,
|
||||
return out << "(FlutterVulkanBackingStore) Image: " << item.image;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out,
|
||||
const FlutterSoftwareBackingStore2& item) {
|
||||
return out << "(FlutterSoftwareBackingStore2) Allocation: " << item.allocation
|
||||
<< " Row Bytes: " << item.row_bytes << " Height: " << item.height
|
||||
<< " User Data: " << item.user_data << " Destruction Callback: "
|
||||
<< reinterpret_cast<void*>(item.destruction_callback)
|
||||
<< " Pixel Format: "
|
||||
<< FlutterSoftwarePixelFormatToString(item.pixel_format);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out,
|
||||
const FlutterBackingStore& backing_store) {
|
||||
out << "(FlutterBackingStore) Struct size: " << backing_store.struct_size
|
||||
@@ -396,6 +441,10 @@ inline std::ostream& operator<<(std::ostream& out,
|
||||
case kFlutterBackingStoreTypeVulkan:
|
||||
out << backing_store.vulkan;
|
||||
break;
|
||||
|
||||
case kFlutterBackingStoreTypeSoftware2:
|
||||
out << backing_store.software2;
|
||||
break;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
@@ -366,13 +366,14 @@ FlutterCompositor& EmbedderConfigBuilder::GetCompositor() {
|
||||
}
|
||||
|
||||
void EmbedderConfigBuilder::SetRenderTargetType(
|
||||
EmbedderTestBackingStoreProducer::RenderTargetType type) {
|
||||
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||
FlutterSoftwarePixelFormat software_pixfmt) {
|
||||
auto& compositor = context_.GetCompositor();
|
||||
// TODO(wrightgeorge): figure out a better way of plumbing through the
|
||||
// GrDirectContext
|
||||
compositor.SetBackingStoreProducer(
|
||||
std::make_unique<EmbedderTestBackingStoreProducer>(
|
||||
compositor.GetGrContext(), type));
|
||||
compositor.GetGrContext(), type, software_pixfmt));
|
||||
}
|
||||
|
||||
UniqueEngine EmbedderConfigBuilder::LaunchEngine() const {
|
||||
|
||||
@@ -105,7 +105,8 @@ class EmbedderConfigBuilder {
|
||||
FlutterCompositor& GetCompositor();
|
||||
|
||||
void SetRenderTargetType(
|
||||
EmbedderTestBackingStoreProducer::RenderTargetType type);
|
||||
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||
FlutterSoftwarePixelFormat software_pixfmt = kNative32);
|
||||
|
||||
UniqueEngine LaunchEngine() const;
|
||||
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
#include "flutter/shell/platform/embedder/tests/embedder_test_backingstore_producer.h"
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/shell/platform/embedder/pixel_formats.h"
|
||||
#include "third_party/skia/include/core/SkColorSpace.h"
|
||||
#include "third_party/skia/include/core/SkColorType.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
#include "third_party/skia/include/core/SkSize.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
||||
namespace flutter {
|
||||
@@ -18,9 +20,11 @@ namespace testing {
|
||||
|
||||
EmbedderTestBackingStoreProducer::EmbedderTestBackingStoreProducer(
|
||||
sk_sp<GrDirectContext> context,
|
||||
RenderTargetType type)
|
||||
RenderTargetType type,
|
||||
FlutterSoftwarePixelFormat software_pixfmt)
|
||||
: context_(context),
|
||||
type_(type)
|
||||
type_(type),
|
||||
software_pixfmt_(software_pixfmt)
|
||||
#ifdef SHELL_ENABLE_METAL
|
||||
,
|
||||
test_metal_context_(std::make_unique<TestMetalContext>())
|
||||
@@ -30,6 +34,14 @@ EmbedderTestBackingStoreProducer::EmbedderTestBackingStoreProducer(
|
||||
test_vulkan_context_(nullptr)
|
||||
#endif
|
||||
{
|
||||
if (type == RenderTargetType::kSoftwareBuffer &&
|
||||
software_pixfmt_ != kNative32) {
|
||||
FML_LOG(ERROR) << "Expected pixel format to be the default (kNative32) when"
|
||||
"backing store producer should produce deprecated v1 "
|
||||
"software backing "
|
||||
"stores.";
|
||||
std::abort();
|
||||
};
|
||||
}
|
||||
|
||||
EmbedderTestBackingStoreProducer::~EmbedderTestBackingStoreProducer() = default;
|
||||
@@ -40,6 +52,8 @@ bool EmbedderTestBackingStoreProducer::Create(
|
||||
switch (type_) {
|
||||
case RenderTargetType::kSoftwareBuffer:
|
||||
return CreateSoftware(config, renderer_out);
|
||||
case RenderTargetType::kSoftwareBuffer2:
|
||||
return CreateSoftware2(config, renderer_out);
|
||||
#ifdef SHELL_ENABLE_GL
|
||||
case RenderTargetType::kOpenGLTexture:
|
||||
return CreateTexture(config, renderer_out);
|
||||
@@ -199,6 +213,47 @@ bool EmbedderTestBackingStoreProducer::CreateSoftware(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmbedderTestBackingStoreProducer::CreateSoftware2(
|
||||
const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out) {
|
||||
const auto color_info = getSkColorInfo(software_pixfmt_);
|
||||
if (!color_info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto surface = SkSurface::MakeRaster(SkImageInfo::Make(
|
||||
SkISize::Make(config->size.width, config->size.height), *color_info));
|
||||
if (!surface) {
|
||||
FML_LOG(ERROR)
|
||||
<< "Could not create the render target for compositor layer.";
|
||||
return false;
|
||||
}
|
||||
|
||||
SkPixmap pixmap;
|
||||
if (!surface->peekPixels(&pixmap)) {
|
||||
FML_LOG(ERROR) << "Could not peek pixels of pixmap.";
|
||||
return false;
|
||||
}
|
||||
|
||||
backing_store_out->type = kFlutterBackingStoreTypeSoftware2;
|
||||
backing_store_out->user_data = surface.get();
|
||||
backing_store_out->software2.struct_size =
|
||||
sizeof(FlutterSoftwareBackingStore2);
|
||||
backing_store_out->software2.user_data = surface.get();
|
||||
backing_store_out->software2.allocation = pixmap.writable_addr();
|
||||
backing_store_out->software2.row_bytes = pixmap.rowBytes();
|
||||
backing_store_out->software2.height = pixmap.height();
|
||||
// The balancing unref is in the destruction callback.
|
||||
surface->ref();
|
||||
backing_store_out->software2.user_data = surface.get();
|
||||
backing_store_out->software2.destruction_callback = [](void* user_data) {
|
||||
reinterpret_cast<SkSurface*>(user_data)->unref();
|
||||
};
|
||||
backing_store_out->software2.pixel_format = software_pixfmt_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EmbedderTestBackingStoreProducer::CreateMTLTexture(
|
||||
const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out) {
|
||||
|
||||
@@ -31,14 +31,17 @@ class EmbedderTestBackingStoreProducer {
|
||||
|
||||
enum class RenderTargetType {
|
||||
kSoftwareBuffer,
|
||||
kSoftwareBuffer2,
|
||||
kOpenGLFramebuffer,
|
||||
kOpenGLTexture,
|
||||
kMetalTexture,
|
||||
kVulkanImage,
|
||||
};
|
||||
|
||||
EmbedderTestBackingStoreProducer(sk_sp<GrDirectContext> context,
|
||||
RenderTargetType type);
|
||||
EmbedderTestBackingStoreProducer(
|
||||
sk_sp<GrDirectContext> context,
|
||||
RenderTargetType type,
|
||||
FlutterSoftwarePixelFormat software_pixfmt = kNative32);
|
||||
~EmbedderTestBackingStoreProducer();
|
||||
|
||||
bool Create(const FlutterBackingStoreConfig* config,
|
||||
@@ -54,6 +57,9 @@ class EmbedderTestBackingStoreProducer {
|
||||
bool CreateSoftware(const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out);
|
||||
|
||||
bool CreateSoftware2(const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* backing_store_out);
|
||||
|
||||
bool CreateMTLTexture(const FlutterBackingStoreConfig* config,
|
||||
FlutterBackingStore* renderer_out);
|
||||
|
||||
@@ -62,6 +68,7 @@ class EmbedderTestBackingStoreProducer {
|
||||
|
||||
sk_sp<GrDirectContext> context_;
|
||||
RenderTargetType type_;
|
||||
FlutterSoftwarePixelFormat software_pixfmt_;
|
||||
|
||||
#ifdef SHELL_ENABLE_METAL
|
||||
std::unique_ptr<TestMetalContext> test_metal_context_;
|
||||
|
||||
@@ -1563,6 +1563,104 @@ TEST_F(EmbedderTest, InvalidFlutterWindowMetricsEvent) {
|
||||
kInvalidArguments);
|
||||
}
|
||||
|
||||
static void expectSoftwareRenderingOutputMatches(
|
||||
EmbedderTest& test,
|
||||
std::string entrypoint,
|
||||
FlutterSoftwarePixelFormat pixfmt,
|
||||
const std::vector<uint8_t>& bytes) {
|
||||
auto& context =
|
||||
test.GetEmbedderContext(EmbedderTestContextType::kSoftwareContext);
|
||||
|
||||
EmbedderConfigBuilder builder(context);
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
bool matches = false;
|
||||
|
||||
builder.SetSoftwareRendererConfig();
|
||||
builder.SetCompositor();
|
||||
builder.SetDartEntrypoint(entrypoint);
|
||||
builder.SetRenderTargetType(
|
||||
EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2,
|
||||
pixfmt);
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
context.GetCompositor().SetNextPresentCallback(
|
||||
[&matches, &bytes, &latch](const FlutterLayer** layers,
|
||||
size_t layers_count) {
|
||||
ASSERT_EQ(layers[0]->type, kFlutterLayerContentTypeBackingStore);
|
||||
ASSERT_EQ(layers[0]->backing_store->type,
|
||||
kFlutterBackingStoreTypeSoftware2);
|
||||
matches = SurfacePixelDataMatchesBytes(
|
||||
(SkSurface*)layers[0]->backing_store->software2.user_data, bytes);
|
||||
latch.Signal();
|
||||
});
|
||||
|
||||
// Send a window metrics events so frames may be scheduled.
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 1;
|
||||
event.height = 1;
|
||||
event.pixel_ratio = 1.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
|
||||
latch.Wait();
|
||||
ASSERT_TRUE(matches);
|
||||
|
||||
engine.reset();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void expectSoftwareRenderingOutputMatches(
|
||||
EmbedderTest& test,
|
||||
std::string entrypoint,
|
||||
FlutterSoftwarePixelFormat pixfmt,
|
||||
T pixelvalue) {
|
||||
uint8_t* bytes = reinterpret_cast<uint8_t*>(&pixelvalue);
|
||||
return expectSoftwareRenderingOutputMatches(
|
||||
test, entrypoint, pixfmt, std::vector<uint8_t>(bytes, bytes + sizeof(T)));
|
||||
}
|
||||
|
||||
#define SW_PIXFMT_TEST_F(dart_entrypoint, pixfmt, matcher) \
|
||||
TEST_F(EmbedderTest, \
|
||||
SoftwareRenderingPixelFormats_##dart_entrypoint##_##pixfmt) { \
|
||||
expectSoftwareRenderingOutputMatches(*this, #dart_entrypoint, pixfmt, \
|
||||
matcher); \
|
||||
}
|
||||
|
||||
// Don't test the pixel formats that contain padding (so an X) and the kNative32
|
||||
// pixel format here, so we don't add any flakiness.
|
||||
SW_PIXFMT_TEST_F(draw_solid_red, kRGB565, (uint16_t)0xF800);
|
||||
SW_PIXFMT_TEST_F(draw_solid_red, kRGBA4444, (uint16_t)0xF00F);
|
||||
SW_PIXFMT_TEST_F(draw_solid_red,
|
||||
kRGBA8888,
|
||||
(std::vector<uint8_t>{0xFF, 0x00, 0x00, 0xFF}));
|
||||
SW_PIXFMT_TEST_F(draw_solid_red,
|
||||
kBGRA8888,
|
||||
(std::vector<uint8_t>{0x00, 0x00, 0xFF, 0xFF}));
|
||||
SW_PIXFMT_TEST_F(draw_solid_red, kGray8, (uint8_t)0x36);
|
||||
|
||||
SW_PIXFMT_TEST_F(draw_solid_green, kRGB565, (uint16_t)0x07E0);
|
||||
SW_PIXFMT_TEST_F(draw_solid_green, kRGBA4444, (uint16_t)0x0F0F);
|
||||
SW_PIXFMT_TEST_F(draw_solid_green,
|
||||
kRGBA8888,
|
||||
(std::vector<uint8_t>{0x00, 0xFF, 0x00, 0xFF}));
|
||||
SW_PIXFMT_TEST_F(draw_solid_green,
|
||||
kBGRA8888,
|
||||
(std::vector<uint8_t>{0x00, 0xFF, 0x00, 0xFF}));
|
||||
SW_PIXFMT_TEST_F(draw_solid_green, kGray8, (uint8_t)0xB6);
|
||||
|
||||
SW_PIXFMT_TEST_F(draw_solid_blue, kRGB565, (uint16_t)0x001F);
|
||||
SW_PIXFMT_TEST_F(draw_solid_blue, kRGBA4444, (uint16_t)0x00FF);
|
||||
SW_PIXFMT_TEST_F(draw_solid_blue,
|
||||
kRGBA8888,
|
||||
(std::vector<uint8_t>{0x00, 0x00, 0xFF, 0xFF}));
|
||||
SW_PIXFMT_TEST_F(draw_solid_blue,
|
||||
kBGRA8888,
|
||||
(std::vector<uint8_t>{0xFF, 0x00, 0x00, 0xFF}));
|
||||
SW_PIXFMT_TEST_F(draw_solid_blue, kGray8, (uint8_t)0x12);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Key Data
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -204,6 +204,53 @@ bool ImageMatchesFixture(const std::string& fixture_file_name,
|
||||
return ImageMatchesFixture(fixture_file_name, scene_image.get());
|
||||
}
|
||||
|
||||
bool SurfacePixelDataMatchesBytes(SkSurface* surface,
|
||||
const std::vector<uint8_t>& bytes) {
|
||||
SkPixmap pixmap;
|
||||
auto ok = surface->peekPixels(&pixmap);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto matches = (pixmap.rowBytes() == bytes.size()) &&
|
||||
(memcmp(bytes.data(), pixmap.addr(), bytes.size()) == 0);
|
||||
|
||||
if (!matches) {
|
||||
FML_LOG(ERROR) << "SkImage pixel data didn't match bytes.";
|
||||
|
||||
{
|
||||
const uint8_t* addr = (const uint8_t*)pixmap.addr();
|
||||
std::stringstream stream;
|
||||
for (size_t i = 0; i < pixmap.computeByteSize(); ++i) {
|
||||
stream << "0x" << std::setfill('0') << std::setw(2) << std::uppercase
|
||||
<< std::hex << static_cast<int>(addr[i]);
|
||||
if (i != pixmap.computeByteSize() - 1) {
|
||||
stream << ", ";
|
||||
}
|
||||
}
|
||||
FML_LOG(ERROR) << " Actual: " << stream.str();
|
||||
}
|
||||
{
|
||||
std::stringstream stream;
|
||||
for (auto b = bytes.begin(); b != bytes.end(); ++b) {
|
||||
stream << "0x" << std::setfill('0') << std::setw(2) << std::uppercase
|
||||
<< std::hex << static_cast<int>(*b);
|
||||
if (b != bytes.end() - 1) {
|
||||
stream << ", ";
|
||||
}
|
||||
}
|
||||
FML_LOG(ERROR) << " Expected: " << stream.str();
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
bool SurfacePixelDataMatchesBytes(std::future<SkSurface*>& surface_future,
|
||||
const std::vector<uint8_t>& bytes) {
|
||||
return SurfacePixelDataMatchesBytes(surface_future.get(), bytes);
|
||||
}
|
||||
|
||||
void FilterMutationsByType(
|
||||
const FlutterPlatformViewMutation** mutations,
|
||||
size_t count,
|
||||
|
||||
@@ -69,6 +69,12 @@ bool ImageMatchesFixture(const std::string& fixture_file_name,
|
||||
bool ImageMatchesFixture(const std::string& fixture_file_name,
|
||||
std::future<sk_sp<SkImage>>& scene_image);
|
||||
|
||||
bool SurfacePixelDataMatchesBytes(SkSurface* surface,
|
||||
const std::vector<uint8_t>& bytes);
|
||||
|
||||
bool SurfacePixelDataMatchesBytes(std::future<SkSurface*>& surface_future,
|
||||
const std::vector<uint8_t>& bytes);
|
||||
|
||||
void FilterMutationsByType(
|
||||
const FlutterPlatformViewMutation** mutations,
|
||||
size_t count,
|
||||
|
||||
Reference in New Issue
Block a user