• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_UploadTask_DEFINED
9 #define skgpu_UploadTask_DEFINED
10 
11 #include "experimental/graphite/src/Task.h"
12 
13 #include <vector>
14 
15 #include "include/core/SkImageInfo.h"
16 #include "include/core/SkRect.h"
17 #include "include/core/SkRefCnt.h"
18 
19 namespace skgpu {
20 
21 class Buffer;
22 struct BufferTextureCopyData;
23 class CommandBuffer;
24 class Recorder;
25 class ResourceProvider;
26 class TextureProxy;
27 
28 struct MipLevel {
29     const void* fPixels = nullptr;
30     size_t fRowBytes = 0;
31 };
32 
33 /**
34  * An UploadCommand represents a single set of uploads from a buffer to texture that
35  * can be processed in a single command.
36  */
37 struct UploadCommand {
38     void addCommand(ResourceProvider*, CommandBuffer*) const;
39 
40     sk_sp<Buffer> fBuffer;
41     sk_sp<TextureProxy> fTextureProxy;
42     std::vector<BufferTextureCopyData> fCopyData;
43 };
44 
45 
46 /**
47  * An UploadList is a mutable collection of UploadCommands.
48  *
49  * Currently commands are accumulated in order and processed in the same order. Dependency
50  * management is expected to be handled by the TaskGraph.
51  *
52  * When an upload is appended to the list its data will be copied to a Buffer in
53  * preparation for a deferred upload.
54  */
55 class UploadList {
56 public:
57     bool appendUpload(Recorder*,
58                       sk_sp<TextureProxy> targetProxy,
59                       SkColorType colorType,
60                       const std::vector<MipLevel>& levels,
61                       const SkIRect& dstRect);
62 
63 private:
64     friend class UploadTask;
65 
66     std::vector<UploadCommand> fCommands;
67 };
68 
69 /*
70  * An UploadTask is a immutable collection of UploadCommands.
71  *
72  * When adding commands to the commandBuffer the texture proxies in those
73  * commands will be instantiated and the copy command added.
74  */
75 class UploadTask final : public Task {
76 public:
77     static sk_sp<UploadTask> Make(UploadList*);
78 
79     ~UploadTask() override;
80 
81     void addCommands(ResourceProvider*, CommandBuffer*) override;
82 
83 private:
84     UploadTask(std::vector<UploadCommand>);
85 
86     std::vector<UploadCommand> fCommands;
87 };
88 
89 } // namespace skgpu
90 
91 #endif // skgpu_UploadTask_DEFINED
92