blob: b10cb345f74fd21373d76c8dce7271f3dc4219f5 [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 Phillipseee4d6e2017-06-05 09:26:07 -040018 // This should only be called after a successful call to instantiate
19 GrSurface* peekSurface() const {
20 SkASSERT(fProxy->fTarget);
21 return fProxy->fTarget;
22 }
23
Robert Phillips3798c862017-03-27 11:08:16 -040024 // If the proxy is already instantiated, return its backing GrTexture; if not,
25 // return null
Robert Phillips8a02f652017-05-12 14:49:16 -040026 GrTexture* peekTexture() const {
Robert Phillips3798c862017-03-27 11:08:16 -040027 return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr;
28 }
29
Robert Phillipseee4d6e2017-06-05 09:26:07 -040030 // This should only be called after a successful call to instantiate
Robert Phillips318c4192017-05-17 09:36:38 -040031 GrRenderTarget* peekRenderTarget() const {
Robert Phillipseee4d6e2017-06-05 09:26:07 -040032 SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget());
Robert Phillips318c4192017-05-17 09:36:38 -040033 return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr;
34 }
35
Robert Phillips757914d2017-01-25 15:48:30 -050036 // Beware! This call is only guaranteed to tell you if the proxy in question has
37 // any pending IO in its current state. It won't tell you about the IO state in the
38 // future when the proxy is actually used/instantiated.
39 bool hasPendingIO() const { return fProxy->hasPendingIO(); }
40
Robert Phillips7ee385e2017-03-30 08:02:11 -040041 // Beware! This call is only guaranteed to tell you if the proxy in question has
42 // any pending writes in its current state. It won't tell you about the IO state in the
43 // future when the proxy is actually used/instantiated.
44 bool hasPendingWrite() const { return fProxy->hasPendingWrite(); }
45
Robert Phillips0ae6faa2017-03-21 16:22:00 -040046 // Don't abuse this call!!!!!!!
Robert Phillips40fd7c92017-01-30 08:06:27 -050047 bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; }
48
Robert Phillips0ae6faa2017-03-21 16:22:00 -040049 // Don't. Just don't.
50 void exactify();
51
Robert Phillips757914d2017-01-25 15:48:30 -050052private:
53 explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {}
54 GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl
55 GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl
56
57 // No taking addresses of this type.
58 const GrSurfaceProxyPriv* operator&() const;
59 GrSurfaceProxyPriv* operator&();
60
61 GrSurfaceProxy* fProxy;
62
63 friend class GrSurfaceProxy; // to construct/copy this type.
64};
65
66inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); }
67
68inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const {
69 return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this));
70}
71
72#endif