Flutter Engine
The Flutter Engine
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"
11#include "flutter/lib/ui/painting/image_decoder.h"
15
16namespace impeller {
17class Context;
18class Allocator;
19class DeviceBuffer;
20} // namespace impeller
21
22namespace flutter {
23
25 public:
26 explicit ImpellerAllocator(std::shared_ptr<impeller::Allocator> allocator);
27
28 ~ImpellerAllocator() = default;
29
30 // |Allocator|
31 bool allocPixelRef(SkBitmap* bitmap) override;
32
33 std::shared_ptr<impeller::DeviceBuffer> GetDeviceBuffer() const;
34
35 private:
36 std::shared_ptr<impeller::Allocator> allocator_;
37 std::shared_ptr<impeller::DeviceBuffer> buffer_;
38};
39
41 std::shared_ptr<impeller::DeviceBuffer> device_buffer;
42 std::shared_ptr<SkBitmap> sk_bitmap;
44 std::string decode_error;
45};
46
47class ImageDecoderImpeller final : public ImageDecoder {
48 public:
50 const TaskRunners& runners,
51 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
52 const fml::WeakPtr<IOManager>& io_manager,
53 bool supports_wide_gamut,
54 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
55
57
58 // |ImageDecoder|
60 uint32_t target_width,
61 uint32_t target_height,
62 const ImageResult& result) override;
63
65 ImageDescriptor* descriptor,
66 SkISize target_size,
67 impeller::ISize max_texture_size,
68 bool supports_wide_gamut,
69 const std::shared_ptr<impeller::Allocator>& allocator);
70
71 /// @brief Create a device private texture from the provided host buffer.
72 /// This method is only suported on the metal backend.
73 /// @param context The Impeller graphics context.
74 /// @param buffer A host buffer containing the image to be uploaded.
75 /// @param image_info Format information about the particular image.
76 /// @param bitmap A bitmap containg the image to be uploaded.
77 /// @param gpu_disabled_switch Whether the GPU is available command encoding.
78 /// @return A DlImage.
79 static std::pair<sk_sp<DlImage>, std::string> UploadTextureToPrivate(
80 const std::shared_ptr<impeller::Context>& context,
81 const std::shared_ptr<impeller::DeviceBuffer>& buffer,
82 const SkImageInfo& image_info,
83 const std::shared_ptr<SkBitmap>& bitmap,
84 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
85
86 /// @brief Create a host visible texture from the provided bitmap.
87 /// @param context The Impeller graphics context.
88 /// @param bitmap A bitmap containg the image to be uploaded.
89 /// @param create_mips Whether mipmaps should be generated for the given
90 /// image.
91 /// @param gpu_disabled_switch Whether the GPU is available for mipmap
92 /// creation.
93 /// @return A DlImage.
94 static std::pair<sk_sp<DlImage>, std::string> UploadTextureToStorage(
95 const std::shared_ptr<impeller::Context>& context,
96 std::shared_ptr<SkBitmap> bitmap,
97 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch,
98 impeller::StorageMode storage_mode,
99 bool create_mips = true);
100
101 private:
102 using FutureContext = std::shared_future<std::shared_ptr<impeller::Context>>;
103 FutureContext context_;
104 const bool supports_wide_gamut_;
105 std::shared_ptr<fml::SyncSwitch> gpu_disabled_switch_;
106
107 FML_DISALLOW_COPY_AND_ASSIGN(ImageDecoderImpeller);
108};
109
110} // namespace flutter
111
112#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_IMPELLER_H_
void Decode(fml::RefPtr< ImageDescriptor > descriptor, uint32_t target_width, uint32_t target_height, const ImageResult &result) override
static std::pair< sk_sp< DlImage >, std::string > UploadTextureToStorage(const std::shared_ptr< impeller::Context > &context, std::shared_ptr< SkBitmap > bitmap, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch, impeller::StorageMode storage_mode, bool create_mips=true)
Create a host visible texture from the provided bitmap.
ImageDecoderImpeller(const TaskRunners &runners, std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner, const fml::WeakPtr< IOManager > &io_manager, bool supports_wide_gamut, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch)
static std::pair< sk_sp< DlImage >, std::string > UploadTextureToPrivate(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::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch)
Create a device private texture from the provided host buffer. This method is only suported on the me...
static DecompressResult DecompressTexture(ImageDescriptor *descriptor, SkISize target_size, impeller::ISize max_texture_size, bool supports_wide_gamut, const std::shared_ptr< impeller::Allocator > &allocator)
std::function< void(sk_sp< DlImage >, std::string)> ImageResult
Definition: image_decoder.h:35
Creates an image descriptor for encoded or decoded image data, describing the width,...
bool allocPixelRef(SkBitmap *bitmap) override
ImpellerAllocator(std::shared_ptr< impeller::Allocator > allocator)
std::shared_ptr< impeller::DeviceBuffer > GetDeviceBuffer() const
GAsyncResult * result
Definition: bitmap.py:1
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:32
Definition: SkSize.h:16
std::shared_ptr< SkBitmap > sk_bitmap
std::shared_ptr< impeller::DeviceBuffer > device_buffer