-
Notifications
You must be signed in to change notification settings - Fork 6k
Use a Pbuffer surface when the onscreen surface is not available for snapshotting on Android #27141
Changes from all commits
40aa579
46baeac
38c703e
ae056ea
2d34f96
e376c25
62bf039
0ac0b5a
1b42c62
966cdeb
b501573
a7781d4
d901094
aa948b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,11 +258,22 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot( | |
| sk_sp<SkImage> result; | ||
| SkImageInfo image_info = SkImageInfo::MakeN32Premul( | ||
| size.width(), size.height(), SkColorSpace::MakeSRGB()); | ||
| if (surface_ == nullptr || surface_->GetContext() == nullptr) { | ||
|
|
||
| std::unique_ptr<Surface> pbuffer_surface; | ||
| Surface* snapshot_surface = nullptr; | ||
| if (surface_ && surface_->GetContext()) { | ||
| snapshot_surface = surface_.get(); | ||
| } else if (snapshot_surface_producer_) { | ||
| pbuffer_surface = snapshot_surface_producer_->CreateSnapshotSurface(); | ||
| if (pbuffer_surface && pbuffer_surface->GetContext()) | ||
| snapshot_surface = pbuffer_surface.get(); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the redundancy of e.g. with something like The rest of the method can then only use snapshot_surface
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd ahve to manually delete the surface if it came from CreateSnapshotSurface then though. like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh I get it now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| if (!snapshot_surface) { | ||
| // Raster surface is fine if there is no on screen surface. This might | ||
| // happen in case of software rendering. | ||
| sk_sp<SkSurface> surface = SkSurface::MakeRaster(image_info); | ||
| result = DrawSnapshot(surface, draw_callback); | ||
| sk_sp<SkSurface> sk_surface = SkSurface::MakeRaster(image_info); | ||
| result = DrawSnapshot(sk_surface, draw_callback); | ||
| } else { | ||
| delegate_.GetIsGpuDisabledSyncSwitch()->Execute( | ||
| fml::SyncSwitch::Handlers() | ||
|
|
@@ -271,12 +282,14 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot( | |
| result = DrawSnapshot(surface, draw_callback); | ||
| }) | ||
| .SetIfFalse([&] { | ||
| auto context_switch = surface_->MakeRenderContextCurrent(); | ||
| FML_DCHECK(snapshot_surface); | ||
| auto context_switch = | ||
| snapshot_surface->MakeRenderContextCurrent(); | ||
| if (!context_switch->GetResult()) { | ||
| return; | ||
| } | ||
|
|
||
| GrRecordingContext* context = surface_->GetContext(); | ||
| GrRecordingContext* context = snapshot_surface->GetContext(); | ||
| auto max_size = context->maxRenderTargetSize(); | ||
| double scale_factor = std::min( | ||
| 1.0, static_cast<double>(max_size) / | ||
|
|
@@ -294,19 +307,19 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot( | |
|
|
||
| // When there is an on screen surface, we need a render target | ||
| // SkSurface because we want to access texture backed images. | ||
| sk_sp<SkSurface> surface = | ||
| sk_sp<SkSurface> sk_surface = | ||
| SkSurface::MakeRenderTarget(context, // context | ||
| SkBudgeted::kNo, // budgeted | ||
| image_info // image info | ||
| ); | ||
| if (!surface) { | ||
| if (!sk_surface) { | ||
| FML_LOG(ERROR) | ||
| << "DoMakeRasterSnapshot can not create GPU render target"; | ||
| return; | ||
| } | ||
|
|
||
| surface->getCanvas()->scale(scale_factor, scale_factor); | ||
| result = DrawSnapshot(surface, draw_callback); | ||
| sk_surface->getCanvas()->scale(scale_factor, scale_factor); | ||
| result = DrawSnapshot(sk_surface, draw_callback); | ||
| })); | ||
| } | ||
|
|
||
|
|
@@ -700,6 +713,11 @@ void Rasterizer::SetExternalViewEmbedder( | |
| external_view_embedder_ = view_embedder; | ||
| } | ||
|
|
||
| void Rasterizer::SetSnapshotSurfaceProducer( | ||
| std::unique_ptr<SnapshotSurfaceProducer> producer) { | ||
| snapshot_surface_producer_ = std::move(producer); | ||
| } | ||
|
|
||
| void Rasterizer::FireNextFrameCallbackIfPresent() { | ||
| if (!next_frame_callback_) { | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef SHELL_COMMON_SNAPSHOT_SURFACE_PRODUCER_H_ | ||
| #define SHELL_COMMON_SNAPSHOT_SURFACE_PRODUCER_H_ | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "flutter/flow/surface.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| class SnapshotSurfaceProducer { | ||
| public: | ||
| virtual ~SnapshotSurfaceProducer() = default; | ||
|
|
||
| virtual std::unique_ptr<Surface> CreateSnapshotSurface() = 0; | ||
| }; | ||
|
|
||
| } // namespace flutter | ||
| #endif // SHELL_COMMON_SNAPSHOT_SURFACE_PRODUCER_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes here are to run multiple firebase testlab tests in parallel. Now that we're running two this makes a difference. The new test executes pretty quickly but still requires setup/upload/results processing time.