1 /*
2  * Copyright 2016 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 GrSurfaceContextPriv_DEFINED
9 #define GrSurfaceContextPriv_DEFINED
10 
11 #include "GrSurfaceContext.h"
12 
13 /** Class that adds methods to GrSurfaceContext that are only intended for use internal to
14     Skia. This class is purely a privileged window into GrSurfaceContext. It should never have
15     additional data members or virtual methods. */
16 class GrSurfaceContextPriv {
17 public:
18     GrContext* getContext() { return fSurfaceContext->fContext; }
19 
20 private:
21     explicit GrSurfaceContextPriv(GrSurfaceContext* surfaceContext)
22         : fSurfaceContext(surfaceContext) {
23     }
24 
25     GrSurfaceContextPriv(const GrSurfaceContextPriv&) {} // unimpl
26     GrSurfaceContextPriv& operator=(const GrSurfaceContextPriv&); // unimpl
27 
28     // No taking addresses of this type.
29     const GrSurfaceContextPriv* operator&() const;
30     GrSurfaceContextPriv* operator&();
31 
32     GrSurfaceContext* fSurfaceContext;
33 
34     friend class GrSurfaceContext; // to construct/copy this type.
35 };
36 
37 inline GrSurfaceContextPriv GrSurfaceContext::surfPriv() {
38     return GrSurfaceContextPriv(this);
39 }
40 
41 inline const GrSurfaceContextPriv GrSurfaceContext::surfPriv() const {
42     return GrSurfaceContextPriv(const_cast<GrSurfaceContext*>(this));
43 }
44 
45 #endif
46