8#include <GLES2/gl2ext.h>
9#include <emscripten/html5_webgl.h>
14#include "third_party/skia/include/core/SkColorSpace.h"
15#include "third_party/skia/include/core/SkData.h"
16#include "third_party/skia/include/core/SkImage.h"
17#include "third_party/skia/include/core/SkImageInfo.h"
18#include "third_party/skia/include/core/SkPicture.h"
19#include "third_party/skia/include/core/SkPictureRecorder.h"
20#include "third_party/skia/include/gpu/GpuTypes.h"
21#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
22#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
23#include "third_party/skia/include/gpu/ganesh/GrExternalTextureGenerator.h"
24#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
25#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
26#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
27#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.h"
28#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
35 return SkColorType::kRGBA_8888_SkColorType;
37 return SkColorType::kBGRA_8888_SkColorType;
39 return SkColorType::kRGBA_F32_SkColorType;
47 return SkAlphaType::kPremul_SkAlphaType;
49 return SkAlphaType::kUnpremul_SkAlphaType;
53class ExternalWebGLTexture :
public GrExternalTexture {
55 ExternalWebGLTexture(GrBackendTexture backend_texture,
57 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
58 : backend_texture_(backend_texture),
60 web_gl_context_(context) {}
62 GrBackendTexture getBackendTexture()
override {
return backend_texture_; }
64 void dispose()
override {
66 glDeleteTextures(1, &texture_id_);
70 GrBackendTexture backend_texture_;
72 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE web_gl_context_;
75class TextureSourceImageGenerator :
public GrExternalTextureGenerator {
77 TextureSourceImageGenerator(SkImageInfo ii,
80 : GrExternalTextureGenerator(ii),
81 texture_source_wrapper_(
82 surface->CreateTextureSourceWrapper(texture_source)) {}
84 std::unique_ptr<GrExternalTexture> generateExternalTexture(
85 GrRecordingContext* context,
86 skgpu::Mipmapped mipmapped)
override {
87 GrGLTextureInfo gl_info;
89 texture_source_wrapper_->GetTextureSource(), fInfo.width(),
91 gl_info.fFormat = GL_RGBA8_OES;
92 gl_info.fTarget = GL_TEXTURE_2D;
94 auto backend_texture = GrBackendTextures::MakeGL(
95 fInfo.width(), fInfo.height(), skgpu::Mipmapped::kNo, gl_info);
99 GrAsDirectContext(context)->resetContext(kTextureBinding_GrGLBackendState);
100 return std::make_unique<ExternalWebGLTexture>(
101 backend_texture, gl_info.fID, emscripten_webgl_get_current_context());
105 std::unique_ptr<Skwasm::TextureSourceWrapper> texture_source_wrapper_;
115 SkPictureRecorder recorder;
119 dispatcher.drawDisplayList(sk_ref_sp(display_list), 1.0f);
122 recorder.finishRecordingAsPicture(), {width, height},
nullptr,
nullptr,
123 SkImages::BitDepth::kU8, SkColorSpace::MakeSRGB()));
131 std::unique_ptr<TextureSourceImageGenerator>(
132 new TextureSourceImageGenerator(
134 SkColorType::kRGBA_8888_SkColorType,
135 SkAlphaType::kPremul_SkAlphaType),
136 texture_source, surface))));
143 size_t row_byte_count) {
145 SkImageInfo::Make(
width,
height, ColorTypeForPixelFormat(pixel_format),
146 AlphaTypeForPixelFormat(pixel_format),
147 SkColorSpace::MakeSRGB()),
148 sk_ref_sp(
data), row_byte_count));
const DlRect & GetBounds() const
static sk_sp< DlImage > Make(const SkImage *image)
Backend implementation of |DlOpReceiver| for |SkCanvas|.
sk_sp< flutter::DlImage > MakeImageFromTexture(SkwasmObject texture_source, int width, int height, Skwasm::Surface *surface)
__externref_t SkwasmObject
void makeCurrent(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE handle)
sk_sp< flutter::DlImage > MakeImageFromPicture(flutter::DisplayList *display_list, int32_t width, int32_t height)
sk_sp< flutter::DlImage > MakeImageFromPixels(SkData *data, int width, int height, PixelFormat pixel_format, size_t row_byte_count)
const SkRect & ToSkRect(const DlRect &rect)
__externref_t SkwasmObject
unsigned int skwasm_createGlTextureFromTextureSource(SkwasmObject texture_source, int width, int height)
std::shared_ptr< const fml::Mapping > data