Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Skwasm::Surface Class Reference

#include <surface.h>

Public Types

using CallbackHandler = void(uint32_t, void *, SkwasmObject)
 

Public Member Functions

 Surface ()
 
unsigned long getThreadId ()
 
void dispose ()
 
uint32_t renderPictures (SkPicture **picture, int count)
 
uint32_t rasterizeImage (SkImage *image, ImageByteFormat format)
 
void setCallbackHandler (CallbackHandler *callbackHandler)
 
void onRenderComplete (uint32_t callbackId, SkwasmObject imageBitmap)
 
std::unique_ptr< TextureSourceWrappercreateTextureSourceWrapper (SkwasmObject textureSource)
 
void renderPicturesOnWorker (sk_sp< SkPicture > *picture, int pictureCount, uint32_t callbackId, double rasterStart)
 

Detailed Description

Definition at line 54 of file surface.h.

Member Typedef Documentation

◆ CallbackHandler

using Skwasm::Surface::CallbackHandler = void(uint32_t, void*, SkwasmObject)

Definition at line 56 of file surface.h.

Constructor & Destructor Documentation

◆ Surface()

Surface::Surface ( )

Definition at line 15 of file surface.cpp.

15 {
16 assert(emscripten_is_main_browser_thread());
17
18 pthread_attr_t attr;
19 pthread_attr_init(&attr);
20 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
21
22 pthread_create(
23 &_thread, &attr,
24 [](void* context) -> void* {
25 static_cast<Surface*>(context)->_runWorker();
26 return nullptr;
27 },
28 this);
29 // Listen to messages from the worker
31
32 // Synchronize the time origin for the worker thread
34}
void skwasm_syncTimeOriginForThread(pthread_t threadId)
void skwasm_registerMessageListener(pthread_t threadId)

Member Function Documentation

◆ createTextureSourceWrapper()

std::unique_ptr< TextureSourceWrapper > Surface::createTextureSourceWrapper ( SkwasmObject  textureSource)

Definition at line 73 of file surface.cpp.

74 {
75 return std::unique_ptr<TextureSourceWrapper>(
76 new TextureSourceWrapper(_thread, textureSource));
77}

◆ dispose()

void Surface::dispose ( )

Definition at line 37 of file surface.cpp.

37 {
38 assert(emscripten_is_main_browser_thread());
39 emscripten_dispatch_to_thread(_thread, EM_FUNC_SIG_VI,
40 reinterpret_cast<void*>(fDispose), nullptr,
41 this);
42}

◆ getThreadId()

unsigned long Skwasm::Surface::getThreadId ( )
inline

Definition at line 61 of file surface.h.

61{ return _thread; }

◆ onRenderComplete()

void Surface::onRenderComplete ( uint32_t  callbackId,
SkwasmObject  imageBitmap 
)

Definition at line 209 of file surface.cpp.

209 {
210 assert(emscripten_is_main_browser_thread());
211 _callbackHandler(callbackId, nullptr, imageBitmap);
212}

◆ rasterizeImage()

uint32_t Surface::rasterizeImage ( SkImage image,
ImageByteFormat  format 
)

Definition at line 62 of file surface.cpp.

62 {
63 assert(emscripten_is_main_browser_thread());
64 uint32_t callbackId = ++_currentCallbackId;
65 image->ref();
66
67 emscripten_dispatch_to_thread(_thread, EM_FUNC_SIG_VIIII,
68 reinterpret_cast<void*>(fRasterizeImage),
69 nullptr, this, image, format, callbackId);
70 return callbackId;
71}
void ref() const
Definition SkRefCnt.h:62
sk_sp< SkImage > image
Definition examples.cpp:29
uint32_t uint32_t * format

◆ renderPictures()

uint32_t Surface::renderPictures ( SkPicture **  picture,
int  count 
)

Definition at line 45 of file surface.cpp.

45 {
46 assert(emscripten_is_main_browser_thread());
47 uint32_t callbackId = ++_currentCallbackId;
48 std::unique_ptr<sk_sp<SkPicture>[]> picturePointers =
49 std::make_unique<sk_sp<SkPicture>[]>(count);
50 for (int i = 0; i < count; i++) {
51 picturePointers[i] = sk_ref_sp(pictures[i]);
52 }
53
54 // Releasing picturePointers here and will recreate the unique_ptr on the
55 // other thread See surface_renderPicturesOnWorker
56 skwasm_dispatchRenderPictures(_thread, this, picturePointers.release(), count,
57 callbackId);
58 return callbackId;
59}
int count
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
void skwasm_dispatchRenderPictures(unsigned long threadId, Skwasm::Surface *surface, sk_sp< SkPicture > *pictures, int count, uint32_t callbackId)

◆ renderPicturesOnWorker()

void Surface::renderPicturesOnWorker ( sk_sp< SkPicture > *  picture,
int  pictureCount,
uint32_t  callbackId,
double  rasterStart 
)

Definition at line 150 of file surface.cpp.

153 {
154 // This is populated by the `captureImageBitmap` call the first time it is
155 // passed in.
156 SkwasmObject imagePromiseArray = __builtin_wasm_ref_null_extern();
157 for (int i = 0; i < pictureCount; i++) {
158 sk_sp<SkPicture> picture = pictures[i];
159 SkRect pictureRect = picture->cullRect();
160 SkIRect roundedOutRect;
161 pictureRect.roundOut(&roundedOutRect);
162 _resizeCanvasToFit(roundedOutRect.width(), roundedOutRect.height());
164 SkMatrix::Translate(-roundedOutRect.fLeft, -roundedOutRect.fTop);
165 makeCurrent(_glContext);
166 auto canvas = _surface->getCanvas();
168 canvas->drawPicture(picture, &matrix, nullptr);
169 _grContext->flush(_surface.get());
170 imagePromiseArray =
171 skwasm_captureImageBitmap(_glContext, roundedOutRect.width(),
172 roundedOutRect.height(), imagePromiseArray);
173 }
174 skwasm_resolveAndPostImages(this, imagePromiseArray, rasterStart, callbackId);
175}
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
virtual SkRect cullRect() const =0
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
T * get() const
Definition SkRefCnt.h:303
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
sk_sp< const SkPicture > picture
Definition SkRecords.h:299
void makeCurrent(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE handle)
Definition wrappers.h:22
SkwasmObject skwasm_captureImageBitmap(uint32_t contextHandle, int width, int height, SkwasmObject imagePromises)
void skwasm_resolveAndPostImages(Skwasm::Surface *surface, SkwasmObject imagePromises, double rasterStart, uint32_t callbackId)
__externref_t SkwasmObject
constexpr int32_t height() const
Definition SkRect.h:165
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
constexpr int32_t width() const
Definition SkRect.h:158
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
void roundOut(SkIRect *dst) const
Definition SkRect.h:1241

◆ setCallbackHandler()

void Surface::setCallbackHandler ( CallbackHandler callbackHandler)

Definition at line 80 of file surface.cpp.

80 {
81 assert(emscripten_is_main_browser_thread());
82 _callbackHandler = callbackHandler;
83}

The documentation for this class was generated from the following files: