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 
6 
7 #include "flutter/fml/trace_event.h"
8 #include "impeller/base/config.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 = static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
35 
36  ColorAttachment color0;
37  color0.texture = std::make_shared<TextureGLES>(
38  gl_context.GetReactor(), color0_tex, TextureGLES::IsWrapped::kWrapped);
42 
43  TextureDescriptor stencil0_tex;
44  stencil0_tex.type = TextureType::kTexture2D;
45  stencil0_tex.format = color_format;
46  stencil0_tex.size = fbo_size;
47  stencil0_tex.usage =
49  stencil0_tex.sample_count = SampleCount::kCount1;
50 
51  StencilAttachment stencil0;
52  stencil0.clear_stencil = 0;
53  stencil0.texture = std::make_shared<TextureGLES>(
54  gl_context.GetReactor(), stencil0_tex, TextureGLES::IsWrapped::kWrapped);
57 
58  RenderTarget render_target_desc;
59 
60  render_target_desc.SetColorAttachment(color0, 0u);
61  render_target_desc.SetStencilAttachment(stencil0);
62 
63  return std::unique_ptr<SurfaceGLES>(
64  new SurfaceGLES(std::move(swap_callback), render_target_desc));
65 }
66 
67 SurfaceGLES::SurfaceGLES(SwapCallback swap_callback,
68  const RenderTarget& target_desc)
69  : Surface(target_desc), swap_callback_(std::move(swap_callback)) {}
70 
71 // |Surface|
72 SurfaceGLES::~SurfaceGLES() = default;
73 
74 // |Surface|
75 bool SurfaceGLES::Present() const {
76  return swap_callback_ ? swap_callback_() : false;
77 }
78 
79 } // namespace impeller
impeller::TextureUsageMask
uint64_t TextureUsageMask
Definition: formats.h:274
impeller::Attachment::store_action
StoreAction store_action
Definition: formats.h:594
impeller::ColorAttachment
Definition: formats.h:599
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:42
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:180
texture_gles.h
context_gles.h
impeller::SampleCount::kCount1
@ kCount1
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::StoreAction::kDontCare
@ kDontCare
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition: texture_descriptor.h:47
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition: texture_descriptor.h:45
surface_gles.h
impeller::Surface
Definition: surface.h:17
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:41
impeller::StencilAttachment
Definition: formats.h:607
impeller::Color::DarkSlateGray
static constexpr Color DarkSlateGray()
Definition: color.h:408
impeller::TSize< int64_t >
impeller::LoadAction::kClear
@ kClear
impeller::ColorAttachment::clear_color
Color clear_color
Definition: formats.h:600
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition: formats.h:591
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::RenderTarget
Definition: render_target.h:48
impeller::StoreAction::kStore
@ kStore
impeller::StencilAttachment::clear_stencil
uint32_t clear_stencil
Definition: formats.h:608
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:43
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:199
std
Definition: comparable.h:98
impeller::SurfaceGLES::SwapCallback
std::function< bool(void)> SwapCallback
Definition: surface_gles.h:19
impeller::BackendCast< ContextGLES, Context >::Cast
static ContextGLES & Cast(Context &base)
Definition: backend_cast.h:14
impeller::Attachment::load_action
LoadAction load_action
Definition: formats.h:593
impeller::SurfaceGLES
Definition: surface_gles.h:17
impeller::TextureGLES::IsWrapped::kWrapped
@ kWrapped
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:40
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::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:39
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::SurfaceGLES::~SurfaceGLES
~SurfaceGLES() override
config.h
impeller
Definition: aiks_context.cc:10