Flutter Engine
 
Loading...
Searching...
No Matches
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 "third_party/skia/include/core/SkCanvas.h"
17#include "third_party/skia/include/core/SkColorSpace.h"
18#include "third_party/skia/include/core/SkSurface.h"
19#include "third_party/skia/include/encode/SkPngEncoder.h"
20#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
21#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
22#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.h"
23#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
24#include "wrappers.h"
25
26namespace flutter {
27class DisplayList;
28}
29
30namespace Skwasm {
31// This must be kept in sync with the `ImageByteFormat` enum in dart:ui.
32enum class ImageByteFormat {
33 rawRgba,
36 png,
37};
38
40 public:
41 TextureSourceWrapper(unsigned long threadId, SkwasmObject textureSource);
43
45
46 private:
47 unsigned long _rasterThreadId;
48};
49
50class Surface {
51 public:
52 using CallbackHandler = void(uint32_t, void*, SkwasmObject);
53
54 // Main thread only
56
57 unsigned long getThreadId() { return _thread; }
58
59 // Main thread only
60 void dispose();
61 void setResourceCacheLimit(int bytes);
63 int width,
64 int height,
65 int count);
66 uint32_t rasterizeImage(SkImage* image, ImageByteFormat format);
67 void setCallbackHandler(CallbackHandler* callbackHandler);
68 void onRenderComplete(uint32_t callbackId, SkwasmObject imageBitmap);
69 void onRasterizeComplete(uint32_t callbackId, SkData* data);
70
71 // Any thread
72 std::unique_ptr<TextureSourceWrapper> createTextureSourceWrapper(
73 SkwasmObject textureSource);
74
75 // Worker thread
76 void renderPicturesOnWorker(sk_sp<flutter::DisplayList>* picture,
77 int width,
78 int height,
79 int pictureCount,
80 uint32_t callbackId,
81 double rasterStart);
83 ImageByteFormat format,
84 uint32_t callbackId);
85
86 private:
87 void _init();
88 void _resizeSurface(int width, int height);
89 void _recreateSurface();
90
91 CallbackHandler* _callbackHandler = nullptr;
92 uint32_t _currentCallbackId = 0;
93
94 int _canvasWidth = 0;
95 int _canvasHeight = 0;
96
97 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE _glContext = 0;
98 sk_sp<GrDirectContext> _grContext = nullptr;
99 sk_sp<SkSurface> _surface = nullptr;
100 GrGLFramebufferInfo _fbInfo;
101 GrGLint _sampleCount;
102 GrGLint _stencil;
103
104 pthread_t _thread;
105
106 bool _isInitialized = false;
107};
108} // namespace Skwasm
109
110#endif // FLUTTER_LIB_WEB_UI_SKWASM_SURFACE_H_
unsigned long getThreadId()
Definition surface.h:57
void onRasterizeComplete(uint32_t callbackId, SkData *data)
void renderPicturesOnWorker(sk_sp< flutter::DisplayList > *picture, int width, int height, int pictureCount, uint32_t callbackId, double rasterStart)
void setResourceCacheLimit(int bytes)
std::unique_ptr< TextureSourceWrapper > createTextureSourceWrapper(SkwasmObject textureSource)
uint32_t rasterizeImage(SkImage *image, ImageByteFormat format)
void(uint32_t, void *, SkwasmObject) CallbackHandler
Definition surface.h:52
uint32_t renderPictures(flutter::DisplayList **picture, int width, int height, int count)
void onRenderComplete(uint32_t callbackId, SkwasmObject imageBitmap)
void rasterizeImageOnWorker(SkImage *image, ImageByteFormat format, uint32_t callbackId)
void setCallbackHandler(CallbackHandler *callbackHandler)
TextureSourceWrapper(unsigned long threadId, SkwasmObject textureSource)
SkwasmObject getTextureSource()
FlutterVulkanImage * image
__externref_t SkwasmObject
Definition wrappers.h:16
ImageByteFormat
Definition surface.h:32
flutter::DisplayList DisplayList
int32_t height
int32_t width
std::shared_ptr< const fml::Mapping > data