2016-05-04 19:47:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrRenderTargetProxy_DEFINED
|
|
|
|
#define GrRenderTargetProxy_DEFINED
|
|
|
|
|
|
|
|
#include "GrSurfaceProxy.h"
|
2017-06-13 12:11:36 +00:00
|
|
|
#include "GrTypesPriv.h"
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2017-03-04 13:12:46 +00:00
|
|
|
class GrResourceProvider;
|
2018-04-26 20:31:38 +00:00
|
|
|
class GrRenderTargetProxyPriv;
|
2016-05-04 19:47:41 +00:00
|
|
|
|
|
|
|
// This class delays the acquisition of RenderTargets until they are actually
|
|
|
|
// required
|
|
|
|
// Beware: the uniqueID of the RenderTargetProxy will usually be different than
|
|
|
|
// the uniqueID of the RenderTarget it represents!
|
2016-11-04 15:59:10 +00:00
|
|
|
class GrRenderTargetProxy : virtual public GrSurfaceProxy {
|
2016-05-04 19:47:41 +00:00
|
|
|
public:
|
|
|
|
GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
|
|
|
|
const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
|
|
|
|
|
|
|
|
// Actually instantiate the backing rendertarget, if necessary.
|
2017-07-18 18:49:38 +00:00
|
|
|
bool instantiate(GrResourceProvider*) override;
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2017-05-12 15:36:10 +00:00
|
|
|
GrFSAAType fsaaType() const {
|
2018-02-03 01:32:49 +00:00
|
|
|
if (fSampleCnt <= 1) {
|
2018-03-16 20:47:25 +00:00
|
|
|
SkASSERT(!this->hasMixedSamples());
|
2017-05-12 15:36:10 +00:00
|
|
|
return GrFSAAType::kNone;
|
|
|
|
}
|
2018-03-16 20:47:25 +00:00
|
|
|
return this->hasMixedSamples() ? GrFSAAType::kMixedSamples : GrFSAAType::kUnifiedMSAA;
|
2017-05-12 15:36:10 +00:00
|
|
|
}
|
2017-05-17 17:49:59 +00:00
|
|
|
|
2017-08-10 12:44:49 +00:00
|
|
|
/*
|
|
|
|
* When instantiated does this proxy require a stencil buffer?
|
|
|
|
*/
|
|
|
|
void setNeedsStencil() { fNeedsStencil = true; }
|
|
|
|
bool needsStencil() const { return fNeedsStencil; }
|
|
|
|
|
2017-05-17 17:49:59 +00:00
|
|
|
/**
|
2018-02-03 01:32:49 +00:00
|
|
|
* Returns the number of samples/pixel in the stencil buffer (One if non-MSAA).
|
2017-05-17 17:49:59 +00:00
|
|
|
*/
|
|
|
|
int numStencilSamples() const { return fSampleCnt; }
|
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
/**
|
2018-02-03 01:32:49 +00:00
|
|
|
* Returns the number of samples/pixel in the color buffer (One if non-MSAA or mixed sampled).
|
2016-05-04 19:47:41 +00:00
|
|
|
*/
|
2017-05-12 15:36:10 +00:00
|
|
|
int numColorSamples() const {
|
2018-02-03 01:32:49 +00:00
|
|
|
return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt;
|
2017-05-12 15:36:10 +00:00
|
|
|
}
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2016-11-09 13:54:35 +00:00
|
|
|
int maxWindowRectangles(const GrCaps& caps) const;
|
|
|
|
|
2016-12-15 14:23:05 +00:00
|
|
|
// TODO: move this to a priv class!
|
|
|
|
bool refsWrappedObjects() const;
|
|
|
|
|
2018-04-26 20:31:38 +00:00
|
|
|
// Provides access to special purpose functions.
|
|
|
|
GrRenderTargetProxyPriv rtPriv();
|
|
|
|
const GrRenderTargetProxyPriv rtPriv() const;
|
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
protected:
|
2018-01-16 13:06:32 +00:00
|
|
|
friend class GrProxyProvider; // for ctors
|
2018-04-26 20:31:38 +00:00
|
|
|
friend class GrRenderTargetProxyPriv;
|
2016-11-09 11:50:43 +00:00
|
|
|
|
2016-08-10 18:09:07 +00:00
|
|
|
// Deferred version
|
2018-03-04 03:43:43 +00:00
|
|
|
GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, GrSurfaceOrigin, SkBackingFit,
|
2018-03-16 20:47:25 +00:00
|
|
|
SkBudgeted, GrInternalSurfaceFlags);
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2017-11-30 05:01:06 +00:00
|
|
|
// Lazy-callback version
|
2018-01-10 22:06:31 +00:00
|
|
|
// There are two main use cases for lazily-instantiated proxies:
|
|
|
|
// basic knowledge - width, height, config, samples, origin are known
|
|
|
|
// minimal knowledge - only config is known.
|
|
|
|
//
|
|
|
|
// The basic knowledge version is used for DDL where we know the type of proxy we are going to
|
|
|
|
// use, but we don't have access to the GPU yet to instantiate it.
|
|
|
|
//
|
|
|
|
// The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
|
|
|
|
// know the final size until flush time.
|
2018-02-08 20:05:44 +00:00
|
|
|
GrRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType lazyType,
|
2018-03-04 03:43:43 +00:00
|
|
|
const GrSurfaceDesc&, GrSurfaceOrigin, SkBackingFit, SkBudgeted,
|
2018-03-16 20:47:25 +00:00
|
|
|
GrInternalSurfaceFlags);
|
2017-11-30 05:01:06 +00:00
|
|
|
|
2016-05-04 19:47:41 +00:00
|
|
|
// Wrapped version
|
2017-07-25 14:16:35 +00:00
|
|
|
GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
|
2016-05-04 19:47:41 +00:00
|
|
|
|
2017-07-18 18:49:38 +00:00
|
|
|
sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
|
|
|
|
|
2016-11-04 15:59:10 +00:00
|
|
|
private:
|
2018-04-26 20:31:38 +00:00
|
|
|
void setHasMixedSamples() {
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled;
|
|
|
|
}
|
|
|
|
bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; }
|
|
|
|
|
|
|
|
void setSupportsWindowRects() {
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kWindowRectsSupport;
|
|
|
|
}
|
|
|
|
bool supportsWindowRects() const {
|
|
|
|
return fSurfaceFlags & GrInternalSurfaceFlags::kWindowRectsSupport;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setGLRTFBOIDIs0() {
|
|
|
|
fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
|
|
|
|
}
|
|
|
|
bool glRTFBOIDIs0() const {
|
|
|
|
return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-17 17:49:59 +00:00
|
|
|
size_t onUninstantiatedGpuMemorySize() const override;
|
2018-04-24 18:32:53 +00:00
|
|
|
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
|
2016-11-01 21:28:40 +00:00
|
|
|
|
2018-09-10 20:26:51 +00:00
|
|
|
// WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
|
|
|
|
// when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes
|
|
|
|
// each class in the diamond require 16 byte alignment. Clang appears to layout the fields for
|
|
|
|
// each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this'
|
|
|
|
// in the constructors, and always looks for the full 16 byte alignment, even if the fields in
|
|
|
|
// that particular class don't require it. Changing the size of this object can move the start
|
|
|
|
// address of other types, leading to this problem.
|
|
|
|
|
2017-06-13 12:11:36 +00:00
|
|
|
int fSampleCnt;
|
2017-08-10 12:44:49 +00:00
|
|
|
bool fNeedsStencil;
|
|
|
|
|
2016-10-28 17:25:24 +00:00
|
|
|
// For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
|
|
|
|
// For deferred proxies that pointer is filled in when we need to instantiate the
|
|
|
|
// deferred resource.
|
2016-05-04 19:47:41 +00:00
|
|
|
|
|
|
|
typedef GrSurfaceProxy INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|