bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | /* |
| 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. |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #ifndef GrGLRenderTarget_DEFINED |
| 10 | #define GrGLRenderTarget_DEFINED |
| 11 | |
| 12 | #include "GrGLIRect.h" |
| 13 | #include "GrRenderTarget.h" |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 14 | #include "SkScalar.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 16 | class GrGLCaps; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 17 | class GrGLGpu; |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 18 | class GrGLStencilAttachment; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 19 | |
| 20 | class GrGLRenderTarget : public GrRenderTarget { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 21 | public: |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 22 | bool alwaysClearStencil() const override { return 0 == fRTFBOID; } |
| 23 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 24 | // set fTexFBOID to this value to indicate that it is multisampled but |
| 25 | // Gr doesn't know how to resolve it. |
| 26 | enum { kUnresolvableFBOID = 0 }; |
| 27 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 28 | struct IDDesc { |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 29 | GrGLuint fRTFBOID; |
| 30 | GrBackendObjectOwnership fRTFBOOwnership; |
| 31 | GrGLuint fTexFBOID; |
| 32 | GrGLuint fMSColorRenderbufferID; |
| 33 | bool fIsMixedSampled; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 36 | static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*, |
| 37 | const GrSurfaceDesc&, |
| 38 | const IDDesc&, |
| 39 | int stencilBits); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 41 | void setViewport(const GrGLIRect& rect) { fViewport = rect; } |
| 42 | const GrGLIRect& getViewport() const { return fViewport; } |
| 43 | |
Brian Osman | 1a9e8f3 | 2017-02-24 09:31:16 -0500 | [diff] [blame] | 44 | // The following two functions return the same ID when a texture/render target is not |
| 45 | // multisampled, and different IDs when it is multisampled. |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 46 | // FBO ID used to render into |
| 47 | GrGLuint renderFBOID() const { return fRTFBOID; } |
| 48 | // FBO ID that has texture ID attached. |
| 49 | GrGLuint textureFBOID() const { return fTexFBOID; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 50 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | // override of GrRenderTarget |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 52 | ResolveType getResolveType() const override { |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 53 | if (GrFSAAType::kUnifiedMSAA != this->fsaaType() || fRTFBOID == fTexFBOID) { |
| 54 | // catches FBO 0 and non unified-MSAA case |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 55 | return kAutoResolves_ResolveType; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 56 | } else if (kUnresolvableFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 57 | return kCantResolve_ResolveType; |
| 58 | } else { |
| 59 | return kCanResolve_ResolveType; |
| 60 | } |
| 61 | } |
| 62 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 63 | GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; } |
| 64 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 65 | bool canAttemptStencilAttachment() const override; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 66 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 67 | // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer |
| 68 | // components seperately. |
| 69 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; |
| 70 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 71 | protected: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 72 | // Constructor for subclasses. |
| 73 | GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 74 | |
| 75 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 76 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | void onAbandon() override; |
| 78 | void onRelease() override; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 79 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 80 | int numSamplesOwnedPerPixel() const { return fNumSamplesOwnedPerPixel; } |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 81 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 82 | private: |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 83 | // Constructor for instances wrapping backend objects. |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 84 | GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*); |
| 85 | |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 86 | static GrRenderTargetFlags ComputeFlags(const GrGLCaps&, const IDDesc&); |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 87 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 88 | GrGLGpu* getGLGpu() const; |
| 89 | bool completeStencilAttachment() override; |
| 90 | |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 91 | size_t onGpuMemorySize() const override; |
| 92 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 93 | int msaaSamples() const; |
| 94 | // The number total number of samples, including both MSAA and resolve texture samples. |
| 95 | int totalSamples() const; |
| 96 | |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 97 | GrGLuint fRTFBOID; |
| 98 | GrGLuint fTexFBOID; |
| 99 | GrGLuint fMSColorRenderbufferID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 100 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 101 | GrBackendObjectOwnership fRTFBOOwnership; |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 102 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 103 | // when we switch to this render target we want to set the viewport to |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 104 | // only render to content area (as opposed to the whole allocation) and |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 105 | // we want the rendering to be at top left (GL has origin in bottom left) |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 106 | GrGLIRect fViewport; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 107 | |
Robert Phillips | 29e52f1 | 2016-11-03 10:19:14 -0400 | [diff] [blame] | 108 | // The RenderTarget needs to be able to report its VRAM footprint even after abandon and |
| 109 | // release have potentially zeroed out the IDs (e.g., so the cache can reset itself). Since |
| 110 | // the IDs are just required for the computation in totalSamples we cache that result here. |
| 111 | int fNumSamplesOwnedPerPixel; |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 112 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 113 | typedef GrRenderTarget INHERITED; |
| 114 | }; |
| 115 | |
| 116 | #endif |