Flutter Engine
flutter::AndroidSurfaceSoftware Class Referencefinal

#include <android_surface_software.h>

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

Public Member Functions

 AndroidSurfaceSoftware (const std::shared_ptr< AndroidContext > &android_context, std::shared_ptr< PlatformViewAndroidJNI > jni_facade)
 
 ~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...
 
- Public Member Functions inherited from flutter::AndroidSurface
virtual ~AndroidSurface ()
 
virtual std::unique_ptr< SurfaceCreatePbufferSurface ()
 
- Public Member Functions inherited from flutter::GPUSurfaceSoftwareDelegate
 ~GPUSurfaceSoftwareDelegate ()
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::AndroidSurface
 AndroidSurface (const std::shared_ptr< AndroidContext > &android_context)
 
- Protected Attributes inherited from flutter::AndroidSurface
std::shared_ptr< AndroidContextandroid_context_
 

Detailed Description

Definition at line 17 of file android_surface_software.h.

Constructor & Destructor Documentation

◆ AndroidSurfaceSoftware()

flutter::AndroidSurfaceSoftware::AndroidSurfaceSoftware ( const std::shared_ptr< AndroidContext > &  android_context,
std::shared_ptr< PlatformViewAndroidJNI jni_facade 
)

Definition at line 41 of file android_surface_software.cc.

References ~AndroidSurfaceSoftware().

44  : AndroidSurface(android_context) {
45  GetSkColorType(WINDOW_FORMAT_RGBA_8888, &target_color_type_,
46  &target_alpha_type_);
47 }
AndroidSurface(const std::shared_ptr< AndroidContext > &android_context)

◆ ~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 82 of file android_surface_software.cc.

References IsValid(), and TRACE_EVENT0.

83  {
84  TRACE_EVENT0("flutter", "AndroidSurfaceSoftware::AcquireBackingStore");
85  if (!IsValid()) {
86  return nullptr;
87  }
88 
89  if (sk_surface_ != nullptr &&
90  SkISize::Make(sk_surface_->width(), sk_surface_->height()) == size) {
91  // The old and new surface sizes are the same. Nothing to do here.
92  return sk_surface_;
93  }
94 
95  SkImageInfo image_info =
96  SkImageInfo::Make(size.fWidth, size.fHeight, target_color_type_,
97  target_alpha_type_, SkColorSpace::MakeSRGB());
98 
99  sk_surface_ = SkSurface::MakeRaster(image_info);
100 
101  return sk_surface_;
102 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
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().

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

◆ 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 149 of file android_surface_software.cc.

149  {
150  return true;
151 }

◆ 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 104 of file android_surface_software.cc.

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

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

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

◆ TeardownOnScreenContext()

void flutter::AndroidSurfaceSoftware::TeardownOnScreenContext ( )
overridevirtual

Implements flutter::AndroidSurface.

Definition at line 147 of file android_surface_software.cc.

147 {}

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