robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #ifndef GrRenderTargetProxy_DEFINED |
| 9 | #define GrRenderTargetProxy_DEFINED |
| 10 | |
| 11 | #include "GrRenderTarget.h" |
| 12 | #include "GrSurfaceProxy.h" |
| 13 | #include "GrTypes.h" |
| 14 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 15 | class GrResourceProvider; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 16 | |
| 17 | // This class delays the acquisition of RenderTargets until they are actually |
| 18 | // required |
| 19 | // Beware: the uniqueID of the RenderTargetProxy will usually be different than |
| 20 | // the uniqueID of the RenderTarget it represents! |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 21 | class GrRenderTargetProxy : virtual public GrSurfaceProxy { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 22 | public: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | GrRenderTargetProxy* asRenderTargetProxy() override { return this; } |
| 24 | const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; } |
| 25 | |
| 26 | // Actually instantiate the backing rendertarget, if necessary. |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame^] | 27 | GrRenderTarget* instantiate(GrResourceProvider* resourceProvider); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 28 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 29 | bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 32 | * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color |
| 33 | * buffer is not. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 34 | */ |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 35 | bool isMixedSampled() const { return fRenderTargetFlags & GrRenderTarget::Flags::kMixedSampled; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 38 | * "Unified Sampled" means the stencil and color buffers are both multisampled. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 39 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 40 | bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 43 | * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA). |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 44 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 45 | int numStencilSamples() const { return fDesc.fSampleCnt; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 48 | * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled). |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 49 | */ |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 50 | int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 51 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 52 | int maxWindowRectangles(const GrCaps& caps) const; |
| 53 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 54 | GrRenderTarget::Flags testingOnly_getFlags() const; |
| 55 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 56 | // TODO: move this to a priv class! |
| 57 | bool refsWrappedObjects() const; |
| 58 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 59 | protected: |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 60 | friend class GrSurfaceProxy; // for ctors |
| 61 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 62 | // Deferred version |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 63 | GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, |
| 64 | SkBackingFit, SkBudgeted, uint32_t flags); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 65 | |
| 66 | // Wrapped version |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 67 | GrRenderTargetProxy(sk_sp<GrSurface>); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 68 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 69 | private: |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 70 | size_t onGpuMemorySize() const override; |
| 71 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 72 | // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class. |
| 73 | // For deferred proxies that pointer is filled in when we need to instantiate the |
| 74 | // deferred resource. |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 75 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 76 | // These don't usually get computed until the render target is instantiated, but the render |
| 77 | // target proxy may need to answer queries about it before then. And since in the deferred case |
| 78 | // we know the newly created render target will be internal, we are able to precompute what the |
| 79 | // flags will ultimately end up being. In the wrapped case we just copy the wrapped |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 80 | // rendertarget's info here. |
Brian Salomon | dac5f6b | 2017-02-28 16:11:04 -0500 | [diff] [blame] | 81 | GrRenderTarget::Flags fRenderTargetFlags; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 82 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 83 | typedef GrSurfaceProxy INHERITED; |
| 84 | }; |
| 85 | |
| 86 | #endif |