blob: f88c5cdfd976d18ef439562010550a7670233df7 [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
13/** Class that adds methods to GrSurfaceProxy that are only intended for use internal to Skia.
14 This class is purely a privileged window into GrSurfaceProxy. It should never have additional
15 data members or virtual methods. */
16class GrSurfaceProxyPriv {
17public:
Robert Phillips57aa3672017-07-21 11:38:13 -040018 bool isInstantiated() const { return SkToBool(fProxy->fTarget); }
19
Robert Phillipseee4d6e2017-06-05 09:26:07 -040020 // This should only be called after a successful call to instantiate
21 GrSurface* peekSurface() const {
22 SkASSERT(fProxy->fTarget);
23 return fProxy->fTarget;
24 }
25
Robert Phillips3798c862017-03-27 11:08:16 -040026 // If the proxy is already instantiated, return its backing GrTexture; if not,
27 // return null
Robert Phillips8a02f652017-05-12 14:49:16 -040028 GrTexture* peekTexture() const {
Robert Phillips3798c862017-03-27 11:08:16 -040029 return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr;
30 }
31
Robert Phillipseee4d6e2017-06-05 09:26:07 -040032 // This should only be called after a successful call to instantiate
Robert Phillips318c4192017-05-17 09:36:38 -040033 GrRenderTarget* peekRenderTarget() const {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040034 SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget());
Robert Phillips318c4192017-05-17 09:36:38 -040035 return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr;
36 }
37
Robert Phillips757914d2017-01-25 15:48:30 -050038 // Beware! This call is only guaranteed to tell you if the proxy in question has
39 // any pending IO in its current state. It won't tell you about the IO state in the
40 // future when the proxy is actually used/instantiated.
41 bool hasPendingIO() const { return fProxy->hasPendingIO(); }
42
Robert Phillips7ee385e2017-03-30 08:02:11 -040043 // Beware! This call is only guaranteed to tell you if the proxy in question has
44 // any pending writes in its current state. It won't tell you about the IO state in the
45 // future when the proxy is actually used/instantiated.
46 bool hasPendingWrite() const { return fProxy->hasPendingWrite(); }
47
Robert Phillips57aa3672017-07-21 11:38:13 -040048 void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); }
49
Robert Phillips5af44de2017-07-18 14:49:38 -040050 // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability)
51 // of the GrSurfaceProxy.
52 sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const {
53 return fProxy->createSurface(resourceProvider);
54 }
55
56 // Assign this proxy the provided GrSurface as its backing surface
57 void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); }
58
Robert Phillips0ae6faa2017-03-21 16:22:00 -040059 // Don't abuse this call!!!!!!!
Robert Phillips40fd7c92017-01-30 08:06:27 -050060 bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; }
61
Robert Phillips0ae6faa2017-03-21 16:22:00 -040062 // Don't. Just don't.
63 void exactify();
64
Robert Phillips757914d2017-01-25 15:48:30 -050065private:
66 explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {}
67 GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl
68 GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl
69
70 // No taking addresses of this type.
71 const GrSurfaceProxyPriv* operator&() const;
72 GrSurfaceProxyPriv* operator&();
73
74 GrSurfaceProxy* fProxy;
75
76 friend class GrSurfaceProxy; // to construct/copy this type.
77};
78
79inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); }
80
81inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const {
82 return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this));
83}
84
85#endif