Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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/abseil-cpp/absl/status/statusor.h"
17#include "third_party/skia/include/core/SkBitmap.h"
18
19namespace impeller {
20class Context;
21class Allocator;
22class DeviceBuffer;
23} // namespace impeller
24
25namespace flutter {
26
27class ImpellerAllocator : public SkBitmap::Allocator {
28 public:
29 explicit ImpellerAllocator(std::shared_ptr<impeller::Allocator> allocator);
30
31 ~ImpellerAllocator() = default;
32
33 // |Allocator|
34 bool allocPixelRef(SkBitmap* bitmap) override;
35
36 std::shared_ptr<impeller::DeviceBuffer> GetDeviceBuffer() const;
37
38 private:
39 std::shared_ptr<impeller::Allocator> allocator_;
40 std::shared_ptr<impeller::DeviceBuffer> buffer_;
41};
42
43class ImageDecoderImpeller final : public ImageDecoder {
44 public:
46 const TaskRunners& runners,
47 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
48 const fml::WeakPtr<IOManager>& io_manager,
49 bool supports_wide_gamut,
50 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
51
53
54 static std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type);
55
56 // |ImageDecoder|
58 const Options& options,
59 const ImageResult& result) override;
60
65
67 std::shared_ptr<impeller::DeviceBuffer> device_buffer;
69 std::optional<SkImageInfo> resize_info;
70 };
71
72 static absl::StatusOr<DecompressResult> DecompressTexture(
73 ImageDescriptor* descriptor,
74 const ImageDecoder::Options& options,
75 impeller::ISize max_texture_size,
76 bool supports_wide_gamut,
77 const std::shared_ptr<const impeller::Capabilities>& capabilities,
78 const std::shared_ptr<impeller::Allocator>& allocator);
79
80 /// @brief Create a device private texture from the provided host buffer.
81 ///
82 /// @param result The image result closure that accepts the DlImage and
83 /// any encoding error messages.
84 /// @param context The Impeller graphics context.
85 /// @param buffer A host buffer containing the image to be uploaded.
86 /// @param image_info Format information about the particular image.
87 /// @param bitmap A bitmap containg the image to be uploaded.
88 /// @param gpu_disabled_switch Whether the GPU is available command encoding.
89 static void UploadTextureToPrivate(
90 ImageResult result,
91 const std::shared_ptr<impeller::Context>& context,
92 const std::shared_ptr<impeller::DeviceBuffer>& buffer,
93 const ImageInfo& image_info,
94 const std::optional<SkImageInfo>& resize_info,
95 const std::shared_ptr<const fml::SyncSwitch>& gpu_disabled_switch);
96
97 /// @brief Create a texture from the provided bitmap.
98 /// @param context The Impeller graphics context.
99 /// @param bitmap A bitmap containg the image to be uploaded.
100 /// @return A DlImage.
101 static std::pair<sk_sp<DlImage>, std::string> UploadTextureToStorage(
102 const std::shared_ptr<impeller::Context>& context,
103 std::shared_ptr<SkBitmap> bitmap);
104
105 private:
106 using FutureContext = std::shared_future<std::shared_ptr<impeller::Context>>;
107 FutureContext context_;
108
109 /// Whether wide gamut rendering has been enabled (but not necessarily whether
110 /// or not it is supported).
111 const bool wide_gamut_enabled_;
112 std::shared_ptr<fml::SyncSwitch> gpu_disabled_switch_;
113
114 /// Only call this method if the GPU is available.
115 static std::pair<sk_sp<DlImage>, std::string> UnsafeUploadTextureToPrivate(
116 const std::shared_ptr<impeller::Context>& context,
117 const std::shared_ptr<impeller::DeviceBuffer>& buffer,
118 const ImageInfo& image_info,
119 const std::optional<SkImageInfo>& resize_info);
120
122};
123
124} // namespace flutter
125
126#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_IMPELLER_H_
GLenum type
std::function< void(sk_sp< DlImage >, std::string)> ImageResult
static absl::StatusOr< DecompressResult > DecompressTexture(ImageDescriptor *descriptor, const ImageDecoder::Options &options, 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::optional< impeller::PixelFormat > ToPixelFormat(SkColorType type)
static void UploadTextureToPrivate(ImageResult result, const std::shared_ptr< impeller::Context > &context, const std::shared_ptr< impeller::DeviceBuffer > &buffer, const ImageInfo &image_info, 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.
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.
void Decode(fml::RefPtr< ImageDescriptor > descriptor, const Options &options, const ImageResult &result) override
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 > bitmap
std::shared_ptr< ImpellerAllocator > allocator
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99
std::shared_ptr< impeller::DeviceBuffer > device_buffer