diff options
author | csmartdalton <csmartdalton@google.com> | 2016-08-10 11:09:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 11:09:07 -0700 |
commit | f9635999a4aa8810d04e8ef04594a9fbcc061e3d (patch) | |
tree | 07e43ef173ca41adc6ceec7ade2f1dd2669cfbf6 /include | |
parent | 4ab47e087ecfc82f070cbbaef4d9eb562d3fd163 (diff) |
Add flag for window rectangles to GrRenderTarget
Adds a flag to GrRenderTarget that indicates whether it can be used
with window rectangles. Also attempts to clean up some of the mixed
samples API.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2225303002
Review-Url: https://codereview.chromium.org/2225303002
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrDrawContext.h | 2 | ||||
-rw-r--r-- | include/gpu/GrRenderTarget.h | 81 | ||||
-rw-r--r-- | include/gpu/GrTypes.h | 21 | ||||
-rw-r--r-- | include/private/GrInstancedPipelineInfo.h | 2 | ||||
-rw-r--r-- | include/private/GrRenderTargetProxy.h | 72 |
5 files changed, 67 insertions, 111 deletions
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index 6b582a6a63..def541d9a9 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -263,7 +263,7 @@ public: return fRenderTarget->isStencilBufferMultisampled(); } bool isUnifiedMultisampled() const { return fRenderTarget->isUnifiedMultisampled(); } - bool hasMixedSamples() const { return fRenderTarget->hasMixedSamples(); } + bool hasMixedSamples() const { return fRenderTarget->isMixedSampled(); } bool mustUseHWAA(const GrPaint& paint) const { return paint.isAntiAlias() && fRenderTarget->isUnifiedMultisampled(); diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h index 77b04d24d3..1f87787d45 100644 --- a/include/gpu/GrRenderTarget.h +++ b/include/gpu/GrRenderTarget.h @@ -30,66 +30,28 @@ public: const GrRenderTarget* asRenderTarget() const override { return this; } // GrRenderTarget - /** - * On some hardware it is possible for a render target to have multisampling - * only in certain buffers. - * Enforce only two legal sample configs. - * kUnified_SampleConfig signifies multisampling in both color and stencil - * buffers and is available across all hardware. - * kStencil_SampleConfig means multisampling is present in stencil buffer - * only; this config requires hardware support of - * NV_framebuffer_mixed_samples. - */ - enum SampleConfig { - kUnified_SampleConfig = 0, - kStencil_SampleConfig = 1 - }; - - /** - * @return true if the surface is multisampled in all buffers, - * false otherwise - */ - bool isUnifiedMultisampled() const { - if (fSampleConfig != kUnified_SampleConfig) { - return false; - } - return 0 != fDesc.fSampleCnt; - } + bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } /** - * @return true if the surface is multisampled in the stencil buffer, - * false otherwise + * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color + * buffer is not. */ - bool isStencilBufferMultisampled() const { - return 0 != fDesc.fSampleCnt; - } + bool isMixedSampled() const { return fFlags & Flags::kMixedSampled; } /** - * @return the number of color samples-per-pixel, or zero if non-MSAA or - * multisampled in the stencil buffer only. + * "Unified Sampled" means the stencil and color buffers are both multisampled. */ - int numColorSamples() const { - if (fSampleConfig == kUnified_SampleConfig) { - return fDesc.fSampleCnt; - } - return 0; - } + bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); } /** - * @return the number of stencil samples-per-pixel, or zero if non-MSAA. + * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA). */ - int numStencilSamples() const { - return fDesc.fSampleCnt; - } + int numStencilSamples() const { return fDesc.fSampleCnt; } /** - * @return true if the surface is mixed sampled, false otherwise. + * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled). */ - bool hasMixedSamples() const { - SkASSERT(kStencil_SampleConfig != fSampleConfig || - this->isStencilBufferMultisampled()); - return kStencil_SampleConfig == fSampleConfig; - } + int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; } /** * Call to indicate the multisample contents were modified such that the @@ -156,19 +118,17 @@ public: void setLastDrawTarget(GrDrawTarget* dt); GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } - static SampleConfig ComputeSampleConfig(const GrCaps& caps, int sampleCnt); - protected: - GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, - SampleConfig sampleConfig, GrStencilAttachment* stencil = nullptr) - : INHERITED(gpu, desc) - , fStencilAttachment(stencil) - , fMultisampleSpecsID(0) - , fSampleConfig(sampleConfig) - , fLastDrawTarget(nullptr) { - fResolveRect.setLargestInverted(); - } + enum class Flags { + kNone = 0, + kMixedSampled = 1 << 0, + kWindowRectsSupport = 1 << 1 + }; + + GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); + GrRenderTarget(GrGpu*, const GrSurfaceDesc&, Flags = Flags::kNone, + GrStencilAttachment* = nullptr); ~GrRenderTarget() override; // override of GrResource @@ -186,7 +146,7 @@ private: GrStencilAttachment* fStencilAttachment; uint8_t fMultisampleSpecsID; - SampleConfig fSampleConfig; + Flags fFlags; SkIRect fResolveRect; @@ -201,5 +161,6 @@ private: typedef GrSurface INHERITED; }; +GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTarget::Flags); #endif diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index a0f13aa6fe..7bc949d73c 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -49,6 +49,27 @@ \ template <typename T> \ friend X operator & (X a, T b); \ + +/** + * Defines bitwise operators that make it possible to use an enum class as a + * very basic bitfield. + */ +#define GR_MAKE_BITFIELD_CLASS_OPS(X) \ + inline X operator | (X a, X b) { \ + return (X) ((int)a | (int)b); \ + } \ + inline X& operator |= (X& a, X b) { \ + return (a = a | b); \ + } \ + inline bool operator & (X a, X b) { \ + return SkToBool((int)a & (int)b); \ + } + +#define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X) \ + friend X operator | (X a, X b); \ + friend X& operator |= (X& a, X b); \ + friend bool operator & (X a, X b); + //////////////////////////////////////////////////////////////////////////////// // compile time versions of min/max diff --git a/include/private/GrInstancedPipelineInfo.h b/include/private/GrInstancedPipelineInfo.h index f12b89fc6b..7e6482da90 100644 --- a/include/private/GrInstancedPipelineInfo.h +++ b/include/private/GrInstancedPipelineInfo.h @@ -17,7 +17,7 @@ struct GrInstancedPipelineInfo { GrInstancedPipelineInfo(const GrRenderTarget* rt) : fIsMultisampled(rt->isStencilBufferMultisampled()), - fIsMixedSampled(rt->hasMixedSamples()), + fIsMixedSampled(rt->isMixedSampled()), fIsRenderingToFloat(GrPixelConfigIsFloatingPoint(rt->desc().fConfig)), fColorDisabled(false), fDrawingShapeToStencil(false), diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h index 287aa017f0..e4bc70f212 100644 --- a/include/private/GrRenderTargetProxy.h +++ b/include/private/GrRenderTargetProxy.h @@ -9,6 +9,7 @@ #define GrRenderTargetProxy_DEFINED #include "GrRenderTarget.h" +#include "GrRenderTargetPriv.h" #include "GrSurfaceProxy.h" #include "GrTypes.h" @@ -25,7 +26,7 @@ public: */ static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, const GrSurfaceDesc&, SkBackingFit, SkBudgeted); - static sk_sp<GrRenderTargetProxy> Make(sk_sp<GrRenderTarget> rt); + static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, sk_sp<GrRenderTarget>); ~GrRenderTargetProxy() override; @@ -36,78 +37,51 @@ public: // Actually instantiate the backing rendertarget, if necessary. GrRenderTarget* instantiate(GrTextureProvider* texProvider); - /** - * @return true if the surface is multisampled in all buffers, - * false otherwise - */ - bool isUnifiedMultisampled() const { - if (fSampleConfig != GrRenderTarget::kUnified_SampleConfig) { - return false; - } - return 0 != fDesc.fSampleCnt; - } + bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } /** - * @return true if the surface is multisampled in the stencil buffer, - * false otherwise + * For our purposes, "Mixed Sampled" means the stencil buffer is multisampled but the color + * buffer is not. */ - bool isStencilBufferMultisampled() const { - return 0 != fDesc.fSampleCnt; - } + bool isMixedSampled() const { return fFlags & GrRenderTargetPriv::Flags::kMixedSampled; } /** - * @return the number of color samples-per-pixel, or zero if non-MSAA or - * multisampled in the stencil buffer only. + * "Unified Sampled" means the stencil and color buffers are both multisampled. */ - int numColorSamples() const { - if (fSampleConfig == GrRenderTarget::kUnified_SampleConfig) { - return fDesc.fSampleCnt; - } - return 0; - } + bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->isMixedSampled(); } /** - * @return the number of stencil samples-per-pixel, or zero if non-MSAA. + * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA). */ - int numStencilSamples() const { - return fDesc.fSampleCnt; - } + int numStencilSamples() const { return fDesc.fSampleCnt; } /** - * @return true if the surface is mixed sampled, false otherwise. + * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled). */ - bool hasMixedSamples() const { - SkASSERT(GrRenderTarget::kStencil_SampleConfig != fSampleConfig || - this->isStencilBufferMultisampled()); - return GrRenderTarget::kStencil_SampleConfig == fSampleConfig; - } + int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; } void setLastDrawTarget(GrDrawTarget* dt); GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } + GrRenderTargetPriv::Flags testingOnly_getFlags() const; + private: - // TODO: we can probably munge the 'desc' in both the wrapped and deferred - // cases to make the sampleConfig/numSamples stuff more rational. - GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, - SkBackingFit fit, SkBudgeted budgeted) - : INHERITED(desc, fit, budgeted) - , fTarget(nullptr) - , fSampleConfig(GrRenderTarget::ComputeSampleConfig(caps, desc.fSampleCnt)) - , fLastDrawTarget(nullptr) { - } + // Deferred version + GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, SkBackingFit, SkBudgeted); // Wrapped version - GrRenderTargetProxy(sk_sp<GrRenderTarget> rt); + GrRenderTargetProxy(const GrCaps&, sk_sp<GrRenderTarget> rt); // For wrapped render targets we store it here. // For deferred proxies we will fill this in when we need to instantiate the deferred resource - sk_sp<GrRenderTarget> fTarget; + sk_sp<GrRenderTarget> fTarget; - // The sample config doesn't usually get computed until the render target is instantiated but - // the render target proxy may need to answer queries about it before then. For this reason - // we precompute it in the deferred case. In the wrapped case we just copy the wrapped + // These don't usually get computed until the render target is instantiated, but the render + // target proxy may need to answer queries about it before then. And since in the deferred case + // we know the newly created render target will be internal, we are able to precompute what the + // flags will ultimately end up being. In the wrapped case we just copy the wrapped // rendertarget's info here. - GrRenderTarget::SampleConfig fSampleConfig; + GrRenderTargetPriv::Flags fFlags; // The last drawTarget that wrote to or is currently going to write to this renderTarget // The drawTarget can be closed (e.g., no draw context is currently bound |