| 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/toolkit/interop/formats.h"
11
12 namespace impeller::interop {
13
14 Surface::Surface(Context& context, std::shared_ptr<impeller::Surface> surface)
15 : context_(Ref(&context)), surface_(std::move(surface)) {
16 is_valid_ =
17 context_ && context_->IsValid() && surface_ && surface_->IsValid();
18 }
19
20 Surface::~Surface() = default;
21
22 bool Surface::IsValid() const {
23 return is_valid_;
24 }
25
26 bool Surface::DrawDisplayList(const DisplayList& dl) const {
27 if (!IsValid() || !dl.IsValid()) {
28 return false;
29 }
30
31 auto display_list = dl.GetDisplayList();
32 auto& content_context = context_->GetAiksContext().GetContentContext();
33 auto render_target = surface_->GetRenderTarget();
34
35 const auto cull_rect = Rect::MakeSize(surface_->GetSize());
36
37 auto result = RenderToTarget(content_context, render_target, display_list,
38 cull_rect, /*reset_host_buffer=*/true);
39 context_->GetContext()->ResetThreadLocalState();
40 return result;
41 }
42
43 bool Surface::Present() const {
44 if (!IsValid()) {
45 return false;
46 }
47 return surface_->Present();
48 }
49
50 } // namespace impeller::interop
aiks_context.h
impeller::interop::Context
Definition: context.h:16
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::Surface::IsValid
bool IsValid() const
Definition: surface.cc:22
impeller::interop::Surface::Present
bool Present() const
Definition: surface.cc:43
impeller::interop::Surface::DrawDisplayList
bool DrawDisplayList(const DisplayList &dl) const
Definition: surface.cc:26
impeller::interop::Surface::~Surface
~Surface() override
impeller::interop::Surface::Surface
Surface(const Surface &)=delete
dl_dispatcher.h
impeller::interop
Definition: context_gles.cc:12
impeller::interop::Ref
ScopedObject< Object > Ref(Object *object)
Definition: object.h:146
impeller::RenderToTarget
bool RenderToTarget(ContentContext &context, RenderTarget render_target, const sk_sp< flutter::DisplayList > &display_list, Rect cull_rect, bool reset_host_buffer, bool is_onscreen)
Render the provided display list to the render target.
Definition: dl_dispatcher.cc:1284
std
Definition: comparable.h:95
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
formats.h
surface.h
validation.h