| Flutter Impeller |

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
5 #include "impeller/renderer/backend/gles/surface_gles.h"
6
7 #include "flutter/fml/trace_event.h"
8 #include "impeller/base/config.h"
9 #include "impeller/renderer/backend/gles/context_gles.h"
10 #include "impeller/renderer/backend/gles/texture_gles.h"
11
12 namespace impeller {
13
14 std::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;
32 color0_tex.usage = TextureUsage::kRenderTarget;
33 color0_tex.sample_count = SampleCount::kCount1;
34 color0_tex.storage_mode = StorageMode::kDevicePrivate;
35
36 ColorAttachment color0;
37 color0.texture =
38 TextureGLES::WrapFBO(gl_context.GetReactor(), color0_tex, fbo);
39 color0.clear_color = Color::DarkSlateGray();
40 color0.load_action = LoadAction::kClear;
41 color0.store_action = StoreAction::kStore;
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 =
51 TextureGLES::CreatePlaceholder(gl_context.GetReactor(), //
52 depth_stencil_texture_desc //
53 );
54
55 DepthAttachment depth0;
56 depth0.clear_depth = 0;
57 depth0.texture = depth_stencil_tex;
58 depth0.load_action = LoadAction::kClear;
59 depth0.store_action = StoreAction::kDontCare;
60
61 StencilAttachment stencil0;
62 stencil0.clear_stencil = 0;
63 stencil0.texture = depth_stencil_tex;
64 stencil0.load_action = LoadAction::kClear;
65 stencil0.store_action = StoreAction::kDontCare;
66
67 RenderTarget render_target_desc;
68
69 render_target_desc.SetColorAttachment(color0, 0u);
70 render_target_desc.SetDepthAttachment(depth0);
71 render_target_desc.SetStencilAttachment(stencil0);
72
73 #ifdef IMPELLER_DEBUG
74 gl_context.GetGPUTracer()->RecordRasterThread();
75 #endif // IMPELLER_DEBUG
76
77 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
78 return std::unique_ptr<SurfaceGLES>(
79 new SurfaceGLES(std::move(swap_callback), render_target_desc));
80 }
81
82 SurfaceGLES::SurfaceGLES(SwapCallback swap_callback,
83 const RenderTarget& target_desc)
84 : Surface(target_desc), swap_callback_(std::move(swap_callback)) {}
85
86 // |Surface|
87 SurfaceGLES::~SurfaceGLES() = default;
88
89 // |Surface|
90 bool SurfaceGLES::Present() const {
91 return swap_callback_ ? swap_callback_() : false;
92 }
93
94 } // namespace impeller
config.h
impeller::BackendCast< ContextGLES, Context >::Cast
static ContextGLES & Cast(Context &base)
Definition: backend_cast.h:13
impeller::RenderTarget
Definition: render_target.h:38
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:199
impeller::RenderTarget::SetDepthAttachment
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
Definition: render_target.cc:213
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:223
impeller::SurfaceGLES
Definition: surface_gles.h:17
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::SurfaceGLES::~SurfaceGLES
~SurfaceGLES() override
impeller::SurfaceGLES::SwapCallback
std::function< bool(void)> SwapCallback
Definition: surface_gles.h:19
impeller::Surface
Definition: surface.h:12
impeller::TextureGLES::WrapFBO
static std::shared_ptr< TextureGLES > WrapFBO(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc, GLuint fbo)
Create a texture by wrapping an external framebuffer object whose lifecycle is owned by the caller.
Definition: texture_gles.cc:147
impeller::TextureGLES::CreatePlaceholder
static std::shared_ptr< TextureGLES > CreatePlaceholder(std::shared_ptr< ReactorGLES > reactor, TextureDescriptor desc)
Create a "texture" that is never expected to be bound/unbound explicitly or initialized in any way....
Definition: texture_gles.cc:179
impeller
Definition: allocation.cc:12
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::LoadAction::kClear
@ kClear
impeller::StoreAction::kStore
@ kStore
impeller::StoreAction::kDontCare
@ kDontCare
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::SampleCount::kCount1
@ kCount1
std
Definition: comparable.h:95
context_gles.h
surface_gles.h
impeller::Attachment::load_action
LoadAction load_action
Definition: formats.h:659
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition: formats.h:657
impeller::Attachment::store_action
StoreAction store_action
Definition: formats.h:660
impeller::ColorAttachment
Definition: formats.h:665
impeller::ColorAttachment::clear_color
Color clear_color
Definition: formats.h:666
impeller::Color::DarkSlateGray
static constexpr Color DarkSlateGray()
Definition: color.h:418
impeller::DepthAttachment
Definition: formats.h:669
impeller::DepthAttachment::clear_depth
double clear_depth
Definition: formats.h:670
impeller::StencilAttachment
Definition: formats.h:673
impeller::StencilAttachment::clear_stencil
uint32_t clear_stencil
Definition: formats.h:674
impeller::TSize
Definition: size.h:25
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition: texture_descriptor.h:44
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:40
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:39
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition: texture_descriptor.h:45
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
texture_gles.h