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 = IRect::MakeSize(surface_->GetSize());
36  auto skia_cull_rect =
37  SkIRect::MakeWH(cull_rect.GetWidth(), cull_rect.GetHeight());
38 
39  auto result = RenderToTarget(content_context, render_target, display_list,
40  skia_cull_rect, /*reset_host_buffer=*/true);
41  context_->GetContext()->ResetThreadLocalState();
42  return result;
43 }
44 
45 bool Surface::Present() const {
46  if (!IsValid()) {
47  return false;
48  }
49  return surface_->Present();
50 }
51 
52 } // 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:45
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, SkIRect 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