10#include "third_party/skia/include/encode/SkPngEncoder.h"
11#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
18 void operator()(uint8_t* p) { std::free(p); }
22 static std::unique_ptr<DlSkiaPixelData> MakeFromRasterImage(
23 const sk_sp<SkImage>& raster_image) {
24 SkImageInfo info = raster_image->imageInfo();
25 info = SkImageInfo::MakeN32Premul(info.dimensions());
28 size_t min_row_bytes = info.minRowBytes();
29 size_t byte_count = info.computeByteSize(min_row_bytes);
30 if (byte_count == std::numeric_limits<size_t>::max()) {
34 std::unique_ptr<uint8_t, FreeDeleter> pixels;
35 pixels.reset(
static_cast<uint8_t*
>(std::malloc(byte_count)));
42 pixmap.reset(info, pixels.get(), info.minRowBytes());
43 if (!raster_image->readPixels(pixmap, 0, 0)) {
54 return std::make_unique<DlSkiaPixelData>(info, min_row_bytes,
58 DlSkiaPixelData(
const SkImageInfo& info,
60 std::unique_ptr<uint8_t, FreeDeleter> pixels)
61 : pixels_(
std::move(pixels)) {
63 pixmap_.reset(info, pixels_.get(), row_bytes);
66 ~DlSkiaPixelData()
override =
default;
68 const uint32_t*
addr32(uint32_t
x, uint32_t
y)
const override {
72 return static_cast<const uint32_t*
>(pixmap_.addr(
x,
y));
75 size_t width()
const override {
return pixmap_.info().width(); }
76 size_t height()
const override {
return pixmap_.info().height(); }
78 virtual bool write(
const std::string& path)
const override {
79 sk_sp<SkData>
data = SkPngEncoder::Encode(pixmap_, {});
86 path.c_str(), mapping);
90 std::unique_ptr<uint8_t, FreeDeleter> pixels_;
113 if (adapter_.
canvas() ==
nullptr) {
115 adapter_.
canvas()->save();
121 const sk_sp<DisplayList>& display_list) {
130 if (GrDirectContext* dContext =
131 GrAsDirectContext(
surface->recordingContext())) {
132 dContext->flushAndSubmit(
surface.get(), GrSyncCpu::kYes);
134 adapter_.
canvas()->restoreToCount(0);
135 adapter_.
canvas()->save();
139 sk_sp<SkImage> raster = GetRasterImage();
143 sk_sp<SkData>
data = SkPngEncoder::Encode(
nullptr, raster.get(), {});
154 sk_sp<SkImage> raster = GetRasterImage();
156 return raster ? DlSkiaPixelData::MakeFromRasterImage(raster) :
nullptr;
171sk_sp<SkImage> DlSurfaceInstanceSkiaBase::GetRasterImage()
const {
177 return image->makeRasterImage(
nullptr);
Developer-facing API for rendering anything within the engine.
virtual void DrawDisplayList(const sk_sp< DisplayList > display_list, DlScalar opacity=SK_Scalar1)=0
void Clear(DlColor color)
static sk_sp< DlImage > Make(const SkImage *image)
void set_canvas(SkCanvas *canvas)
virtual size_t height() const =0
virtual const uint32_t * addr32(uint32_t x, uint32_t y) const =0
virtual bool write(const std::string &path) const =0
virtual size_t width() const =0
std::unique_ptr< DlPixelData > SnapshotToPixelData() const override
DlCanvas * GetCanvas() override
virtual sk_sp< SkSurface > GetSurface() const =0
void RenderDisplayList(const sk_sp< DisplayList > &display_list) override
bool SnapshotToFile(std::string &filename) const override
Store a snapshot of this Surface to the file indicated by the filename.
DlSurfaceInstanceSkiaBase()
void FlushSubmitCpuSync() override
sk_sp< DlImage > SnapshotToImage() const override
int height() const override
The height of the underlying surface.
void Clear(const DlColor &color) override
Clear the entire surface to the indicated color.
virtual ~DlSurfaceInstanceSkiaBase()
int width() const override
The width of the underlying surface.
sk_sp< SkSurface > GetSurface() const override
DlSurfaceInstanceSkia(sk_sp< SkSurface > surface)
FlutterVulkanImage * image
#define FML_CHECK(condition)
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)