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 
6 
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
const sk_sp< flutter::DisplayList > GetDisplayList() const
Definition: dl.cc:18
bool IsValid() const
Definition: dl.cc:14
bool IsValid() const
Definition: surface.cc:22
bool Present() const
Definition: surface.cc:43
bool DrawDisplayList(const DisplayList &dl) const
Definition: surface.cc:26
Surface(const Surface &)=delete
ScopedObject< Object > Ref(Object *object)
Definition: object.h:146
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: comparable.h:95
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150