8#include <GLES2/gl2ext.h>
9#include <emscripten/html5_webgl.h>
15#include "third_party/skia/include/core/SkColorSpace.h"
16#include "third_party/skia/include/core/SkData.h"
17#include "third_party/skia/include/core/SkImage.h"
18#include "third_party/skia/include/core/SkImageInfo.h"
19#include "third_party/skia/include/core/SkPicture.h"
20#include "third_party/skia/include/core/SkPictureRecorder.h"
21#include "third_party/skia/include/gpu/GpuTypes.h"
22#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
23#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
24#include "third_party/skia/include/gpu/ganesh/GrExternalTextureGenerator.h"
25#include "third_party/skia/include/gpu/ganesh/SkImageGanesh.h"
26#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
27#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
28#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.h"
29#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
36 return SkColorType::kRGBA_8888_SkColorType;
38 return SkColorType::kBGRA_8888_SkColorType;
40 return SkColorType::kRGBA_F32_SkColorType;
48 return SkAlphaType::kPremul_SkAlphaType;
50 return SkAlphaType::kUnpremul_SkAlphaType;
54class ExternalWebGLTexture :
public GrExternalTexture {
56 ExternalWebGLTexture(GrBackendTexture backend_texture,
58 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
59 : backend_texture_(backend_texture),
61 web_gl_context_(context) {}
63 GrBackendTexture getBackendTexture()
override {
return backend_texture_; }
65 void dispose()
override {
67 glDeleteTextures(1, &texture_id_);
71 GrBackendTexture backend_texture_;
73 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE web_gl_context_;
76class TextureSourceImageGenerator :
public GrExternalTextureGenerator {
78 TextureSourceImageGenerator(SkImageInfo ii,
81 : GrExternalTextureGenerator(ii),
82 texture_source_wrapper_(
83 surface->CreateTextureSourceWrapper(texture_source)) {}
85 std::unique_ptr<GrExternalTexture> generateExternalTexture(
86 GrRecordingContext* context,
87 skgpu::Mipmapped mipmapped)
override {
88 GrGLTextureInfo gl_info;
90 texture_source_wrapper_->GetTextureSource(), fInfo.width(),
92 gl_info.fFormat = GL_RGBA8_OES;
93 gl_info.fTarget = GL_TEXTURE_2D;
95 auto backend_texture = GrBackendTextures::MakeGL(
96 fInfo.width(), fInfo.height(), skgpu::Mipmapped::kNo, gl_info);
100 GrAsDirectContext(context)->resetContext(kTextureBinding_GrGLBackendState);
101 return std::make_unique<ExternalWebGLTexture>(
102 backend_texture, gl_info.fID, emscripten_webgl_get_current_context());
106 std::unique_ptr<Skwasm::TextureSourceWrapper> texture_source_wrapper_;
116 SkPictureRecorder recorder;
120 dispatcher.drawDisplayList(sk_ref_sp(display_list), 1.0f);
123 recorder.finishRecordingAsPicture(), {width, height},
nullptr,
nullptr,
124 SkImages::BitDepth::kU8, SkColorSpace::MakeSRGB()));
132 std::unique_ptr<TextureSourceImageGenerator>(
133 new TextureSourceImageGenerator(
135 SkColorType::kRGBA_8888_SkColorType,
136 SkAlphaType::kPremul_SkAlphaType),
137 texture_source, surface))));
144 size_t row_byte_count) {
146 SkImageInfo::Make(
width,
height, ColorTypeForPixelFormat(pixel_format),
147 AlphaTypeForPixelFormat(pixel_format),
148 SkColorSpace::MakeSRGB()),
149 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)