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 15 class GrResourceProvider; 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! 21 class GrRenderTargetProxy : virtual public GrSurfaceProxy { 22 public: asRenderTargetProxy()23 GrRenderTargetProxy* asRenderTargetProxy() override { return this; } asRenderTargetProxy()24 const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; } 25 26 // Actually instantiate the backing rendertarget, if necessary. 27 GrRenderTarget* instantiate(GrResourceProvider* resourceProvider); 28 isStencilBufferMultisampled()29 bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } 30 31 /** 32 * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color 33 * buffer is not. 34 */ isMixedSampled()35 bool isMixedSampled() const { return fRenderTargetFlags & GrRenderTarget::Flags::kMixedSampled; } 36 37 /** 38 * "Unified Sampled" means the stencil and color buffers are both multisampled. 39 */ isUnifiedMultisampled()40 bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); } 41 42 /** 43 * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA). 44 */ numStencilSamples()45 int numStencilSamples() const { return fDesc.fSampleCnt; } 46 47 /** 48 * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled). 49 */ numColorSamples()50 int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; } 51 52 int maxWindowRectangles(const GrCaps& caps) const; 53 54 GrRenderTarget::Flags testingOnly_getFlags() const; 55 56 // TODO: move this to a priv class! 57 bool refsWrappedObjects() const; 58 59 protected: 60 friend class GrSurfaceProxy; // for ctors 61 62 // Deferred version 63 GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, 64 SkBackingFit, SkBudgeted, uint32_t flags); 65 66 // Wrapped version 67 GrRenderTargetProxy(sk_sp<GrSurface>); 68 69 private: 70 size_t onGpuMemorySize() const override; 71 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. 75 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 80 // rendertarget's info here. 81 GrRenderTarget::Flags fRenderTargetFlags; 82 83 typedef GrSurfaceProxy INHERITED; 84 }; 85 86 #endif 87