13#include "third_party/skia/include/core/SkColorSpace.h"
14#include "third_party/skia/include/core/SkSurface.h"
15#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
20sk_sp<SkImage> DrawSnapshot(
21 const sk_sp<SkSurface>& surface,
22 const std::function<
void(SkCanvas*)>& draw_callback) {
23 if (surface ==
nullptr ||
surface->getCanvas() ==
nullptr) {
27 draw_callback(
surface->getCanvas());
28 auto dContext = GrAsDirectContext(
surface->recordingContext());
30 dContext->flushAndSubmit();
33 sk_sp<SkImage> device_snapshot;
36 device_snapshot =
surface->makeImageSnapshot();
39 if (device_snapshot ==
nullptr) {
45 if (
auto raster_image = device_snapshot->makeRasterImage(
nullptr)) {
55 sk_sp<DisplayList> display_list,
57 std::function<
void(
const sk_sp<SkImage>&)>
callback,
63 sk_sp<DisplayList> display_list,
66 auto draw_callback = [&display_list](SkCanvas* canvas) {
70 return DoMakeRasterSnapshot(
size, draw_callback);
74 sk_sp<DisplayList> display_list,
76 std::function<
void(
const std::shared_ptr<impeller::Texture>&)>
callback,
81std::shared_ptr<impeller::Texture>
83 sk_sp<DisplayList> display_list,
89sk_sp<SkImage> SnapshotControllerSkia::DoMakeRasterSnapshot(
91 std::function<
void(SkCanvas*)> draw_callback) {
93 sk_sp<SkImage> result;
94 SkImageInfo image_info = SkImageInfo::MakeN32Premul(
size.width,
size.height,
95 SkColorSpace::MakeSRGB());
97 std::unique_ptr<Surface> pbuffer_surface;
98 Surface* snapshot_surface =
nullptr;
100 if (delegate.GetSurface() && delegate.GetSurface()->GetContext()) {
101 snapshot_surface = delegate.GetSurface().get();
102 }
else if (delegate.GetSnapshotSurfaceProducer()) {
104 delegate.GetSnapshotSurfaceProducer()->CreateSnapshotSurface();
105 if (pbuffer_surface && pbuffer_surface->GetContext()) {
106 snapshot_surface = pbuffer_surface.get();
110 if (!snapshot_surface) {
113 sk_sp<SkSurface> sk_surface = SkSurfaces::Raster(image_info);
114 result = DrawSnapshot(sk_surface, draw_callback);
116 delegate.GetIsGpuDisabledSyncSwitch()->Execute(
119 sk_sp<SkSurface>
surface = SkSurfaces::Raster(image_info);
120 result = DrawSnapshot(surface, draw_callback);
124 auto context_switch =
126 if (!context_switch->GetResult()) {
130 GrRecordingContext* context = snapshot_surface->
GetContext();
131 auto max_size = context->maxRenderTargetSize();
132 double scale_factor = std::min(
133 1.0,
static_cast<double>(max_size) /
134 static_cast<double>(std::max(image_info.width(),
135 image_info.height())));
140 if (scale_factor < 1.0) {
141 image_info = image_info.makeWH(
142 static_cast<double>(image_info.width()) * scale_factor,
143 static_cast<double>(image_info.height()) * scale_factor);
148 sk_sp<SkSurface> sk_surface =
149 SkSurfaces::RenderTarget(context,
150 skgpu::Budgeted::kNo,
155 <<
"DoMakeRasterSnapshot can not create GPU render target";
159 sk_surface->getCanvas()->scale(scale_factor, scale_factor);
160 result = DrawSnapshot(sk_surface, draw_callback);
170 sk_sp<SkImage>
image,
175std::shared_ptr<impeller::Texture>
177 sk_sp<SkImage>
image,
183 sk_sp<SkImage>
image) {
188 GetDelegate().GetSurface()->GetContext() ==
nullptr) {
192 if (
image ==
nullptr) {
198 auto result = DoMakeRasterSnapshot(
199 image_size, [
image = std::move(
image)](SkCanvas* canvas) {
200 canvas->drawImage(
image, 0, 0);
206 const std::shared_ptr<impeller::RuntimeStage>& runtime_stage) {}
Backend implementation of |DlCanvas| for |SkCanvas|.
void DrawDisplayList(const sk_sp< DisplayList > display_list, DlScalar opacity=SK_Scalar1) override
const Delegate & GetDelegate()
std::shared_ptr< impeller::Texture > MakeImpellerSnapshotSync(sk_sp< DisplayList > display_list, DlISize size, SnapshotPixelFormat pixel_format) override
void CacheRuntimeStage(const std::shared_ptr< impeller::RuntimeStage > &runtime_stage) override
sk_sp< SkImage > MakeSkiaTextureImage(sk_sp< SkImage > image, SnapshotPixelFormat pixel_format) override
virtual sk_sp< SkImage > ConvertToRasterImage(sk_sp< SkImage > image) override
void MakeSkiaSnapshot(sk_sp< DisplayList > display_list, DlISize picture_size, std::function< void(const sk_sp< SkImage > &)> callback, SnapshotPixelFormat pixel_format) override
bool MakeRenderContextCurrent() override
std::shared_ptr< impeller::Texture > MakeImpellerTextureImage(sk_sp< SkImage > image, SnapshotPixelFormat pixel_format) override
sk_sp< SkImage > MakeSkiaSnapshotSync(sk_sp< DisplayList > display_list, DlISize size, SnapshotPixelFormat pixel_format) override
void MakeImpellerSnapshot(sk_sp< DisplayList > display_list, DlISize picture_size, std::function< void(const std::shared_ptr< impeller::Texture > &)> callback, SnapshotPixelFormat pixel_format) override
Abstract Base Class that represents where we will be rendering content.
virtual std::unique_ptr< GLContextResult > MakeRenderContextCurrent()
virtual GrDirectContext * GetContext()=0
FlutterVulkanImage * image
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
const DlISize & ToDlISize(const SkISize &size)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Represents the 2 code paths available when calling |SyncSwitchExecute|.
#define TRACE_EVENT0(category_group, name)