1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/lib/ui/painting/picture.h"
6
7 #include "flutter/lib/ui/painting/canvas.h"
8 #include "third_party/skia/include/core/SkImage.h"
9 #include "flutter/lib/ui/ui_dart_state.h"
10
11 namespace flutter {
12
Create(SkiaGPUObject<SkPicture> picture)13 fml::RefPtr<Picture> Picture::Create(SkiaGPUObject<SkPicture> picture) {
14 return fml::MakeRefCounted<Picture>(std::move(picture));
15 }
16
Picture(SkiaGPUObject<SkPicture> picture)17 Picture::Picture(SkiaGPUObject<SkPicture> picture)
18 : picture_(std::move(picture)) {}
19
20 Picture::~Picture() = default;
21
toImage(int width,int height)22 fml::RefPtr<CanvasImage> Picture::toImage(int width, int height) {
23 fml::RefPtr<CanvasImage> image = CanvasImage::Create();
24 image->set_image(UIDartState::CreateGPUObject<SkImage>(SkImage::MakeFromPicture(
25 picture_.get(), SkISize::Make(width, height), nullptr, nullptr,
26 SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB())));
27 return image;
28 }
29
RasterizeToImage(sk_sp<SkPicture> picture,uint32_t width,uint32_t height,Dart_Handle raw_image_callback)30 Dart_Handle Picture::RasterizeToImage(sk_sp<SkPicture> picture,
31 uint32_t width,
32 uint32_t height,
33 Dart_Handle raw_image_callback) {
34 return nullptr;
35 }
36
GetAllocationSize()37 size_t Picture::GetAllocationSize() {
38 if (auto picture = picture_.get()) {
39 return picture->approximateBytesUsed();
40 } else {
41 return sizeof(Picture);
42 }
43 }
44
45 } // namespace blink
46