| Flutter Impeller |

surface.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
5 #include "impeller/toolkit/interop/surface.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/display_list/aiks_context.h"
9 #include "impeller/display_list/dl_dispatcher.h"
10 #include "impeller/renderer/backend/gles/surface_gles.h"
11 #include "impeller/toolkit/interop/formats.h"
12
13 namespace impeller::interop {
14
15 Surface::Surface(Context& context, std::shared_ptr<impeller::Surface> surface)
16 : context_(Ref(&context)), surface_(std::move(surface)) {
17 is_valid_ =
18 context_ && context_->IsValid() && surface_ && surface_->IsValid();
19 }
20
21 Surface::~Surface() = default;
22
23 ScopedObject<Surface> Surface::WrapFBO(Context& context,
24 uint64_t fbo,
25 PixelFormat color_format,
26 ISize size) {
27 if (context.GetContext()->GetBackendType() !=
28 impeller::Context::BackendType::kOpenGLES) {
29 VALIDATION_LOG << "Context is not OpenGL ES based.";
30 return nullptr;
31 }
32
33 auto impeller_surface = impeller::SurfaceGLES::WrapFBO(
34 context.GetContext(), []() { return true; }, fbo, color_format, size);
35 if (!impeller_surface || !impeller_surface->IsValid()) {
36 VALIDATION_LOG << "Could not wrap FBO as a surface";
37 return nullptr;
38 }
39
40 auto surface = Create<Surface>(context, std::move(impeller_surface));
41 if (!surface->IsValid()) {
42 VALIDATION_LOG << "Could not create valid surface.";
43 return nullptr;
44 }
45 return surface;
46 }
47
48 bool Surface::IsValid() const {
49 return is_valid_;
50 }
51
52 bool Surface::DrawDisplayList(const DisplayList& dl) const {
53 if (!IsValid() || !dl.IsValid()) {
54 return false;
55 }
56
57 auto display_list = dl.GetDisplayList();
58 auto& content_context = context_->GetAiksContext().GetContentContext();
59 auto render_target = surface_->GetRenderTarget();
60
61 const auto cull_rect = IRect::MakeSize(surface_->GetSize());
62 auto skia_cull_rect =
63 SkIRect::MakeWH(cull_rect.GetWidth(), cull_rect.GetHeight());
64
65 auto result = RenderToTarget(content_context, render_target, display_list,
66 skia_cull_rect, /*reset_host_buffer=*/true);
67 context_->GetContext()->ResetThreadLocalState();
68 return result;
69 }
70
71 } // namespace impeller::interop
aiks_context.h
impeller::Context::BackendType::kOpenGLES
@ kOpenGLES
impeller::SurfaceGLES::WrapFBO
static std::unique_ptr< Surface > WrapFBO(const std::shared_ptr< Context > &context, SwapCallback swap_callback, GLuint fbo, PixelFormat color_format, ISize fbo_size)
Definition: surface_gles.cc:14
impeller::interop::Context
Definition: context.h:18
impeller::interop::Context::GetContext
std::shared_ptr< impeller::Context > GetContext() const
Definition: context.cc:37
impeller::interop::DisplayList
Definition: dl.h:16
impeller::interop::DisplayList::GetDisplayList
const sk_sp< flutter::DisplayList > GetDisplayList() const
Definition: dl.cc:18
impeller::interop::DisplayList::IsValid
bool IsValid() const
Definition: dl.cc:14
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop::Surface::IsValid
bool IsValid() const
Definition: surface.cc:48
impeller::interop::Surface::Surface
Surface(Context &context, std::shared_ptr< impeller::Surface > surface)
Definition: surface.cc:15
impeller::interop::Surface::WrapFBO
static ScopedObject< Surface > WrapFBO(Context &context, uint64_t fbo, PixelFormat color_format, ISize size)
Definition: surface.cc:23
impeller::interop::Surface::DrawDisplayList
bool DrawDisplayList(const DisplayList &dl) const
Definition: surface.cc:52
impeller::interop::Surface::~Surface
~Surface() override
dl_dispatcher.h
impeller::interop
Definition: color_filter.cc:7
impeller::interop::Ref
ScopedObject< Object > Ref(Object *object)
Definition: object.h:145
impeller::RenderToTarget
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, SkIRect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
Definition: dl_dispatcher.cc:1314
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
std
Definition: comparable.h:95
impeller::TRect::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
impeller::TSize
Definition: size.h:25
surface_gles.h
formats.h
surface.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91