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 "GrSurfaceProxy.h" 12#include "GrTypesPriv.h" 13 14class GrResourceProvider; 15 16// This class delays the acquisition of RenderTargets until they are actually 17// required 18// Beware: the uniqueID of the RenderTargetProxy will usually be different than 19// the uniqueID of the RenderTarget it represents! 20class GrRenderTargetProxy : virtual public GrSurfaceProxy { 21public: 22 GrRenderTargetProxy* asRenderTargetProxy() override { return this; } 23 const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; } 24 25 // Actually instantiate the backing rendertarget, if necessary. 26 bool instantiate(GrResourceProvider*) override; 27 28 GrFSAAType fsaaType() const { 29 if (fSampleCnt <= 1) { 30 SkASSERT(!(fRenderTargetFlags & GrRenderTargetFlags::kMixedSampled)); 31 return GrFSAAType::kNone; 32 } 33 return (fRenderTargetFlags & GrRenderTargetFlags::kMixedSampled) 34 ? GrFSAAType::kMixedSamples 35 : GrFSAAType::kUnifiedMSAA; 36 } 37 38 /* 39 * When instantiated does this proxy require a stencil buffer? 40 */ 41 void setNeedsStencil() { fNeedsStencil = true; } 42 bool needsStencil() const { return fNeedsStencil; } 43 44 /** 45 * Returns the number of samples/pixel in the stencil buffer (One if non-MSAA). 46 */ 47 int numStencilSamples() const { return fSampleCnt; } 48 49 /** 50 * Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled). 51 */ 52 int numColorSamples() const { 53 return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt; 54 } 55 56 int maxWindowRectangles(const GrCaps& caps) const; 57 58 GrRenderTargetFlags testingOnly_getFlags() const; 59 60 // TODO: move this to a priv class! 61 bool refsWrappedObjects() const; 62 63protected: 64 friend class GrProxyProvider; // for ctors 65 66 // Deferred version 67 GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, 68 SkBackingFit, SkBudgeted, uint32_t flags); 69 70 // Lazy-callback version 71 // There are two main use cases for lazily-instantiated proxies: 72 // basic knowledge - width, height, config, samples, origin are known 73 // minimal knowledge - only config is known. 74 // 75 // The basic knowledge version is used for DDL where we know the type of proxy we are going to 76 // use, but we don't have access to the GPU yet to instantiate it. 77 // 78 // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not 79 // know the final size until flush time. 80 GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType, 81 const GrSurfaceDesc&, SkBackingFit, SkBudgeted, uint32_t flags, 82 GrRenderTargetFlags renderTargetFlags); 83 84 // Wrapped version 85 GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin); 86 87 sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; 88 89private: 90 size_t onUninstantiatedGpuMemorySize() const override; 91 SkDEBUGCODE(void validateLazySurface(const GrSurface*) override;) 92 93 int fSampleCnt; 94 bool fNeedsStencil; 95 96 // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class. 97 // For deferred proxies that pointer is filled in when we need to instantiate the 98 // deferred resource. 99 100 // These don't usually get computed until the render target is instantiated, but the render 101 // target proxy may need to answer queries about it before then. And since in the deferred case 102 // we know the newly created render target will be internal, we are able to precompute what the 103 // flags will ultimately end up being. In the wrapped case we just copy the wrapped 104 // rendertarget's info here. 105 GrRenderTargetFlags fRenderTargetFlags; 106 107 typedef GrSurfaceProxy INHERITED; 108}; 109 110#endif 111