Flutter Engine
The Flutter Engine
lib
web_ui
skwasm
surface.h
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
#ifndef FLUTTER_LIB_WEB_UI_SKWASM_SURFACE_H_
6
#define FLUTTER_LIB_WEB_UI_SKWASM_SURFACE_H_
7
8
#include <GLES2/gl2.h>
9
#include <GLES2/gl2ext.h>
10
#include <emscripten.h>
11
#include <emscripten/html5_webgl.h>
12
#include <emscripten/threading.h>
13
#include <webgl/webgl1.h>
14
#include <cassert>
15
#include "
export.h
"
16
#include "
skwasm_support.h
"
17
#include "
third_party/skia/include/core/SkCanvas.h
"
18
#include "
third_party/skia/include/core/SkColorSpace.h
"
19
#include "
third_party/skia/include/core/SkPicture.h
"
20
#include "
third_party/skia/include/core/SkSurface.h
"
21
#include "
third_party/skia/include/encode/SkPngEncoder.h
"
22
#include "
third_party/skia/include/gpu/GrDirectContext.h
"
23
#include "
third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h
"
24
#include "
third_party/skia/include/gpu/gl/GrGLInterface.h
"
25
#include "
third_party/skia/include/gpu/gl/GrGLTypes.h
"
26
#include "
wrappers.h
"
27
28
namespace
Skwasm
{
29
// This must be kept in sync with the `ImageByteFormat` enum in dart:ui.
30
enum class
ImageByteFormat
{
31
rawRgba
,
32
rawStraightRgba
,
33
rawUnmodified
,
34
png
,
35
};
36
37
class
TextureSourceWrapper
{
38
public
:
39
TextureSourceWrapper
(
unsigned
long
threadId,
SkwasmObject
textureSource)
40
: _rasterThreadId(threadId) {
41
skwasm_setAssociatedObjectOnThread
(_rasterThreadId,
this
, textureSource);
42
}
43
44
~TextureSourceWrapper
() {
45
skwasm_disposeAssociatedObjectOnThread
(_rasterThreadId,
this
);
46
}
47
48
SkwasmObject
getTextureSource
() {
return
skwasm_getAssociatedObject
(
this
); }
49
50
private
:
51
unsigned
long
_rasterThreadId;
52
};
53
54
class
Surface
{
55
public
:
56
using
CallbackHandler
= void(uint32_t,
void
*,
SkwasmObject
);
57
58
// Main thread only
59
Surface
();
60
61
unsigned
long
getThreadId
() {
return
_thread; }
62
63
// Main thread only
64
void
dispose
();
65
uint32_t
renderPictures
(
SkPicture
**
picture
,
int
count
);
66
uint32_t
rasterizeImage
(
SkImage
*
image
,
ImageByteFormat
format
);
67
void
setCallbackHandler
(
CallbackHandler
* callbackHandler);
68
void
onRenderComplete
(uint32_t callbackId,
SkwasmObject
imageBitmap);
69
70
// Any thread
71
std::unique_ptr<TextureSourceWrapper>
createTextureSourceWrapper
(
72
SkwasmObject
textureSource);
73
74
// Worker thread
75
void
renderPicturesOnWorker
(
sk_sp<SkPicture>
*
picture
,
76
int
pictureCount,
77
uint32_t callbackId,
78
double
rasterStart);
79
80
private
:
81
void
_runWorker();
82
void
_init();
83
void
_dispose();
84
void
_resizeCanvasToFit(
int
width
,
int
height
);
85
void
_recreateSurface();
86
void
_rasterizeImage(
SkImage
*
image
,
87
ImageByteFormat
format
,
88
uint32_t callbackId);
89
void
_onRasterizeComplete(
SkData
*
data
, uint32_t callbackId);
90
91
std::string _canvasID;
92
CallbackHandler
* _callbackHandler =
nullptr
;
93
uint32_t _currentCallbackId = 0;
94
95
int
_canvasWidth = 0;
96
int
_canvasHeight = 0;
97
98
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE _glContext = 0;
99
sk_sp<GrDirectContext>
_grContext =
nullptr
;
100
sk_sp<SkSurface>
_surface =
nullptr
;
101
GrGLFramebufferInfo
_fbInfo;
102
GrGLint
_sampleCount;
103
GrGLint
_stencil;
104
105
pthread_t _thread;
106
107
static
void
fDispose(
Surface
*
surface
);
108
static
void
fOnRenderComplete(
Surface
*
surface
,
109
uint32_t callbackId,
110
SkwasmObject
imageBitmap);
111
static
void
fRasterizeImage(
Surface
*
surface
,
112
SkImage
*
image
,
113
ImageByteFormat
format
,
114
uint32_t callbackId);
115
static
void
fOnRasterizeComplete(
Surface
*
surface
,
116
SkData
* imageData,
117
uint32_t callbackId);
118
};
119
}
// namespace Skwasm
120
121
#endif
// FLUTTER_LIB_WEB_UI_SKWASM_SURFACE_H_
count
int count
Definition:
FontMgrTest.cpp:50
GrDirectContext.h
GrGLInterface.h
GrGLTypes.h
GrGLint
int GrGLint
Definition:
GrGLTypes.h:108
SkCanvas.h
SkColorSpace.h
SkPicture.h
SkPngEncoder.h
SkSurfaceGanesh.h
SkSurface.h
SkData
Definition:
SkData.h:25
SkImage
Definition:
SkImage.h:272
SkPicture
Definition:
SkPicture.h:44
Skwasm::Surface
Definition:
surface.h:54
Skwasm::Surface::getThreadId
unsigned long getThreadId()
Definition:
surface.h:61
Skwasm::Surface::dispose
void dispose()
Definition:
surface.cpp:38
Skwasm::Surface::createTextureSourceWrapper
std::unique_ptr< TextureSourceWrapper > createTextureSourceWrapper(SkwasmObject textureSource)
Definition:
surface.cpp:74
Skwasm::Surface::setCallbackHandler
void setCallbackHandler(CallbackHandler *callbackHandler)
Definition:
surface.cpp:81
Skwasm::Surface::CallbackHandler
void(uint32_t, void *, SkwasmObject) CallbackHandler
Definition:
surface.h:56
Skwasm::Surface::Surface
Surface()
Definition:
surface.cpp:16
Skwasm::Surface::onRenderComplete
void onRenderComplete(uint32_t callbackId, SkwasmObject imageBitmap)
Definition:
surface.cpp:210
Skwasm::Surface::rasterizeImage
uint32_t rasterizeImage(SkImage *image, ImageByteFormat format)
Definition:
surface.cpp:63
Skwasm::Surface::renderPicturesOnWorker
void renderPicturesOnWorker(sk_sp< SkPicture > *picture, int pictureCount, uint32_t callbackId, double rasterStart)
Definition:
surface.cpp:151
Skwasm::Surface::renderPictures
uint32_t renderPictures(SkPicture **picture, int count)
Definition:
surface.cpp:46
Skwasm::TextureSourceWrapper
Definition:
surface.h:37
Skwasm::TextureSourceWrapper::TextureSourceWrapper
TextureSourceWrapper(unsigned long threadId, SkwasmObject textureSource)
Definition:
surface.h:39
Skwasm::TextureSourceWrapper::getTextureSource
SkwasmObject getTextureSource()
Definition:
surface.h:48
Skwasm::TextureSourceWrapper::~TextureSourceWrapper
~TextureSourceWrapper()
Definition:
surface.h:44
sk_sp< SkPicture >
surface
VkSurfaceKHR surface
Definition:
main.cc:49
format
uint32_t uint32_t * format
Definition:
fl_texture_registrar_test.cc:41
SkRecords::image
sk_sp< const SkImage > image
Definition:
SkRecords.h:269
SkRecords::picture
sk_sp< const SkPicture > picture
Definition:
SkRecords.h:299
Skwasm
Definition:
helpers.h:12
Skwasm::ImageByteFormat
ImageByteFormat
Definition:
surface.h:30
Skwasm::ImageByteFormat::rawRgba
@ rawRgba
Skwasm::ImageByteFormat::rawUnmodified
@ rawUnmodified
Skwasm::ImageByteFormat::png
@ png
Skwasm::ImageByteFormat::rawStraightRgba
@ rawStraightRgba
height
int32_t height
Definition:
serialization_callbacks.cc:1
width
int32_t width
Definition:
serialization_callbacks.cc:0
skwasm_support.h
skwasm_disposeAssociatedObjectOnThread
void skwasm_disposeAssociatedObjectOnThread(unsigned long threadId, void *pointer)
skwasm_getAssociatedObject
SkwasmObject skwasm_getAssociatedObject(void *pointer)
skwasm_setAssociatedObjectOnThread
void skwasm_setAssociatedObjectOnThread(unsigned long threadId, void *pointer, SkwasmObject object)
SkwasmObject
__externref_t SkwasmObject
Definition:
skwasm_support.h:16
GrGLFramebufferInfo
Definition:
GrGLTypes.h:196
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
export.h
wrappers.h
Generated on Sun Jun 23 2024 21:54:57 for Flutter Engine by
1.9.4