Flutter Engine
The Flutter Engine
UploadTask.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef skgpu_graphite_task_UploadTask_DEFINED
9#define skgpu_graphite_task_UploadTask_DEFINED
10
12
14#include "include/core/SkRect.h"
18
19#include <memory>
20
21namespace skgpu::graphite {
22
23class Buffer;
24class Recorder;
25class TextureProxy;
26
27struct MipLevel {
28 const void* fPixels = nullptr;
29 size_t fRowBytes = 0;
30};
31
32/**
33 * The ConditionalUploadContext, if set, is used to determine whether an upload needs to occur
34 * on Recording playback. Clients will need to create their own subclasses to store the
35 * necessary data and override the needsUpload() method to do this check.
36 */
38public:
40
41 // Return true if the upload needs to occur; false if it should be skipped this time.
42 virtual bool needsUpload(Context*) = 0;
43
44 // Return true if the upload should be kept in the task (and possibly re-executed on replay
45 // depending on needsUpload()'s return value), or false if it should be discarded and never
46 // attempt to be uploaded on any replay.
47 virtual bool uploadSubmitted() { return true; }
48};
49
50/**
51 * ImageUploadContext is an implementation of ConditionalUploadContext that returns true on
52 * the first call to needsUpload() and then returns false on subsequent calls. This is used to
53 * upload an image once and then avoid redundant uploads after that.
54 */
56public:
57 ~ImageUploadContext() override {}
58
59 // Always upload, since it will be discarded right afterwards
60 bool needsUpload(Context*) override { return true; }
61
62 // Always return false so the upload instance is discarded after the first execution
63 bool uploadSubmitted() override { return false; }
64};
65
66/**
67 * An UploadInstance represents a single set of uploads from a buffer to texture that
68 * can be processed in a single command.
69 */
71public:
73 sk_sp<TextureProxy> targetProxy,
74 const SkColorInfo& srcColorInfo,
75 const SkColorInfo& dstColorInfo,
77 const SkIRect& dstRect,
78 std::unique_ptr<ConditionalUploadContext>);
80 sk_sp<TextureProxy> targetProxy,
81 const void* data,
82 size_t dataSize);
83
84 static UploadInstance Invalid() { return {}; }
85
89
90 bool isValid() const { return fBuffer != nullptr && fTextureProxy != nullptr; }
91
93
94 // Adds upload command to the given CommandBuffer, returns false if the instance should be
95 // discarded.
97
98private:
100 // Copy data is appended directly after the object is created
101 UploadInstance(const Buffer*,
102 size_t bytesPerPixel,
104 std::unique_ptr<ConditionalUploadContext> = nullptr);
105
106 const Buffer* fBuffer;
107 size_t fBytesPerPixel;
108 sk_sp<TextureProxy> fTextureProxy;
110 std::unique_ptr<ConditionalUploadContext> fConditionalContext;
111};
112
113/**
114 * An UploadList is a mutable collection of UploadCommands.
115 *
116 * Currently commands are accumulated in order and processed in the same order. Dependency
117 * management is expected to be handled by the TaskGraph.
118 *
119 * When an upload is appended to the list its data will be copied to a Buffer in
120 * preparation for a deferred upload.
121 */
123public:
125 sk_sp<TextureProxy> targetProxy,
126 const SkColorInfo& srcColorInfo,
127 const SkColorInfo& dstColorInfo,
129 const SkIRect& dstRect,
130 std::unique_ptr<ConditionalUploadContext>);
131
132 int size() { return fInstances.size(); }
133
134private:
135 friend class UploadTask;
136
138};
139
140/*
141 * An UploadTask is a immutable collection of UploadCommands.
142 *
143 * When adding commands to the commandBuffer the texture proxies in those
144 * commands will be instantiated and the copy command added.
145 */
146class UploadTask final : public Task {
147public:
150
151 ~UploadTask() override;
152
155 const RuntimeEffectDictionary*) override;
156
158
159private:
162
164};
165
166} // namespace skgpu::graphite
167
168#endif // skgpu_graphite_task_UploadTask_DEFINED
virtual bool needsUpload(Context *)=0
bool needsUpload(Context *) override
Definition: UploadTask.h:60
static UploadInstance Invalid()
Definition: UploadTask.h:84
UploadInstance(UploadInstance &&)
static UploadInstance MakeCompressed(Recorder *, sk_sp< TextureProxy > targetProxy, const void *data, size_t dataSize)
Definition: UploadTask.cpp:235
static UploadInstance Make(Recorder *, sk_sp< TextureProxy > targetProxy, const SkColorInfo &srcColorInfo, const SkColorInfo &dstColorInfo, SkSpan< const MipLevel > levels, const SkIRect &dstRect, std::unique_ptr< ConditionalUploadContext >)
Definition: UploadTask.cpp:91
Task::Status addCommand(Context *, CommandBuffer *, Task::ReplayTargetData) const
Definition: UploadTask.cpp:346
bool prepareResources(ResourceProvider *)
Definition: UploadTask.cpp:331
UploadInstance & operator=(UploadInstance &&)
bool recordUpload(Recorder *, sk_sp< TextureProxy > targetProxy, const SkColorInfo &srcColorInfo, const SkColorInfo &dstColorInfo, SkSpan< const MipLevel > levels, const SkIRect &dstRect, std::unique_ptr< ConditionalUploadContext >)
Definition: UploadTask.cpp:405
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
Definition: UploadTask.cpp:449
static sk_sp< UploadTask > Make(UploadList *)
Definition: UploadTask.cpp:425
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Definition: UploadTask.cpp:463
Definition: SkRect.h:32
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63