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 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 11 | #include "GrSurface.h" |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 12 | #include "SkRect.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 13 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 14 | class GrStencilBuffer; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * GrRenderTarget represents a 2D buffer of pixels that can be rendered to. |
| 18 | * A context's render target is set by setRenderTarget(). Render targets are |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 19 | * created by a createTexture with the kRenderTarget_SurfaceFlag flag. |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 20 | * Additionally, GrContext provides methods for creating GrRenderTargets |
| 21 | * that wrap externally created render targets. |
| 22 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 23 | class GrRenderTarget : virtual public GrSurface { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 24 | public: |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 25 | SK_DECLARE_INST_COUNT(GrRenderTarget) |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 26 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 27 | // GrSurface overrides |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 28 | virtual GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; } |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 29 | virtual const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return this; } |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 30 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 31 | // GrRenderTarget |
| 32 | /** |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 33 | * If this RT is multisampled, this is the multisample buffer |
| 34 | * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL) |
| 35 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 36 | virtual GrBackendObject getRenderTargetHandle() const = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * If this RT is multisampled, this is the buffer it is resolved to. |
| 40 | * Otherwise, same as getRenderTargetHandle(). |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 41 | * (In GL a separate FBO ID is used for the MSAA and resolved buffers) |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 42 | * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL) |
| 43 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 44 | virtual GrBackendObject getRenderTargetResolvedHandle() const = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 47 | * @return true if the surface is multisampled, false otherwise |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 48 | */ |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 49 | bool isMultisampled() const { return 0 != fDesc.fSampleCnt; } |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * @return the number of samples-per-pixel or zero if non-MSAA. |
| 53 | */ |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 54 | int numSamples() const { return fDesc.fSampleCnt; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Call to indicate the multisample contents were modified such that the |
| 58 | * render target needs to be resolved before it can be used as texture. Gr |
| 59 | * 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] | 60 | * when the render target has been modified outside of Gr. This has no |
| 61 | * effect on wrapped backend render targets. |
| 62 | * |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 63 | * @param rect a rect bounding the area needing resolve. NULL indicates |
| 64 | * the whole RT needs resolving. |
| 65 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 66 | void flagAsNeedingResolve(const SkIRect* rect = NULL); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Call to override the region that needs to be resolved. |
| 70 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 71 | void overrideResolveRect(const SkIRect rect); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Call to indicate that GrRenderTarget was externally resolved. This may |
| 75 | * allow Gr to skip a redundant resolve step. |
| 76 | */ |
| 77 | void flagAsResolved() { fResolveRect.setLargestInverted(); } |
| 78 | |
| 79 | /** |
| 80 | * @return true if the GrRenderTarget requires MSAA resolving |
| 81 | */ |
| 82 | bool needsResolve() const { return !fResolveRect.isEmpty(); } |
| 83 | |
| 84 | /** |
| 85 | * Returns a rect bounding the region needing resolving. |
| 86 | */ |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 87 | const SkIRect& getResolveRect() const { return fResolveRect; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 88 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 89 | /** |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 90 | * Provide a performance hint that the render target's contents are allowed |
| 91 | * to become undefined. |
| 92 | */ |
| 93 | void discard(); |
| 94 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 95 | // 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] | 96 | // 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] | 97 | // resolve destination. |
| 98 | enum ResolveType { |
| 99 | kCanResolve_ResolveType, |
| 100 | kAutoResolves_ResolveType, |
| 101 | kCantResolve_ResolveType, |
| 102 | }; |
| 103 | virtual ResolveType getResolveType() const = 0; |
| 104 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 105 | /** |
| 106 | * GrStencilBuffer is not part of the public API. |
| 107 | */ |
| 108 | GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; } |
| 109 | void setStencilBuffer(GrStencilBuffer* stencilBuffer); |
| 110 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 111 | protected: |
| 112 | GrRenderTarget(GrGpu* gpu, |
bsalomon@google.com | 7283022 | 2013-01-23 20:25:22 +0000 | [diff] [blame] | 113 | bool isWrapped, |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 114 | const GrSurfaceDesc& desc) |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 115 | : INHERITED(gpu, isWrapped, desc) |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 116 | , fStencilBuffer(NULL) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 117 | fResolveRect.setLargestInverted(); |
| 118 | } |
| 119 | |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 120 | // override of GrResource |
| 121 | virtual void onAbandon() SK_OVERRIDE; |
| 122 | virtual void onRelease() SK_OVERRIDE; |
| 123 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 124 | private: |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 125 | GrStencilBuffer* fStencilBuffer; |
robertphillips@google.com | e98ade4 | 2012-06-13 12:53:07 +0000 | [diff] [blame] | 126 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 127 | SkIRect fResolveRect; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 128 | |
robertphillips@google.com | 7d501ab | 2012-06-21 21:09:06 +0000 | [diff] [blame] | 129 | typedef GrSurface INHERITED; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | #endif |