bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 8 | #ifndef GrDrawOp_DEFINED |
| 9 | #define GrDrawOp_DEFINED |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 10 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 11 | #include <functional> |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 12 | #include "GrOp.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 13 | #include "GrPipeline.h" |
| 14 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 15 | class GrAppliedClip; |
| 16 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 17 | /** |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 18 | * GrDrawOps are flushed in two phases (preDraw, and draw). In preDraw uploads to GrGpuResources |
| 19 | * and draws are determined and scheduled. They are issued in the draw phase. GrDrawOpUploadToken is |
| 20 | * used to sequence the uploads relative to each other and to draws. |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 21 | **/ |
| 22 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 23 | class GrDrawOpUploadToken { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 24 | public: |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 25 | static GrDrawOpUploadToken AlreadyFlushedToken() { return GrDrawOpUploadToken(0); } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 26 | |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 27 | GrDrawOpUploadToken(const GrDrawOpUploadToken& that) : fSequenceNumber(that.fSequenceNumber) {} |
| 28 | GrDrawOpUploadToken& operator =(const GrDrawOpUploadToken& that) { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 29 | fSequenceNumber = that.fSequenceNumber; |
| 30 | return *this; |
| 31 | } |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 32 | bool operator==(const GrDrawOpUploadToken& that) const { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 33 | return fSequenceNumber == that.fSequenceNumber; |
| 34 | } |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 35 | bool operator!=(const GrDrawOpUploadToken& that) const { return !(*this == that); } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 36 | |
| 37 | private: |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 38 | GrDrawOpUploadToken(); |
| 39 | explicit GrDrawOpUploadToken(uint64_t sequenceNumber) : fSequenceNumber(sequenceNumber) {} |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 40 | friend class GrOpFlushState; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 41 | uint64_t fSequenceNumber; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /** |
Brian Salomon | 53e4c3c | 2016-12-21 11:38:53 -0500 | [diff] [blame] | 45 | * Base class for GrOps that draw. These ops have a GrPipeline installed by GrOpList. |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 46 | */ |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 47 | class GrDrawOp : public GrOp { |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 48 | public: |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 49 | /** Method that performs an upload on behalf of a DeferredUploadFn. */ |
Robert Phillips | acaa607 | 2017-07-28 10:54:53 -0400 | [diff] [blame] | 50 | using WritePixelsFn = std::function<bool(GrTextureProxy*, |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 51 | int left, int top, int width, int height, |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 52 | GrPixelConfig config, const void* buffer, |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 53 | size_t rowBytes)>; |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 54 | /** See comments before GrDrawOp::Target definition on how deferred uploaders work. */ |
jvanverth | c3d706f | 2016-04-20 10:33:27 -0700 | [diff] [blame] | 55 | using DeferredUploadFn = std::function<void(WritePixelsFn&)>; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 56 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 57 | class Target; |
| 58 | |
Brian Salomon | b5cb683 | 2017-02-24 11:01:15 -0500 | [diff] [blame] | 59 | GrDrawOp(uint32_t classID) : INHERITED(classID) {} |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 60 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 61 | /** |
| 62 | * This information is required to determine how to compute a GrAppliedClip from a GrClip for |
| 63 | * this op. |
| 64 | */ |
| 65 | enum class FixedFunctionFlags : uint32_t { |
| 66 | kNone = 0x0, |
| 67 | /** Indices that the op will enable MSAA or mixed samples rendering. */ |
| 68 | kUsesHWAA = 0x1, |
| 69 | /** Indices that the op reads and/or writes the stencil buffer */ |
| 70 | kUsesStencil = 0x2, |
| 71 | }; |
| 72 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(FixedFunctionFlags); |
| 73 | virtual FixedFunctionFlags fixedFunctionFlags() const = 0; |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 74 | |
Brian Salomon | f86d37b | 2017-06-16 10:04:34 -0400 | [diff] [blame] | 75 | enum class RequiresDstTexture : bool { kNo = false, kYes = true }; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 76 | /** |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 77 | * This is called after the GrAppliedClip has been computed and just prior to recording the op |
Brian Salomon | f86d37b | 2017-06-16 10:04:34 -0400 | [diff] [blame] | 78 | * or combining it with a previously recorded op. The op should convert any proxies or resources |
| 79 | * it owns to "pending io" status so that resource allocation can be more optimal. Additionally, |
| 80 | * at this time the op must report whether a copy of the destination (or destination texture |
| 81 | * itself) needs to be provided to the GrXferProcessor when this op executes. |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 82 | */ |
Brian Salomon | f86d37b | 2017-06-16 10:04:34 -0400 | [diff] [blame] | 83 | virtual RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) = 0; |
Brian Salomon | 5298dc8 | 2017-02-22 11:52:03 -0500 | [diff] [blame] | 84 | |
Brian Salomon | 7c3e718 | 2016-12-01 09:35:30 -0500 | [diff] [blame] | 85 | protected: |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 86 | struct QueuedUpload { |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 87 | QueuedUpload(DeferredUploadFn&& upload, GrDrawOpUploadToken token) |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 88 | : fUpload(std::move(upload)) |
| 89 | , fUploadBeforeToken(token) {} |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 90 | DeferredUploadFn fUpload; |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 91 | GrDrawOpUploadToken fUploadBeforeToken; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 92 | }; |
Brian Salomon | 9afd371 | 2016-12-01 10:59:09 -0500 | [diff] [blame] | 93 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 94 | SkTArray<QueuedUpload> fInlineUploads; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 95 | |
| 96 | private: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 97 | typedef GrOp INHERITED; |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 100 | GR_MAKE_BITFIELD_CLASS_OPS(GrDrawOp::FixedFunctionFlags); |
| 101 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 102 | #endif |