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) {
61sk_sp<DlImage> SnapshotControllerSkia::DoMakeRasterSnapshot(
63 std::function<
void(SkCanvas*)> draw_callback) {
65 sk_sp<SkImage> result;
66 SkImageInfo image_info = SkImageInfo::MakeN32Premul(
size.width,
size.height,
67 SkColorSpace::MakeSRGB());
69 std::unique_ptr<Surface> pbuffer_surface;
70 Surface* snapshot_surface =
nullptr;
72 if (delegate.GetSurface() && delegate.GetSurface()->GetContext()) {
73 snapshot_surface = delegate.GetSurface().get();
74 }
else if (delegate.GetSnapshotSurfaceProducer()) {
76 delegate.GetSnapshotSurfaceProducer()->CreateSnapshotSurface();
77 if (pbuffer_surface && pbuffer_surface->GetContext()) {
78 snapshot_surface = pbuffer_surface.get();
82 if (!snapshot_surface) {
85 sk_sp<SkSurface> sk_surface = SkSurfaces::Raster(image_info);
86 result = DrawSnapshot(sk_surface, draw_callback);
88 delegate.GetIsGpuDisabledSyncSwitch()->Execute(
91 sk_sp<SkSurface>
surface = SkSurfaces::Raster(image_info);
92 result = DrawSnapshot(surface, draw_callback);
98 if (!context_switch->GetResult()) {
102 GrRecordingContext* context = snapshot_surface->
GetContext();
103 auto max_size = context->maxRenderTargetSize();
104 double scale_factor = std::min(
105 1.0,
static_cast<double>(max_size) /
106 static_cast<double>(std::max(image_info.width(),
107 image_info.height())));
112 if (scale_factor < 1.0) {
113 image_info = image_info.makeWH(
114 static_cast<double>(image_info.width()) * scale_factor,
115 static_cast<double>(image_info.height()) * scale_factor);
120 sk_sp<SkSurface> sk_surface =
121 SkSurfaces::RenderTarget(context,
122 skgpu::Budgeted::kNo,
127 <<
"DoMakeRasterSnapshot can not create GPU render target";
131 sk_surface->getCanvas()->scale(scale_factor, scale_factor);
132 result = DrawSnapshot(sk_surface, draw_callback);
142 sk_sp<DisplayList> display_list,
144 return DoMakeRasterSnapshot(
size, [display_list](SkCanvas* canvas) {
150 sk_sp<SkImage>
image) {
155 GetDelegate().GetSurface()->GetContext() ==
nullptr) {
159 if (
image ==
nullptr) {
165 auto result = DoMakeRasterSnapshot(
166 image_size, [
image = std::move(
image)](SkCanvas* canvas) {
167 canvas->drawImage(
image, 0, 0);
169 return result->skia_image();
173 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()
void CacheRuntimeStage(const std::shared_ptr< impeller::RuntimeStage > &runtime_stage) override
virtual sk_sp< SkImage > ConvertToRasterImage(sk_sp< SkImage > image) override
void MakeRasterSnapshot(sk_sp< DisplayList > display_list, DlISize picture_size, std::function< void(const sk_sp< DlImage > &)> callback) override
bool MakeRenderContextCurrent() override
sk_sp< DlImage > MakeRasterSnapshotSync(sk_sp< DisplayList > display_list, DlISize size) 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)