Flutter Engine
The Flutter Engine
surface_gles.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 "flutter/fml/trace_event.h"
11
12namespace impeller {
13
14std::unique_ptr<Surface> SurfaceGLES::WrapFBO(
15 const std::shared_ptr<Context>& context,
16 SwapCallback swap_callback,
17 GLuint fbo,
18 PixelFormat color_format,
19 ISize fbo_size) {
20 TRACE_EVENT0("impeller", "SurfaceGLES::WrapOnScreenFBO");
21
22 if (context == nullptr || !context->IsValid() || !swap_callback) {
23 return nullptr;
24 }
25
26 const auto& gl_context = ContextGLES::Cast(*context);
27
28 TextureDescriptor color0_tex;
29 color0_tex.type = TextureType::kTexture2D;
30 color0_tex.format = color_format;
31 color0_tex.size = fbo_size;
35
36 ColorAttachment color0;
37 color0.texture = std::make_shared<TextureGLES>(
38 gl_context.GetReactor(), color0_tex, TextureGLES::IsWrapped::kWrapped);
42
43 TextureDescriptor depth_stencil_texture_desc;
44 depth_stencil_texture_desc.type = TextureType::kTexture2D;
45 depth_stencil_texture_desc.format = color_format;
46 depth_stencil_texture_desc.size = fbo_size;
47 depth_stencil_texture_desc.usage = TextureUsage::kRenderTarget;
48 depth_stencil_texture_desc.sample_count = SampleCount::kCount1;
49
50 auto depth_stencil_tex = std::make_shared<TextureGLES>(
51 gl_context.GetReactor(), depth_stencil_texture_desc,
53
54 DepthAttachment depth0;
55 depth0.clear_depth = 0;
56 depth0.texture = depth_stencil_tex;
59
60 StencilAttachment stencil0;
61 stencil0.clear_stencil = 0;
62 stencil0.texture = depth_stencil_tex;
65
66 RenderTarget render_target_desc;
67
68 render_target_desc.SetColorAttachment(color0, 0u);
69 render_target_desc.SetDepthAttachment(depth0);
70 render_target_desc.SetStencilAttachment(stencil0);
71
72#ifdef IMPELLER_DEBUG
73 gl_context.GetGPUTracer()->RecordRasterThread();
74#endif // IMPELLER_DEBUG
75
76 return std::unique_ptr<SurfaceGLES>(
77 new SurfaceGLES(std::move(swap_callback), render_target_desc));
78}
79
80SurfaceGLES::SurfaceGLES(SwapCallback swap_callback,
81 const RenderTarget& target_desc)
82 : Surface(target_desc), swap_callback_(std::move(swap_callback)) {}
83
84// |Surface|
86
87// |Surface|
88bool SurfaceGLES::Present() const {
89 return swap_callback_ ? swap_callback_() : false;
90}
91
92} // namespace impeller
static ContextGLES & Cast(Context &base)
Definition: backend_cast.h:13
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
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
std::function< bool(void)> SwapCallback
Definition: surface_gles.h:19
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
Definition: ref_ptr.h:256
LoadAction load_action
Definition: formats.h:653
std::shared_ptr< Texture > texture
Definition: formats.h:651
StoreAction store_action
Definition: formats.h:654
static constexpr Color DarkSlateGray()
Definition: color.h:420
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131