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<DlImage>&)>
callback,
62sk_sp<DlImage> SnapshotControllerSkia::DoMakeRasterSnapshot(
64 std::function<
void(SkCanvas*)> draw_callback) {
66 sk_sp<SkImage> result;
67 SkImageInfo image_info = SkImageInfo::MakeN32Premul(
size.width,
size.height,
68 SkColorSpace::MakeSRGB());
70 std::unique_ptr<Surface> pbuffer_surface;
71 Surface* snapshot_surface =
nullptr;
73 if (delegate.GetSurface() && delegate.GetSurface()->GetContext()) {
74 snapshot_surface = delegate.GetSurface().get();
75 }
else if (delegate.GetSnapshotSurfaceProducer()) {
77 delegate.GetSnapshotSurfaceProducer()->CreateSnapshotSurface();
78 if (pbuffer_surface && pbuffer_surface->GetContext()) {
79 snapshot_surface = pbuffer_surface.get();
83 if (!snapshot_surface) {
86 sk_sp<SkSurface> sk_surface = SkSurfaces::Raster(image_info);
87 result = DrawSnapshot(sk_surface, draw_callback);
89 delegate.GetIsGpuDisabledSyncSwitch()->Execute(
92 sk_sp<SkSurface>
surface = SkSurfaces::Raster(image_info);
93 result = DrawSnapshot(surface, draw_callback);
99 if (!context_switch->GetResult()) {
103 GrRecordingContext* context = snapshot_surface->
GetContext();
104 auto max_size = context->maxRenderTargetSize();
105 double scale_factor = std::min(
106 1.0,
static_cast<double>(max_size) /
107 static_cast<double>(std::max(image_info.width(),
108 image_info.height())));
113 if (scale_factor < 1.0) {
114 image_info = image_info.makeWH(
115 static_cast<double>(image_info.width()) * scale_factor,
116 static_cast<double>(image_info.height()) * scale_factor);
121 sk_sp<SkSurface> sk_surface =
122 SkSurfaces::RenderTarget(context,
123 skgpu::Budgeted::kNo,
128 <<
"DoMakeRasterSnapshot can not create GPU render target";
132 sk_surface->getCanvas()->scale(scale_factor, scale_factor);
133 result = DrawSnapshot(sk_surface, draw_callback);
143 sk_sp<DisplayList> display_list,
146 return DoMakeRasterSnapshot(
size, [display_list](SkCanvas* canvas) {
152 sk_sp<SkImage>
image,
158 sk_sp<SkImage>
image) {
163 GetDelegate().GetSurface()->GetContext() ==
nullptr) {
167 if (
image ==
nullptr) {
173 auto result = DoMakeRasterSnapshot(
174 image_size, [
image = std::move(
image)](SkCanvas* canvas) {
175 canvas->drawImage(
image, 0, 0);
177 return result->skia_image();
181 const std::shared_ptr<impeller::RuntimeStage>& runtime_stage) {}
static sk_sp< DlImage > Make(const SkImage *image)
Backend implementation of |DlCanvas| for |SkCanvas|.
void DrawDisplayList(const sk_sp< DisplayList > display_list, DlScalar opacity=SK_Scalar1) override
const Delegate & GetDelegate()
sk_sp< DlImage > MakeTextureImage(sk_sp< SkImage > image, SnapshotPixelFormat pixel_format) override
void CacheRuntimeStage(const std::shared_ptr< impeller::RuntimeStage > &runtime_stage) override
sk_sp< DlImage > MakeRasterSnapshotSync(sk_sp< DisplayList > display_list, DlISize size, SnapshotPixelFormat pixel_format) override
virtual sk_sp< SkImage > ConvertToRasterImage(sk_sp< SkImage > image) override
bool MakeRenderContextCurrent() override
void MakeRasterSnapshot(sk_sp< DisplayList > display_list, DlISize picture_size, std::function< void(const sk_sp< DlImage > &)> 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)