blob: eaae49ecaf5a13969e6d98d2d9eaabe0dbe7b0cf [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001/*
reed@google.comdd335ae2012-12-13 19:24:05 +00002 * 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.comaa5b6732011-07-29 15:13:20 +00006 */
7
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00008#ifndef GrRenderTarget_DEFINED
9#define GrRenderTarget_DEFINED
10
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000011#include "GrSurface.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000012#include "SkRect.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000013
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000014class GrStencilBuffer;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015
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
bsalomon37dd3312014-11-03 08:47:23 -080019 * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000020 * Additionally, GrContext provides methods for creating GrRenderTargets
21 * that wrap externally created render targets.
22 */
bsalomon37dd3312014-11-03 08:47:23 -080023class GrRenderTarget : virtual public GrSurface {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000024public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000025 SK_DECLARE_INST_COUNT(GrRenderTarget)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000026
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000027 // GrSurface overrides
mtklein72c9faa2015-01-09 10:06:39 -080028 GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; }
29 const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return this; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000030
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000031 // GrRenderTarget
32 /**
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000033 * 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.com16e3dde2012-10-25 18:43:28 +000036 virtual GrBackendObject getRenderTargetHandle() const = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000037
38 /**
39 * If this RT is multisampled, this is the buffer it is resolved to.
40 * Otherwise, same as getRenderTargetHandle().
bsalomon@google.com2d0bade2012-10-26 19:01:17 +000041 * (In GL a separate FBO ID is used for the MSAA and resolved buffers)
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000042 * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
43 */
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000044 virtual GrBackendObject getRenderTargetResolvedHandle() const = 0;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000045
46 /**
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000047 * @return true if the surface is multisampled, false otherwise
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000048 */
robertphillips@google.come98ade42012-06-13 12:53:07 +000049 bool isMultisampled() const { return 0 != fDesc.fSampleCnt; }
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000050
51 /**
52 * @return the number of samples-per-pixel or zero if non-MSAA.
53 */
robertphillips@google.come98ade42012-06-13 12:53:07 +000054 int numSamples() const { return fDesc.fSampleCnt; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000055
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.com16e3dde2012-10-25 18:43:28 +000060 * when the render target has been modified outside of Gr. This has no
61 * effect on wrapped backend render targets.
62 *
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000063 * @param rect a rect bounding the area needing resolve. NULL indicates
64 * the whole RT needs resolving.
65 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000066 void flagAsNeedingResolve(const SkIRect* rect = NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000067
68 /**
69 * Call to override the region that needs to be resolved.
70 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000071 void overrideResolveRect(const SkIRect rect);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000072
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.orgfd03d4a2013-07-17 21:39:42 +000087 const SkIRect& getResolveRect() const { return fResolveRect; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000088
bsalomon@google.com75f9f252012-01-31 13:35:56 +000089 /**
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000090 * Provide a performance hint that the render target's contents are allowed
91 * to become undefined.
92 */
93 void discard();
94
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000095 // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
rmistry@google.comfbfcd562012-08-23 18:09:54 +000096 // 0 in GL), or be unresolvable because the client didn't give us the
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000097 // resolve destination.
98 enum ResolveType {
99 kCanResolve_ResolveType,
100 kAutoResolves_ResolveType,
101 kCantResolve_ResolveType,
102 };
103 virtual ResolveType getResolveType() const = 0;
104
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000105 /**
106 * GrStencilBuffer is not part of the public API.
107 */
108 GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; }
109 void setStencilBuffer(GrStencilBuffer* stencilBuffer);
110
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000111protected:
bsalomon5236cf42015-01-14 10:42:08 -0800112 GrRenderTarget(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
113 : INHERITED(gpu, lifeCycle, desc)
bsalomon37dd3312014-11-03 08:47:23 -0800114 , fStencilBuffer(NULL) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000115 fResolveRect.setLargestInverted();
116 }
117
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000118 // override of GrResource
mtklein72c9faa2015-01-09 10:06:39 -0800119 void onAbandon() SK_OVERRIDE;
120 void onRelease() SK_OVERRIDE;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000121
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000122private:
bsalomon@google.com558a75b2011-08-08 17:01:14 +0000123 GrStencilBuffer* fStencilBuffer;
robertphillips@google.come98ade42012-06-13 12:53:07 +0000124
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000125 SkIRect fResolveRect;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000126
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000127 typedef GrSurface INHERITED;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000128};
129
130#endif