Flutter Engine
The Flutter Engine
image_decoder.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_H_
6#define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_H_
7
8#include <memory>
9
10#include "flutter/common/settings.h"
11#include "flutter/common/task_runners.h"
12#include "flutter/display_list/image/dl_image.h"
13#include "flutter/fml/concurrent_message_loop.h"
14#include "flutter/lib/ui/io_manager.h"
15#include "flutter/lib/ui/painting/image_descriptor.h"
16
17namespace flutter {
18
19// An object that coordinates image decompression and texture upload across
20// multiple threads/components in the shell. This object must be created,
21// accessed and collected on the UI thread (typically the engine or its runtime
22// controller). None of the expensive operations performed by this component
23// occur in a frame pipeline.
25 public:
26 static std::unique_ptr<ImageDecoder> Make(
27 const Settings& settings,
28 const TaskRunners& runners,
29 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
30 fml::WeakPtr<IOManager> io_manager,
31 const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch);
32
33 virtual ~ImageDecoder();
34
35 using ImageResult = std::function<void(sk_sp<DlImage>, std::string)>;
36
37 // Takes an image descriptor and returns a handle to a texture resident on the
38 // GPU. All image decompression and resizes are done on a worker thread
39 // concurrently. Texture upload is done on the IO thread and the result
40 // returned back on the UI thread. On error, the texture is null but the
41 // callback is guaranteed to return on the UI thread.
42 virtual void Decode(fml::RefPtr<ImageDescriptor> descriptor,
43 uint32_t target_width,
44 uint32_t target_height,
45 const ImageResult& result) = 0;
46
48
49 protected:
51 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner_;
53
55 const TaskRunners& runners,
56 std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
57 fml::WeakPtr<IOManager> io_manager);
58
59 private:
61
62 FML_DISALLOW_COPY_AND_ASSIGN(ImageDecoder);
63};
64
65} // namespace flutter
66
67#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_H_
std::function< void(sk_sp< DlImage >, std::string)> ImageResult
Definition: image_decoder.h:35
virtual void Decode(fml::RefPtr< ImageDescriptor > descriptor, uint32_t target_width, uint32_t target_height, const ImageResult &result)=0
std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner_
Definition: image_decoder.h:51
ImageDecoder(const TaskRunners &runners, std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner, fml::WeakPtr< IOManager > io_manager)
fml::WeakPtr< ImageDecoder > GetWeakPtr() const
static std::unique_ptr< ImageDecoder > Make(const Settings &settings, const TaskRunners &runners, std::shared_ptr< fml::ConcurrentTaskRunner > concurrent_task_runner, fml::WeakPtr< IOManager > io_manager, const std::shared_ptr< fml::SyncSwitch > &gpu_disabled_switch)
fml::WeakPtr< IOManager > io_manager_
Definition: image_decoder.h:52
GAsyncResult * result
Dart_NativeFunction function
Definition: fuchsia.cc:51