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