blob: ef8fe19f6af571aacb016cb549745225b0bf0933 [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 Phillips715d08c2018-07-18 13:56:48 -040020 // Beware! Woe betide anyone whosoever calls this method.
21 // The refs on proxies and their backing GrSurfaces shift around based on whether the proxy
22 // is instantiated or not. Additionally, the lifetime of a proxy (and a GrSurface) also
23 // depends on the read and write refs (So this method can validly return 0).
24 int32_t getProxyRefCnt() const { return fProxy->getProxyRefCnt(); }
25
Robert Phillips57aa3672017-07-21 11:38:13 -040026 void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); }
27
Robert Phillips5af44de2017-07-18 14:49:38 -040028 // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability)
29 // of the GrSurfaceProxy.
30 sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const {
31 return fProxy->createSurface(resourceProvider);
32 }
33
34 // Assign this proxy the provided GrSurface as its backing surface
35 void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); }
36
Robert Phillipsf8e25022017-11-08 15:24:31 -050037 bool requiresNoPendingIO() const {
Robert Phillipsfe0253f2018-03-16 16:47:25 -040038 return fProxy->fSurfaceFlags & GrInternalSurfaceFlags::kNoPendingIO;
Robert Phillipsf8e25022017-11-08 15:24:31 -050039 }
40
Robert Phillips0ae6faa2017-03-21 16:22:00 -040041 // Don't abuse this call!!!!!!!
Robert Phillips40fd7c92017-01-30 08:06:27 -050042 bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; }
43
Robert Phillips0ae6faa2017-03-21 16:22:00 -040044 // Don't. Just don't.
45 void exactify();
46
Greg Danielbddcc952018-01-24 13:22:24 -050047 bool doLazyInstantiation(GrResourceProvider*);
Chris Dalton706a6ff2017-11-29 22:01:06 -070048
Greg Daniel457469c2018-02-08 15:05:44 -050049 GrSurfaceProxy::LazyInstantiationType lazyInstantiationType() const {
50 return fProxy->fLazyInstantiationType;
51 }
52
Brian Salomon876a0172019-03-08 11:12:14 -050053 bool isSafeToDeinstantiate() const {
54 return SkToBool(fProxy->fTarget) && SkToBool(fProxy->fLazyInstantiateCallback) &&
55 GrSurfaceProxy::LazyInstantiationType::kDeinstantiate == lazyInstantiationType();
56 }
57
Robert Phillips01a91282018-07-26 08:03:04 -040058 static bool SK_WARN_UNUSED_RESULT AttachStencilIfNeeded(GrResourceProvider*, GrSurface*,
59 bool needsStencil);
Robert Phillipseafd48a2017-11-16 07:52:08 -050060
Robert Phillips757914d2017-01-25 15:48:30 -050061private:
62 explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {}
63 GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl
64 GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl
65
66 // No taking addresses of this type.
67 const GrSurfaceProxyPriv* operator&() const;
68 GrSurfaceProxyPriv* operator&();
69
70 GrSurfaceProxy* fProxy;
71
72 friend class GrSurfaceProxy; // to construct/copy this type.
73};
74
75inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); }
76
77inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const {
78 return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this));
79}
80
81#endif