Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
render_context_skia.cc
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
6
7#include <GLES2/gl2.h>
8#include <GLES2/gl2ext.h>
9
12#include "third_party/skia/include/core/SkSurface.h"
13#include "third_party/skia/include/gpu/ganesh/GrBackendSurface.h"
14#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
15#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
16#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
17#include "third_party/skia/include/gpu/ganesh/gl/GrGLDirectContext.h"
18#include "third_party/skia/include/gpu/ganesh/gl/GrGLInterface.h"
19#include "third_party/skia/include/gpu/ganesh/gl/GrGLMakeWebGLInterface.h"
20#include "third_party/skia/include/gpu/ganesh/gl/GrGLTypes.h"
21
23 return false;
24}
25
26namespace {
27class SkiaRenderContext : public Skwasm::RenderContext {
28 public:
29 SkiaRenderContext(int sample_count, int stencil)
30 : sample_count_(sample_count),
31 stencil_(stencil),
32 gr_context_(GrDirectContexts::MakeGL(GrGLInterfaces::MakeWebGL())),
33 fb_info_({0, GL_RGBA8_OES}) {
34 gr_context_->resetContext(kRenderTarget_GrGLBackendState |
35 kMisc_GrGLBackendState);
36 }
37
38 virtual void RenderPicture(
39 const sk_sp<flutter::DisplayList> display_list) override {
40 auto canvas = surface_->getCanvas();
41 canvas->drawColor(SK_ColorTRANSPARENT, SkBlendMode::kSrc);
42 auto dispatcher = flutter::DlSkCanvasDispatcher(canvas);
43 dispatcher.save();
44 dispatcher.drawDisplayList(display_list, 1.0f);
45 dispatcher.restore();
46
47 gr_context_->flush(surface_.get());
48 }
49
51 Skwasm::ImageByteFormat format) override {
52 auto canvas = surface_->getCanvas();
53 canvas->drawColor(SK_ColorTRANSPARENT, SkBlendMode::kSrc);
54
55 // We want the pixels from the upper left corner, but glReadPixels gives us
56 // the pixels from the lower left corner. So we have to flip the image when
57 // we are drawing it to get the pixels in the desired order.
58 canvas->save();
59 canvas->scale(1, -1);
60 canvas->drawImage(image->skia_image(), 0, -height_);
61 canvas->restore();
62 gr_context_->flush(surface_.get());
63 }
64
65 virtual void Resize(int width, int height) override {
66 if (width_ != width || height_ != height) {
67 width_ = width;
68 height_ = height;
69 auto target = GrBackendRenderTargets::MakeGL(width, height, sample_count_,
70 stencil_, fb_info_);
71 surface_ = SkSurfaces::WrapBackendRenderTarget(
72 gr_context_.get(), target, kBottomLeft_GrSurfaceOrigin,
73 kRGBA_8888_SkColorType, SkColorSpace::MakeSRGB(), nullptr);
74 }
75 }
76
77 virtual void SetResourceCacheLimit(int bytes) override {
78 gr_context_->setResourceCacheLimit(bytes);
79 }
80
81 private:
82 sk_sp<GrDirectContext> gr_context_ = nullptr;
83 sk_sp<SkSurface> surface_ = nullptr;
84 GrGLFramebufferInfo fb_info_;
85 GrGLint sample_count_;
86 GrGLint stencil_;
87 int width_ = 0;
88 int height_ = 0;
89};
90} // namespace
91
92std::unique_ptr<Skwasm::RenderContext> Skwasm::RenderContext::Make(
93 int sample_count,
94 int stencil) {
95 return std::make_unique<SkiaRenderContext>(sample_count, stencil);
96}
virtual void RenderImage(flutter::DlImage *image, ImageByteFormat format)=0
virtual void RenderPicture(const sk_sp< flutter::DisplayList > display_list)=0
static std::unique_ptr< RenderContext > Make(int sample_count, int stencil)
virtual void Resize(int width, int height)=0
virtual void SetResourceCacheLimit(int bytes)=0
Represents an image whose allocation is (usually) resident on device memory.
Definition dl_image.h:32
Backend implementation of |DlOpReceiver| for |SkCanvas|.
FlutterVulkanImage * image
uint32_t * target
EGLSurface surface_
ImageByteFormat
Definition helpers.h:75
SKWASM_EXPORT bool skwasm_isWimp()
int32_t height
int32_t width
#define SKWASM_EXPORT
Definition export.h:10