1 /*
2  * Copyright 2019 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 GrRecordingContextPriv_DEFINED
9 #define GrRecordingContextPriv_DEFINED
10 
11 #include "include/private/GrRecordingContext.h"
12 
13 /** Class that exposes methods to GrRecordingContext that are only intended for use internal to
14     Skia. This class is purely a privileged window into GrRecordingContext. It should never have
15     additional data members or virtual methods. */
16 class GrRecordingContextPriv {
17 public:
18     // from GrContext_Base
contextID()19     uint32_t contextID() const { return fContext->contextID(); }
20 
matches(GrContext_Base * candidate)21     bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
22 
options()23     const GrContextOptions& options() const { return fContext->options(); }
24 
caps()25     const GrCaps* caps() const { return fContext->caps(); }
26     sk_sp<const GrCaps> refCaps() const;
27 
28     sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
29 
asImageContext()30     GrImageContext* asImageContext() { return fContext->asImageContext(); }
asRecordingContext()31     GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
asDirectContext()32     GrContext* asDirectContext() { return fContext->asDirectContext(); }
33 
34     // from GrImageContext
proxyProvider()35     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
proxyProvider()36     const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
37 
abandoned()38     bool abandoned() const { return fContext->abandoned(); }
39 
40     /** This is only useful for debug purposes */
SkDEBUGCODE(GrSingleOwner * singleOwner ()const{ return fContext->singleOwner(); } )41     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
42 
43     // from GrRecordingContext
44     GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
45 
46     sk_sp<GrOpMemoryPool> refOpMemoryPool();
opMemoryPool()47     GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
48 
getGrStrikeCache()49     GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
getTextBlobCache()50     GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
51 
52     /**
53      * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
54      *
55      * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
56      * ensure its lifetime is tied to that of the context.
57      */
58     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
59 
60     std::unique_ptr<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
61                                                                 GrColorType,
62                                                                 SkAlphaType,
63                                                                 sk_sp<SkColorSpace> = nullptr,
64                                                                 const SkSurfaceProps* = nullptr);
65 
66     /** Create a new texture context backed by a deferred-style GrTextureProxy. */
67     std::unique_ptr<GrTextureContext> makeDeferredTextureContext(
68             SkBackingFit,
69             int width,
70             int height,
71             GrColorType,
72             SkAlphaType,
73             sk_sp<SkColorSpace>,
74             GrMipMapped = GrMipMapped::kNo,
75             GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
76             SkBudgeted = SkBudgeted::kYes,
77             GrProtected = GrProtected::kNo);
78 
79     /*
80      * Create a new render target context backed by a deferred-style
81      * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
82      * renderTargetContexts created via this entry point.
83      */
84     std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContext(
85             SkBackingFit fit,
86             int width,
87             int height,
88             GrColorType,
89             sk_sp<SkColorSpace> colorSpace,
90             int sampleCnt = 1,
91             GrMipMapped = GrMipMapped::kNo,
92             GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
93             const SkSurfaceProps* surfaceProps = nullptr,
94             SkBudgeted = SkBudgeted::kYes,
95             GrProtected isProtected = GrProtected::kNo);
96 
97     /*
98      * This method will attempt to create a renderTargetContext that has, at least, the number of
99      * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
100      * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
101      * SRGB-ness will be preserved.
102      */
103     std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
104             SkBackingFit fit,
105             int width,
106             int height,
107             GrColorType,
108             sk_sp<SkColorSpace> colorSpace,
109             int sampleCnt = 1,
110             GrMipMapped = GrMipMapped::kNo,
111             GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
112             const SkSurfaceProps* surfaceProps = nullptr,
113             SkBudgeted budgeted = SkBudgeted::kYes,
114             GrProtected isProtected = GrProtected::kNo);
115 
auditTrail()116     GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
117 
118     // CONTEXT TODO: remove this backdoor
119     // In order to make progress we temporarily need a way to break CL impasses.
120     GrContext* backdoor();
121 
122 private:
GrRecordingContextPriv(GrRecordingContext * context)123     explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
124     GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl
125     GrRecordingContextPriv& operator=(const GrRecordingContextPriv&); // unimpl
126 
127     // No taking addresses of this type.
128     const GrRecordingContextPriv* operator&() const;
129     GrRecordingContextPriv* operator&();
130 
131     GrRecordingContext* fContext;
132 
133     friend class GrRecordingContext; // to construct/copy this type.
134 };
135 
priv()136 inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
137 
priv()138 inline const GrRecordingContextPriv GrRecordingContext::priv () const {
139     return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
140 }
141 
142 #endif
143