blob: 40e006aa8aec8edb70b28cec5a3274f5b7f0e110 [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;
bsalomon6bc1b5f2015-02-23 09:06:38 -080015class GrRenderTargetPriv;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000016
17/**
18 * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
19 * A context's render target is set by setRenderTarget(). Render targets are
bsalomon37dd3312014-11-03 08:47:23 -080020 * created by a createTexture with the kRenderTarget_SurfaceFlag flag.
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000021 * Additionally, GrContext provides methods for creating GrRenderTargets
22 * that wrap externally created render targets.
23 */
bsalomon37dd3312014-11-03 08:47:23 -080024class GrRenderTarget : virtual public GrSurface {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000025public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000026 SK_DECLARE_INST_COUNT(GrRenderTarget)
bsalomon@google.com558a75b2011-08-08 17:01:14 +000027
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000028 // GrSurface overrides
mtklein72c9faa2015-01-09 10:06:39 -080029 GrRenderTarget* asRenderTarget() SK_OVERRIDE { return this; }
30 const GrRenderTarget* asRenderTarget() const SK_OVERRIDE { return this; }
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000031
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000032 // GrRenderTarget
33 /**
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000034 * @return true if the surface is multisampled, false otherwise
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000035 */
robertphillips@google.come98ade42012-06-13 12:53:07 +000036 bool isMultisampled() const { return 0 != fDesc.fSampleCnt; }
bsalomon@google.com5bfc2172011-07-29 20:29:05 +000037
38 /**
39 * @return the number of samples-per-pixel or zero if non-MSAA.
40 */
robertphillips@google.come98ade42012-06-13 12:53:07 +000041 int numSamples() const { return fDesc.fSampleCnt; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000042
43 /**
44 * Call to indicate the multisample contents were modified such that the
45 * render target needs to be resolved before it can be used as texture. Gr
46 * tracks this for its own drawing and thus this only needs to be called
bsalomon@google.com16e3dde2012-10-25 18:43:28 +000047 * when the render target has been modified outside of Gr. This has no
48 * effect on wrapped backend render targets.
49 *
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000050 * @param rect a rect bounding the area needing resolve. NULL indicates
51 * the whole RT needs resolving.
52 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000053 void flagAsNeedingResolve(const SkIRect* rect = NULL);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000054
55 /**
56 * Call to override the region that needs to be resolved.
57 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000058 void overrideResolveRect(const SkIRect rect);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000059
60 /**
61 * Call to indicate that GrRenderTarget was externally resolved. This may
62 * allow Gr to skip a redundant resolve step.
63 */
64 void flagAsResolved() { fResolveRect.setLargestInverted(); }
65
66 /**
67 * @return true if the GrRenderTarget requires MSAA resolving
68 */
69 bool needsResolve() const { return !fResolveRect.isEmpty(); }
70
71 /**
72 * Returns a rect bounding the region needing resolving.
73 */
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000074 const SkIRect& getResolveRect() const { return fResolveRect; }
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000075
bsalomon@google.com75f9f252012-01-31 13:35:56 +000076 /**
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000077 * Provide a performance hint that the render target's contents are allowed
78 * to become undefined.
79 */
80 void discard();
81
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000082 // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
rmistry@google.comfbfcd562012-08-23 18:09:54 +000083 // 0 in GL), or be unresolvable because the client didn't give us the
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000084 // resolve destination.
85 enum ResolveType {
86 kCanResolve_ResolveType,
87 kAutoResolves_ResolveType,
88 kCantResolve_ResolveType,
89 };
90 virtual ResolveType getResolveType() const = 0;
91
bsalomon6bc1b5f2015-02-23 09:06:38 -080092 // Provides access to functions that aren't part of the public API.
93 GrRenderTargetPriv renderTargetPriv();
94 const GrRenderTargetPriv renderTargetPriv() const;
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000095
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000096protected:
bsalomon5236cf42015-01-14 10:42:08 -080097 GrRenderTarget(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
98 : INHERITED(gpu, lifeCycle, desc)
bsalomon37dd3312014-11-03 08:47:23 -080099 , fStencilBuffer(NULL) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000100 fResolveRect.setLargestInverted();
101 }
102
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000103 // override of GrResource
mtklein72c9faa2015-01-09 10:06:39 -0800104 void onAbandon() SK_OVERRIDE;
105 void onRelease() SK_OVERRIDE;
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +0000106
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000107private:
bsalomon6bc1b5f2015-02-23 09:06:38 -0800108 // Checked when this object is asked to attach a stencil buffer.
109 virtual bool canAttemptStencilAttachment() const = 0;
110
111 friend class GrRenderTargetPriv;
112
bsalomon@google.com558a75b2011-08-08 17:01:14 +0000113 GrStencilBuffer* fStencilBuffer;
robertphillips@google.come98ade42012-06-13 12:53:07 +0000114
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000115 SkIRect fResolveRect;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000116
robertphillips@google.com7d501ab2012-06-21 21:09:06 +0000117 typedef GrSurface INHERITED;
bsalomon@google.comaa5b6732011-07-29 15:13:20 +0000118};
119
120#endif