Flutter Engine
 
Loading...
Searching...
No Matches
image_decoder_impeller.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_IMPELLER_H_
6#define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_IMPELLER_H_
7
8#include <future>
9
10#include "flutter/fml/macros.h"
15#include "include/core/SkImageInfo.h"
16#include "third_party/skia/include/core/SkBitmap.h"
17
18namespace impeller {
19class Context;
20class Allocator;
21class DeviceBuffer;
22} // namespace impeller
23
24namespace flutter {
25
26class ImpellerAllocator : public SkBitmap::Allocator {
27 public:
28 explicit ImpellerAllocator(std::shared_ptr<impeller::Allocator> allocator);
29
30 ~ImpellerAllocator() = default;
31
32 // |Allocator|
33 bool allocPixelRef(SkBitmap* bitmap) override;
34
35 std::shared_ptr<impeller::DeviceBuffer> GetDeviceBuffer() const;
36
37 private:
38 std::shared_ptr<impeller::Allocator> allocator_;
39 std::shared_ptr<impeller::DeviceBuffer> buffer_;
40};
41
43 std::shared_ptr<impeller::DeviceBuffer> device_buffer;
44 std::shared_ptr<SkBitmap> sk_bitmap;
45 SkImageInfo image_info;
46 std::optional<SkImageInfo> resize_info = std::nullopt;
47 std::string decode_error;
48};
49
50class ImageDecoderImpeller final : public ImageDecoder {
51 public:
53 const TaskRunners& runners,
54 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
55 const fml::WeakPtr<IOManager>& io_manager,
56 bool supports_wide_gamut,
57 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
58
60
61 // |ImageDecoder|
63 uint32_t target_width,
64 uint32_t target_height,
65 const ImageResult& result) override;
66
68 ImageDescriptor* descriptor,
69 SkISize target_size,
70 impeller::ISize max_texture_size,
71 bool supports_wide_gamut,
72 const std::shared_ptr<const impeller::Capabilities>& capabilities,
73 const std::shared_ptr<impeller::Allocator>& allocator);
74
75 /// @brief Create a device private texture from the provided host buffer.
76 ///
77 /// @param result The image result closure that accepts the DlImage and
78 /// any encoding error messages.
79 /// @param context The Impeller graphics context.
80 /// @param buffer A host buffer containing the image to be uploaded.
81 /// @param image_info Format information about the particular image.
82 /// @param bitmap A bitmap containg the image to be uploaded.
83 /// @param gpu_disabled_switch Whether the GPU is available command encoding.
84 static void UploadTextureToPrivate(
85 ImageResult result,
86 const std::shared_ptr<impeller::Context>& context,
87 const std::shared_ptr<impeller::DeviceBuffer>& buffer,
88 const SkImageInfo& image_info,
89 const std::shared_ptr<SkBitmap>& bitmap,
90 const std::optional<SkImageInfo>& resize_info,
91 const std::shared_ptr<const fml::SyncSwitch>& gpu_disabled_switch);
92
93 /// @brief Create a texture from the provided bitmap.
94 /// @param context The Impeller graphics context.
95 /// @param bitmap A bitmap containg the image to be uploaded.
96 /// @return A DlImage.
97 static std::pair<sk_sp<DlImage>, std::string> UploadTextureToStorage(
98 const std::shared_ptr<impeller::Context>& context,
99 std::shared_ptr<SkBitmap> bitmap);
100
101 private:
102 using FutureContext = std::shared_future<std::shared_ptr<impeller::Context>>;
103 FutureContext context_;
104
105 /// Whether wide gamut rendering has been enabled (but not necessarily whether
106 /// or not it is supported).
107 const bool wide_gamut_enabled_;
108 std::shared_ptr<fml::SyncSwitch> gpu_disabled_switch_;
109
110 /// Only call this method if the GPU is available.
111 static std::pair<sk_sp<DlImage>, std::string> UnsafeUploadTextureToPrivate(
112 const std::shared_ptr<impeller::Context>& context,
113 const std::shared_ptr<impeller::DeviceBuffer>& buffer,
114 const SkImageInfo& image_info,
115 const std::optional<SkImageInfo>& resize_info);
116
118};
119
120} // namespace flutter
121
122#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_IMPELLER_H_
std::function< void(sk_sp< DlImage >, std::string)> ImageResult
void Decode(fml::RefPtr< ImageDescriptor > descriptor, uint32_t target_width, uint32_t target_height, const ImageResult &result) override
static DecompressResult DecompressTexture(ImageDescriptor *descriptor, SkISize target_size, impeller::ISize max_texture_size, bool supports_wide_gamut, const std::shared_ptr< const impeller::Capabilities > &capabilities, const std::shared_ptr< impeller::Allocator > &allocator)
static std::pair< sk_sp< DlImage >, std::string > UploadTextureToStorage(const std::shared_ptr< impeller::Context > &context, std::shared_ptr< SkBitmap > bitmap)
Create a texture from the provided bitmap.
static void UploadTextureToPrivate(ImageResult result, const std::shared_ptr< impeller::Context > &context, const std::shared_ptr< impeller::DeviceBuffer > &buffer, const SkImageInfo &image_info, const std::shared_ptr< SkBitmap > &bitmap, const std::optional< SkImageInfo > &resize_info, const std::shared_ptr< const fml::SyncSwitch > &gpu_disabled_switch)
Create a device private texture from the provided host buffer.
Creates an image descriptor for encoded or decoded image data, describing the width,...
bool allocPixelRef(SkBitmap *bitmap) override
std::shared_ptr< impeller::DeviceBuffer > GetDeviceBuffer() const
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::shared_ptr< SkBitmap > sk_bitmap
std::shared_ptr< impeller::DeviceBuffer > device_buffer
std::optional< SkImageInfo > resize_info