Flutter Engine
flutter::AndroidSurfaceSoftware Class Referencefinal

#include <android_surface_software.h>

Inheritance diagram for flutter::AndroidSurfaceSoftware:
flutter::AndroidSurface flutter::GPUSurfaceSoftwareDelegate flutter::GPUSurfaceDelegate

Public Member Functions

 AndroidSurfaceSoftware (std::shared_ptr< AndroidContext > android_context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade, std::shared_ptr< AndroidExternalViewEmbedder > external_view_embedder)
 
 ~AndroidSurfaceSoftware () override
 
bool IsValid () const override
 
bool ResourceContextMakeCurrent () override
 
bool ResourceContextClearCurrent () override
 
std::unique_ptr< SurfaceCreateGPUSurface (GrDirectContext *gr_context) override
 
void TeardownOnScreenContext () override
 
bool OnScreenSurfaceResize (const SkISize &size) override
 
bool SetNativeWindow (fml::RefPtr< AndroidNativeWindow > window) override
 
sk_sp< SkSurface > AcquireBackingStore (const SkISize &size) override
 Called when the GPU surface needs a new buffer to render a new frame into. More...
 
bool PresentBackingStore (sk_sp< SkSurface > backing_store) override
 Called by the platform when a frame has been rendered into the backing store and the platform must display it on-screen. More...
 
ExternalViewEmbedderGetExternalViewEmbedder () override
 Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks should be composited back on-screen. This field is optional and the Flutter rasterizer will render into a single on-screen surface if this call returns a null external view embedder. This happens on the GPU thread. More...
 
- Public Member Functions inherited from flutter::AndroidSurface
virtual ~AndroidSurface ()
 
- Public Member Functions inherited from flutter::GPUSurfaceSoftwareDelegate
 ~GPUSurfaceSoftwareDelegate () override
 
- Public Member Functions inherited from flutter::GPUSurfaceDelegate
virtual ~GPUSurfaceDelegate ()
 

Detailed Description

Definition at line 18 of file android_surface_software.h.

Constructor & Destructor Documentation

◆ AndroidSurfaceSoftware()

flutter::AndroidSurfaceSoftware::AndroidSurfaceSoftware ( std::shared_ptr< AndroidContext android_context,
std::shared_ptr< PlatformViewAndroidJNI jni_facade,
std::shared_ptr< AndroidExternalViewEmbedder external_view_embedder 
)

Definition at line 40 of file android_surface_software.cc.

References ~AndroidSurfaceSoftware().

44  : external_view_embedder_(external_view_embedder) {
45  GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_,
46  &target_alpha_type_);
47 }

◆ ~AndroidSurfaceSoftware()

flutter::AndroidSurfaceSoftware::~AndroidSurfaceSoftware ( )
overridedefault

Referenced by AndroidSurfaceSoftware().

Member Function Documentation

◆ AcquireBackingStore()

sk_sp< SkSurface > flutter::AndroidSurfaceSoftware::AcquireBackingStore ( const SkISize &  size)
overridevirtual

Called when the GPU surface needs a new buffer to render a new frame into.

Parameters
[in]sizeThe size of the frame.
Returns
A raster surface returned by the platform.

Implements flutter::GPUSurfaceSoftwareDelegate.

Definition at line 80 of file android_surface_software.cc.

References IsValid(), and TRACE_EVENT0.

81  {
82  TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::AcquireBackingStore");
83  if (!IsValid()) {
84  return nullptr;
85  }
86 
87  if (sk_surface_ != nullptr &&
88  SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
89  // The old and new surface sizes are the same. Nothing to do here.
90  return sk_surface_;
91  }
92 
93  SkImageInfo image_info =
94  SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_,
95  target_alpha_type_, SkColorSpace::MakeSRGB());
96 
97  sk_surface_ = SkSurface::MakeRaster(image_info);
98 
99  return sk_surface_;
100 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ CreateGPUSurface()

std::unique_ptr< Surface > flutter::AndroidSurfaceSoftware::CreateGPUSurface ( GrDirectContext *  gr_context)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 64 of file android_surface_software.cc.

References IsValid().

65  {
66  if (!IsValid()) {
67  return nullptr;
68  }
69 
70  auto surface =
71  std::make_unique<GPUSurfaceSoftware>(this, true /* render to surface */);
72 
73  if (!surface->IsValid()) {
74  return nullptr;
75  }
76 
77  return surface;
78 }

◆ GetExternalViewEmbedder()

ExternalViewEmbedder * flutter::AndroidSurfaceSoftware::GetExternalViewEmbedder ( )
overridevirtual

Gets the view embedder that controls how the Flutter layer hierarchy split into multiple chunks should be composited back on-screen. This field is optional and the Flutter rasterizer will render into a single on-screen surface if this call returns a null external view embedder. This happens on the GPU thread.

Returns
The external view embedder, or, null if Flutter is rendering into a single on-screen surface.

Reimplemented from flutter::GPUSurfaceSoftwareDelegate.

Definition at line 145 of file android_surface_software.cc.

145  {
146  return external_view_embedder_.get();
147 }

◆ IsValid()

bool flutter::AndroidSurfaceSoftware::IsValid ( ) const
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 51 of file android_surface_software.cc.

Referenced by AcquireBackingStore(), CreateGPUSurface(), and PresentBackingStore().

51  {
52  return true;
53 }

◆ OnScreenSurfaceResize()

bool flutter::AndroidSurfaceSoftware::OnScreenSurfaceResize ( const SkISize &  size)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 151 of file android_surface_software.cc.

151  {
152  return true;
153 }

◆ PresentBackingStore()

bool flutter::AndroidSurfaceSoftware::PresentBackingStore ( sk_sp< SkSurface >  backing_store)
overridevirtual

Called by the platform when a frame has been rendered into the backing store and the platform must display it on-screen.

Parameters
[in]backing_storeThe software backing store to present.
Returns
Returns if the platform could present the backing store onto the screen.

Implements flutter::GPUSurfaceSoftwareDelegate.

Definition at line 102 of file android_surface_software.cc.

References alpha_type, color_type, IsValid(), and TRACE_EVENT0.

103  {
104  TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::PresentBackingStore");
105  if (!IsValid() || backing_store == nullptr) {
106  return false;
107  }
108 
109  SkPixmap pixmap;
110  if (!backing_store->peekPixels(&pixmap)) {
111  return false;
112  }
113 
114  ANativeWindow_Buffer native_buffer;
115  if (ANativeWindow_lock(native_window_->handle(), &native_buffer, nullptr)) {
116  return false;
117  }
118 
119  SkColorType color_type;
120  SkAlphaType alpha_type;
121  if (GetSkColorType(native_buffer.format, &color_type, &alpha_type)) {
122  SkImageInfo native_image_info = SkImageInfo::Make(
123  native_buffer.width, native_buffer.height, color_type, alpha_type);
124 
125  std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(
126  native_image_info, native_buffer.bits,
127  native_buffer.stride * SkColorTypeBytesPerPixel(color_type));
128 
129  if (canvas) {
130  SkBitmap bitmap;
131  if (bitmap.installPixels(pixmap)) {
132  canvas->drawBitmapRect(
133  bitmap, SkRect::MakeIWH(native_buffer.width, native_buffer.height),
134  nullptr);
135  }
136  }
137  }
138 
139  ANativeWindow_unlockAndPost(native_window_->handle());
140 
141  return true;
142 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:75
uint32_t color_type
uint32_t alpha_type

◆ ResourceContextClearCurrent()

bool flutter::AndroidSurfaceSoftware::ResourceContextClearCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 60 of file android_surface_software.cc.

60  {
61  return false;
62 }

◆ ResourceContextMakeCurrent()

bool flutter::AndroidSurfaceSoftware::ResourceContextMakeCurrent ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 55 of file android_surface_software.cc.

55  {
56  // Resource Context always not available on software backend.
57  return false;
58 }

◆ SetNativeWindow()

bool flutter::AndroidSurfaceSoftware::SetNativeWindow ( fml::RefPtr< AndroidNativeWindow window)
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 155 of file android_surface_software.cc.

156  {
157  native_window_ = std::move(window);
158  if (!(native_window_ && native_window_->IsValid()))
159  return false;
160  int32_t window_format = ANativeWindow_getFormat(native_window_->handle());
161  if (window_format < 0)
162  return false;
163  if (!GetSkColorType(window_format, &target_color_type_, &target_alpha_type_))
164  return false;
165  return true;
166 }

◆ TeardownOnScreenContext()

void flutter::AndroidSurfaceSoftware::TeardownOnScreenContext ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 149 of file android_surface_software.cc.

149 {}

The documentation for this class was generated from the following files: