• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
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 GrDeferredUpload_DEFINED
9 #define GrDeferredUpload_DEFINED
10 
11 #include <functional>
12 #include "include/gpu/GrTypes.h"
13 #include "include/private/gpu/ganesh/GrTypesPriv.h"
14 #include "src/gpu/AtlasTypes.h"
15 
16 class GrTextureProxy;
17 
18 /**
19  * A word about deferred uploads and tokens: Ops should usually schedule their uploads to occur at
20  * the beginning of a frame whenever possible. These are called ASAP uploads. Of course, this
21  * requires that there are no draws that have yet to be flushed that rely on the old texture
22  * contents. In that case the ASAP upload would happen prior to the draw and therefore the draw
23  * would read the new (wrong) texture data. When this read-before-write data hazard exists they
24  * should schedule an inline upload.
25  *
26  * Ops, in conjunction with helpers such as GrDrawOpAtlas, use upload tokens to know what the most
27  * recent draw was that referenced a resource (or portion of a resource). Each draw is assigned a
28  * token. A resource (or portion thereof) can be tagged with the most recent reading draw's token.
29  * The deferred upload's target provides a facility for testing whether the draw corresponding to
30  * the token has been flushed. If it has not been flushed then the op must perform an inline upload
31  * instead so that the upload occurs after the draw depending on the old contents and before the
32  * draw depending on the updated contents. When scheduling an inline upload the op provides the
33  * token of the draw that the upload must occur before.
34  */
35 
36 /**
37  * Passed to a deferred upload when it is executed, this method allows the deferred upload to
38  * actually write its pixel data into a texture.
39  */
40 using GrDeferredTextureUploadWritePixelsFn = std::function<bool(GrTextureProxy*,
41                                                                 SkIRect,
42                                                                 GrColorType srcColorType,
43                                                                 const void*,
44                                                                 size_t rowBytes)>;
45 
46 /**
47  * A deferred texture upload is simply a std::function that takes a
48  * GrDeferredTextureUploadWritePixelsFn as a parameter. It is called when it should perform its
49  * upload as the draw/upload sequence is executed.
50  */
51 using GrDeferredTextureUploadFn = std::function<void(GrDeferredTextureUploadWritePixelsFn&)>;
52 
53 /**
54  * An interface for scheduling deferred uploads. It accepts asap and deferred inline uploads.
55  */
56 class GrDeferredUploadTarget {
57 public:
~GrDeferredUploadTarget()58     virtual ~GrDeferredUploadTarget() {}
59 
60     virtual const skgpu::TokenTracker* tokenTracker() = 0;
61 
62     /** Returns the token of the draw that this upload will occur before. */
63     virtual skgpu::AtlasToken addInlineUpload(GrDeferredTextureUploadFn&&) = 0;
64 
65     /** Returns the token of the draw that this upload will occur before. Since ASAP uploads
66         are done first during a flush, this will be the first token since the most recent
67         flush. */
68     virtual skgpu::AtlasToken addASAPUpload(GrDeferredTextureUploadFn&& upload) = 0;
69 };
70 
71 #endif
72