blob: 54b9f1674bb0b30ab6a78d7741e649e8cde21782 [file] [log] [blame]
bsalomon16b99132015-08-13 14:55:50 -07001/*
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 Salomon53e4c3c2016-12-21 11:38:53 -05008#ifndef GrDrawOp_DEFINED
9#define GrDrawOp_DEFINED
bsalomon16b99132015-08-13 14:55:50 -070010
bsalomon342bfc22016-04-01 06:06:20 -070011#include <functional>
Brian Salomon25a88092016-12-01 09:36:50 -050012#include "GrOp.h"
bsalomon16b99132015-08-13 14:55:50 -070013#include "GrPipeline.h"
14
Brian Salomon54d212e2017-03-21 14:22:38 -040015class GrAppliedClip;
16
bsalomon16b99132015-08-13 14:55:50 -070017/**
Brian Salomon9afd3712016-12-01 10:59:09 -050018 * 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.
bsalomon75398562015-08-17 12:55:38 -070021 **/
22
Brian Salomon9afd3712016-12-01 10:59:09 -050023class GrDrawOpUploadToken {
bsalomon75398562015-08-17 12:55:38 -070024public:
Brian Salomon9afd3712016-12-01 10:59:09 -050025 static GrDrawOpUploadToken AlreadyFlushedToken() { return GrDrawOpUploadToken(0); }
bsalomon75398562015-08-17 12:55:38 -070026
Brian Salomon9afd3712016-12-01 10:59:09 -050027 GrDrawOpUploadToken(const GrDrawOpUploadToken& that) : fSequenceNumber(that.fSequenceNumber) {}
28 GrDrawOpUploadToken& operator =(const GrDrawOpUploadToken& that) {
bsalomon342bfc22016-04-01 06:06:20 -070029 fSequenceNumber = that.fSequenceNumber;
30 return *this;
31 }
Brian Salomon9afd3712016-12-01 10:59:09 -050032 bool operator==(const GrDrawOpUploadToken& that) const {
bsalomon342bfc22016-04-01 06:06:20 -070033 return fSequenceNumber == that.fSequenceNumber;
34 }
Brian Salomon9afd3712016-12-01 10:59:09 -050035 bool operator!=(const GrDrawOpUploadToken& that) const { return !(*this == that); }
bsalomon75398562015-08-17 12:55:38 -070036
37private:
Brian Salomon9afd3712016-12-01 10:59:09 -050038 GrDrawOpUploadToken();
39 explicit GrDrawOpUploadToken(uint64_t sequenceNumber) : fSequenceNumber(sequenceNumber) {}
Brian Salomon742e31d2016-12-07 17:06:19 -050040 friend class GrOpFlushState;
bsalomon342bfc22016-04-01 06:06:20 -070041 uint64_t fSequenceNumber;
bsalomon75398562015-08-17 12:55:38 -070042};
43
44/**
Brian Salomon53e4c3c2016-12-21 11:38:53 -050045 * Base class for GrOps that draw. These ops have a GrPipeline installed by GrOpList.
bsalomon16b99132015-08-13 14:55:50 -070046 */
Brian Salomon9afd3712016-12-01 10:59:09 -050047class GrDrawOp : public GrOp {
bsalomon16b99132015-08-13 14:55:50 -070048public:
jvanverthc3d706f2016-04-20 10:33:27 -070049 /** Method that performs an upload on behalf of a DeferredUploadFn. */
Robert Phillipsacaa6072017-07-28 10:54:53 -040050 using WritePixelsFn = std::function<bool(GrTextureProxy*,
bsalomon342bfc22016-04-01 06:06:20 -070051 int left, int top, int width, int height,
jvanverthc3d706f2016-04-20 10:33:27 -070052 GrPixelConfig config, const void* buffer,
bsalomon342bfc22016-04-01 06:06:20 -070053 size_t rowBytes)>;
Brian Salomon9afd3712016-12-01 10:59:09 -050054 /** See comments before GrDrawOp::Target definition on how deferred uploaders work. */
jvanverthc3d706f2016-04-20 10:33:27 -070055 using DeferredUploadFn = std::function<void(WritePixelsFn&)>;
bsalomon342bfc22016-04-01 06:06:20 -070056
bsalomon75398562015-08-17 12:55:38 -070057 class Target;
58
Brian Salomonb5cb6832017-02-24 11:01:15 -050059 GrDrawOp(uint32_t classID) : INHERITED(classID) {}
bsalomon16b99132015-08-13 14:55:50 -070060
Brian Salomon54d212e2017-03-21 14:22:38 -040061 /**
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;
bsalomon16b99132015-08-13 14:55:50 -070074
Brian Salomonf86d37b2017-06-16 10:04:34 -040075 enum class RequiresDstTexture : bool { kNo = false, kYes = true };
Brian Salomon5298dc82017-02-22 11:52:03 -050076 /**
Brian Salomon54d212e2017-03-21 14:22:38 -040077 * This is called after the GrAppliedClip has been computed and just prior to recording the op
Brian Salomonf86d37b2017-06-16 10:04:34 -040078 * 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 Salomon5298dc82017-02-22 11:52:03 -050082 */
Brian Salomonf86d37b2017-06-16 10:04:34 -040083 virtual RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*) = 0;
Brian Salomon5298dc82017-02-22 11:52:03 -050084
Brian Salomon7c3e7182016-12-01 09:35:30 -050085protected:
bsalomon342bfc22016-04-01 06:06:20 -070086 struct QueuedUpload {
Brian Salomon9afd3712016-12-01 10:59:09 -050087 QueuedUpload(DeferredUploadFn&& upload, GrDrawOpUploadToken token)
bsalomon342bfc22016-04-01 06:06:20 -070088 : fUpload(std::move(upload))
89 , fUploadBeforeToken(token) {}
Brian Salomon54d212e2017-03-21 14:22:38 -040090 DeferredUploadFn fUpload;
Brian Salomon9afd3712016-12-01 10:59:09 -050091 GrDrawOpUploadToken fUploadBeforeToken;
bsalomon342bfc22016-04-01 06:06:20 -070092 };
Brian Salomon9afd3712016-12-01 10:59:09 -050093
Brian Salomon54d212e2017-03-21 14:22:38 -040094 SkTArray<QueuedUpload> fInlineUploads;
bsalomon75398562015-08-17 12:55:38 -070095
96private:
Brian Salomon25a88092016-12-01 09:36:50 -050097 typedef GrOp INHERITED;
bsalomon16b99132015-08-13 14:55:50 -070098};
99
Brian Salomon54d212e2017-03-21 14:22:38 -0400100GR_MAKE_BITFIELD_CLASS_OPS(GrDrawOp::FixedFunctionFlags);
101
bsalomon16b99132015-08-13 14:55:50 -0700102#endif