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 GrContextPriv_DEFINED
9 #define GrContextPriv_DEFINED
10 
11 #include "GrContext.h"
12 #include "GrSurfaceContext.h"
13 
14 class GrSemaphore;
15 class GrSurfaceProxy;
16 class GrPreFlushCallbackObject;
17 
18 /** Class that adds methods to GrContext that are only intended for use internal to Skia.
19     This class is purely a privileged window into GrContext. It should never have additional
20     data members or virtual methods. */
21 class GrContextPriv {
22 public:
drawingManager()23     GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
24 
25     // Create a renderTargetContext that wraps an existing renderTarget
26     sk_sp<GrRenderTargetContext> makeWrappedRenderTargetContext(sk_sp<GrRenderTarget> rt,
27                                                                 sk_sp<SkColorSpace> colorSpace,
28                                                                 const SkSurfaceProps* = nullptr);
29 
30     // Create a surfaceContext that wraps an existing texture or renderTarget
31     sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex);
32 
33     sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy,
34                                                       sk_sp<SkColorSpace>);
35 
36     sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc,
37                                                        SkBackingFit dstFit,
38                                                        SkBudgeted isDstBudgeted);
39 
40     // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove
41     // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext
42     sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
43                                                       sk_sp<SkColorSpace> colorSpace);
44 
45     sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
46                                                          const GrBackendTextureDesc& desc,
47                                                          sk_sp<SkColorSpace> colorSpace,
48                                                          const SkSurfaceProps* = nullptr);
49 
50     sk_sp<GrRenderTargetContext> makeBackendRenderTargetRenderTargetContext(
51                                                               const GrBackendRenderTargetDesc& desc,
52                                                               sk_sp<SkColorSpace> colorSpace,
53                                                               const SkSurfaceProps* = nullptr);
54 
55     sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext(
56                                                                  const GrBackendTextureDesc& desc,
57                                                                  sk_sp<SkColorSpace> colorSpace,
58                                                                  const SkSurfaceProps* = nullptr);
59 
disableGpuYUVConversion()60     bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
61 
62     /*
63      * A ref will be taken on the preFlushCallbackObject which will be removed when the
64      * context is destroyed.
65      */
66     void addPreFlushCallbackObject(sk_sp<GrPreFlushCallbackObject>);
67 
68 private:
GrContextPriv(GrContext * context)69     explicit GrContextPriv(GrContext* context) : fContext(context) {}
70     GrContextPriv(const GrContextPriv&); // unimpl
71     GrContextPriv& operator=(const GrContextPriv&); // unimpl
72 
73     // No taking addresses of this type.
74     const GrContextPriv* operator&() const;
75     GrContextPriv* operator&();
76 
77     GrContext* fContext;
78 
79     friend class GrContext; // to construct/copy this type.
80 };
81 
contextPriv()82 inline GrContextPriv GrContext::contextPriv() { return GrContextPriv(this); }
83 
contextPriv()84 inline const GrContextPriv GrContext::contextPriv () const {
85     return GrContextPriv(const_cast<GrContext*>(this));
86 }
87 
88 #endif
89