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 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 16 | class GrGLGpu; |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 17 | class GrGLStencilAttachment; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 18 | |
| 19 | class GrGLRenderTarget : public GrRenderTarget { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 20 | public: |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 21 | // set fTexFBOID to this value to indicate that it is multisampled but |
| 22 | // Gr doesn't know how to resolve it. |
| 23 | enum { kUnresolvableFBOID = 0 }; |
| 24 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 25 | struct IDDesc { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 26 | GrGLuint fRTFBOID; |
| 27 | GrGLuint fTexFBOID; |
| 28 | GrGLuint fMSColorRenderbufferID; |
| 29 | GrGpuResource::LifeCycle fLifeCycle; |
| 30 | GrRenderTarget::SampleConfig fSampleConfig; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 33 | static GrGLRenderTarget* CreateWrapped(GrGLGpu*, |
| 34 | const GrSurfaceDesc&, |
| 35 | const IDDesc&, |
| 36 | int stencilBits); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 37 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 38 | void setViewport(const GrGLIRect& rect) { fViewport = rect; } |
| 39 | const GrGLIRect& getViewport() const { return fViewport; } |
| 40 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 41 | // The following two functions return the same ID when a |
| 42 | // texture/render target is multisampled, and different IDs when |
| 43 | // it is. |
| 44 | // FBO ID used to render into |
| 45 | GrGLuint renderFBOID() const { return fRTFBOID; } |
| 46 | // FBO ID that has texture ID attached. |
| 47 | GrGLuint textureFBOID() const { return fTexFBOID; } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 48 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 49 | // override of GrRenderTarget |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 50 | ResolveType getResolveType() const override { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 51 | if (!this->isUnifiedMultisampled() || |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 52 | fRTFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 53 | // catches FBO 0 and non MSAA case |
| 54 | return kAutoResolves_ResolveType; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 55 | } else if (kUnresolvableFBOID == fTexFBOID) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 56 | return kCantResolve_ResolveType; |
| 57 | } else { |
| 58 | return kCanResolve_ResolveType; |
| 59 | } |
| 60 | } |
| 61 | |
joshualitt | 8179341 | 2015-07-08 12:54:04 -0700 | [diff] [blame] | 62 | GrBackendObject getRenderTargetHandle() const override { return fRTFBOID; } |
| 63 | |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 64 | /** When we don't own the FBO ID we don't attempt to modify its attachments. */ |
bsalomon | 6dc6f5f | 2015-06-18 09:12:16 -0700 | [diff] [blame] | 65 | bool canAttemptStencilAttachment() const override { |
| 66 | return kCached_LifeCycle == fRTLifecycle || kUncached_LifeCycle == fRTLifecycle; |
| 67 | } |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 68 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 69 | // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer |
| 70 | // components seperately. |
| 71 | void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; |
| 72 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 73 | protected: |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 74 | // The public constructor registers this object with the cache. However, only the most derived |
| 75 | // class should register with the cache. This constructor does not do the registration and |
| 76 | // rather moves that burden onto the derived class. |
| 77 | enum Derived { kDerived }; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 78 | GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 79 | |
| 80 | void init(const GrSurfaceDesc&, const IDDesc&); |
| 81 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 82 | void onAbandon() override; |
| 83 | void onRelease() override; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 84 | |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 85 | // In protected because subclass GrGLTextureRenderTarget calls this version. |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 86 | size_t onGpuMemorySize() const override; |
bsalomon | 69ed47f | 2014-11-12 11:13:39 -0800 | [diff] [blame] | 87 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 88 | private: |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 89 | // This ctor is used only for creating wrapped render targets and is only called for the static |
| 90 | // create function CreateWrapped(...). |
| 91 | GrGLRenderTarget(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrGLStencilAttachment*); |
| 92 | |
| 93 | GrGLGpu* getGLGpu() const; |
| 94 | bool completeStencilAttachment() override; |
| 95 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 96 | // The total size of the resource (including all pixels) for a single sample. |
| 97 | size_t totalBytesPerSample() const; |
| 98 | int msaaSamples() const; |
| 99 | // The number total number of samples, including both MSAA and resolve texture samples. |
| 100 | int totalSamples() const; |
| 101 | |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 102 | GrGLuint fRTFBOID; |
| 103 | GrGLuint fTexFBOID; |
| 104 | GrGLuint fMSColorRenderbufferID; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 105 | |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 106 | // We track this separately from GrGpuResource because this may be both a texture and a render |
| 107 | // target, and the texture may be wrapped while the render target is not. |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 108 | LifeCycle fRTLifecycle; |
hendrikw | 9a0c7ab | 2014-12-09 14:26:47 -0800 | [diff] [blame] | 109 | |
bsalomon@google.com | 2d0bade | 2012-10-26 19:01:17 +0000 | [diff] [blame] | 110 | // 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] | 111 | // 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] | 112 | // 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] | 113 | GrGLIRect fViewport; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 114 | |
senorblanco | d298121 | 2015-04-30 12:06:10 -0700 | [diff] [blame] | 115 | // onGpuMemorySize() needs to know the VRAM footprint of the FBO(s). However, abandon and |
| 116 | // release zero out the IDs and the cache needs to know the size even after those actions. |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 117 | size_t fGpuMemorySize; |
| 118 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 119 | typedef GrRenderTarget INHERITED; |
| 120 | }; |
| 121 | |
| 122 | #endif |