bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | /* |
reed@google.com | dd335ae | 2012-12-13 19:24:05 +0000 | [diff] [blame] | 2 | * Copyright 2011 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. |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 8 | #ifndef GrRenderTarget_DEFINED |
| 9 | #define GrRenderTarget_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkRect.h" |
| 12 | #include "include/gpu/GrSurface.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 13 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 14 | class GrCaps; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 15 | class GrRenderTargetOpList; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 16 | class GrRenderTargetPriv; |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 17 | class GrStencilAttachment; |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 18 | class GrBackendRenderTarget; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. |
| 22 | * A context's render target is set by setRenderTarget(). Render targets are |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 23 | * created by a createTexture with the kRenderTarget_SurfaceFlag flag. |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 24 | * Additionally, GrContext provides methods for creating GrRenderTargets |
| 25 | * that wrap externally created render targets. |
| 26 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 27 | class GrRenderTarget : virtual public GrSurface { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 28 | public: |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 29 | virtual bool alwaysClearStencil() const { return false; } |
| 30 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 31 | // GrSurface overrides |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | GrRenderTarget* asRenderTarget() override { return this; } |
Brian Salomon | 9f7d9a2 | 2018-12-11 19:01:32 +0000 | [diff] [blame] | 33 | const GrRenderTarget* asRenderTarget() const override { return this; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 34 | |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 35 | /** |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 36 | * Returns the number of samples/pixel in the color buffer (One if non-MSAA). |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 37 | */ |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 38 | int numSamples() const { return fSampleCnt; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Call to indicate the multisample contents were modified such that the |
| 42 | * render target needs to be resolved before it can be used as texture. Gr |
| 43 | * tracks this for its own drawing and thus this only needs to be called |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 44 | * when the render target has been modified outside of Gr. This has no |
| 45 | * effect on wrapped backend render targets. |
| 46 | * |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 47 | * @param rect a rect bounding the area needing resolve. NULL indicates |
| 48 | * the whole RT needs resolving. |
| 49 | */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 50 | void flagAsNeedingResolve(const SkIRect* rect = nullptr); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 51 | |
| 52 | /** |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 53 | * Call to indicate that GrRenderTarget was externally resolved. This may |
| 54 | * allow Gr to skip a redundant resolve step. |
| 55 | */ |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 56 | void flagAsResolved(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * @return true if the GrRenderTarget requires MSAA resolving |
| 60 | */ |
| 61 | bool needsResolve() const { return !fResolveRect.isEmpty(); } |
| 62 | |
| 63 | /** |
| 64 | * Returns a rect bounding the region needing resolving. |
| 65 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 66 | const SkIRect& getResolveRect() const { return fResolveRect; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 67 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 68 | // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 69 | // 0 in GL), or be unresolvable because the client didn't give us the |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 70 | // resolve destination. |
| 71 | enum ResolveType { |
| 72 | kCanResolve_ResolveType, |
| 73 | kAutoResolves_ResolveType, |
| 74 | kCantResolve_ResolveType, |
| 75 | }; |
| 76 | virtual ResolveType getResolveType() const = 0; |
| 77 | |
Robert Phillips | b67821d | 2017-12-13 15:00:45 -0500 | [diff] [blame] | 78 | virtual GrBackendRenderTarget getBackendRenderTarget() const = 0; |
| 79 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 80 | // Checked when this object is asked to attach a stencil buffer. |
| 81 | virtual bool canAttemptStencilAttachment() const = 0; |
| 82 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 83 | // Provides access to functions that aren't part of the public API. |
| 84 | GrRenderTargetPriv renderTargetPriv(); |
| 85 | const GrRenderTargetPriv renderTargetPriv() const; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 86 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 87 | protected: |
Brian Salomon | a9c2257 | 2019-08-05 12:57:09 -0400 | [diff] [blame] | 88 | GrRenderTarget(GrGpu*, const SkISize&, GrPixelConfig, int sampleCount, GrProtected, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 89 | GrStencilAttachment* = nullptr); |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 90 | ~GrRenderTarget() override; |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 91 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 92 | // override of GrResource |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 93 | void onAbandon() override; |
| 94 | void onRelease() override; |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 95 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 96 | private: |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 97 | // Allows the backends to perform any additional work that is required for attaching a |
| 98 | // GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto |
| 99 | // the GrRenderTarget. This function must return false if any failures occur when completing the |
| 100 | // stencil attachment. |
| 101 | virtual bool completeStencilAttachment() = 0; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 102 | |
| 103 | friend class GrRenderTargetPriv; |
| 104 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 105 | int fSampleCnt; |
| 106 | int fSamplePatternKey; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 107 | sk_sp<GrStencilAttachment> fStencilAttachment; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 108 | SkIRect fResolveRect; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 109 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 110 | typedef GrSurface INHERITED; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 113 | #endif |