blob: 8d7d8d02d76d8ee05a45ef50030926d76dc78f70 [file] [log] [blame]
Robert Phillips757914d2017-01-25 15:48:30 -05001/*
2 * Copyright 2017 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 GrSurfaceProxyPriv_DEFINED
9#define GrSurfaceProxyPriv_DEFINED
10
11#include "GrSurfaceProxy.h"
12
Robert Phillipsf8e25022017-11-08 15:24:31 -050013#include "GrResourceProvider.h"
14
Robert Phillips757914d2017-01-25 15:48:30 -050015/** Class that adds methods to GrSurfaceProxy that are only intended for use internal to Skia.
16 This class is purely a privileged window into GrSurfaceProxy. It should never have additional
17 data members or virtual methods. */
18class GrSurfaceProxyPriv {
19public:
Robert Phillips57aa3672017-07-21 11:38:13 -040020 bool isInstantiated() const { return SkToBool(fProxy->fTarget); }
21
Robert Phillipseee4d6e2017-06-05 09:26:07 -040022 // This should only be called after a successful call to instantiate
23 GrSurface* peekSurface() const {
24 SkASSERT(fProxy->fTarget);
25 return fProxy->fTarget;
26 }
27
Robert Phillips3798c862017-03-27 11:08:16 -040028 // If the proxy is already instantiated, return its backing GrTexture; if not,
29 // return null
Robert Phillips8a02f652017-05-12 14:49:16 -040030 GrTexture* peekTexture() const {
Robert Phillips3798c862017-03-27 11:08:16 -040031 return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr;
32 }
33
Robert Phillipseee4d6e2017-06-05 09:26:07 -040034 // This should only be called after a successful call to instantiate
Robert Phillips318c4192017-05-17 09:36:38 -040035 GrRenderTarget* peekRenderTarget() const {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040036 SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget());
Robert Phillips318c4192017-05-17 09:36:38 -040037 return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr;
38 }
39
Robert Phillips757914d2017-01-25 15:48:30 -050040 // Beware! This call is only guaranteed to tell you if the proxy in question has
41 // any pending IO in its current state. It won't tell you about the IO state in the
42 // future when the proxy is actually used/instantiated.
43 bool hasPendingIO() const { return fProxy->hasPendingIO(); }
44
Robert Phillips7ee385e2017-03-30 08:02:11 -040045 // Beware! This call is only guaranteed to tell you if the proxy in question has
46 // any pending writes in its current state. It won't tell you about the IO state in the
47 // future when the proxy is actually used/instantiated.
48 bool hasPendingWrite() const { return fProxy->hasPendingWrite(); }
49
Robert Phillips57aa3672017-07-21 11:38:13 -040050 void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); }
51
Robert Phillips5af44de2017-07-18 14:49:38 -040052 // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability)
53 // of the GrSurfaceProxy.
54 sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const {
55 return fProxy->createSurface(resourceProvider);
56 }
57
58 // Assign this proxy the provided GrSurface as its backing surface
59 void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); }
60
Robert Phillipsf8e25022017-11-08 15:24:31 -050061 bool requiresNoPendingIO() const {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040062 return fProxy->fSurfaceFlags & GrInternalSurfaceFlags::kNoPendingIO;
Robert Phillipsf8e25022017-11-08 15:24:31 -050063 }
64
Robert Phillips0ae6faa2017-03-21 16:22:00 -040065 // Don't abuse this call!!!!!!!
Robert Phillips40fd7c92017-01-30 08:06:27 -050066 bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; }
67
Robert Phillips0ae6faa2017-03-21 16:22:00 -040068 // Don't. Just don't.
69 void exactify();
70
Greg Danielbddcc952018-01-24 13:22:24 -050071 bool doLazyInstantiation(GrResourceProvider*);
Chris Dalton706a6ff2017-11-29 22:01:06 -070072
Greg Daniel457469c2018-02-08 15:05:44 -050073 GrSurfaceProxy::LazyInstantiationType lazyInstantiationType() const {
74 return fProxy->fLazyInstantiationType;
75 }
76
Greg Daniel4684f822018-03-08 15:27:36 -050077 bool isSafeToUninstantiate() const {
78 return SkToBool(fProxy->fTarget) &&
79 SkToBool(fProxy->fLazyInstantiateCallback) &&
80 GrSurfaceProxy::LazyInstantiationType::kUninstantiate == lazyInstantiationType();
81 }
82
Robert Phillipseafd48a2017-11-16 07:52:08 -050083 static bool AttachStencilIfNeeded(GrResourceProvider*, GrSurface*, bool needsStencil);
84
Robert Phillips757914d2017-01-25 15:48:30 -050085private:
86 explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {}
87 GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl
88 GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl
89
90 // No taking addresses of this type.
91 const GrSurfaceProxyPriv* operator&() const;
92 GrSurfaceProxyPriv* operator&();
93
94 GrSurfaceProxy* fProxy;
95
96 friend class GrSurfaceProxy; // to construct/copy this type.
97};
98
99inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); }
100
101inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const {
102 return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this));
103}
104
105#endif