blob: 46f13f29a65ced7830dc40bc19ad487720569de4 [file] [log] [blame]
Robert Phillips4217ea72019-01-30 13:08:28 -05001/*
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 "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. */
16class GrRecordingContextPriv {
17public:
18 // from GrContext_Base
Robert Phillipsfd0d9702019-02-01 10:19:42 -050019 uint32_t contextID() const { return fContext->contextID(); }
Robert Phillips4217ea72019-01-30 13:08:28 -050020
Robert Phillipsfe0963c2019-02-07 13:25:07 -050021 bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); }
22
Robert Phillipsc1541ae2019-02-04 12:05:37 -050023 const GrContextOptions& options() const { return fContext->options(); }
24
Robert Phillips7e90be92019-02-15 12:22:59 -050025 bool explicitlyAllocateGPUResources() const {
26 return fContext->explicitlyAllocateGPUResources();
27 }
28
Robert Phillipsbb606772019-02-04 17:50:57 -050029 const GrCaps* caps() const { return fContext->caps(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050030 sk_sp<const GrCaps> refCaps() const;
Robert Phillipsbb606772019-02-04 17:50:57 -050031
Robert Phillipsa41c6852019-02-07 10:44:10 -050032 sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
33
34 GrImageContext* asImageContext() { return fContext->asImageContext(); }
35 GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
36 GrContext* asDirectContext() { return fContext->asDirectContext(); }
Robert Phillipsbb606772019-02-04 17:50:57 -050037
Robert Phillips4217ea72019-01-30 13:08:28 -050038 // from GrImageContext
Robert Phillipsa41c6852019-02-07 10:44:10 -050039 GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
40 const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
41
Robert Phillipsa9162df2019-02-11 14:12:03 -050042 bool abandoned() const { return fContext->abandoned(); }
43
Robert Phillipsa41c6852019-02-07 10:44:10 -050044 /** This is only useful for debug purposes */
45 SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
Robert Phillips4217ea72019-01-30 13:08:28 -050046
47 // from GrRecordingContext
Robert Phillips6f0e02f2019-02-13 11:02:28 -050048 GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
49
Robert Phillipsd6841482019-02-08 10:29:20 -050050 sk_sp<GrOpMemoryPool> refOpMemoryPool();
51 GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
52
Herb Derbya00da612019-03-04 17:10:01 -050053 GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
Robert Phillips2184fb72019-02-21 16:11:41 -050054 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
55
Robert Phillipsc5058a62019-02-15 12:52:59 -050056 /**
57 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
58 *
59 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
60 * ensure its lifetime is tied to that of the context.
61 */
62 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
63
Robert Phillips292a6b22019-02-14 14:49:02 -050064 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
65 sk_sp<SkColorSpace> = nullptr,
66 const SkSurfaceProps* = nullptr);
67
68 sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrBackendFormat&,
69 const GrSurfaceDesc&,
70 GrSurfaceOrigin,
71 GrMipMapped,
72 SkBackingFit,
73 SkBudgeted,
74 sk_sp<SkColorSpace> colorSpace = nullptr,
75 const SkSurfaceProps* = nullptr);
76
Robert Phillipsb97da532019-02-12 15:24:12 -050077 /*
78 * Create a new render target context backed by a deferred-style
79 * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
80 * renderTargetContexts created via this entry point.
81 */
82 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
83 const GrBackendFormat& format,
84 SkBackingFit fit,
85 int width, int height,
86 GrPixelConfig config,
87 sk_sp<SkColorSpace> colorSpace,
88 int sampleCnt = 1,
89 GrMipMapped = GrMipMapped::kNo,
90 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
91 const SkSurfaceProps* surfaceProps = nullptr,
92 SkBudgeted = SkBudgeted::kYes);
93
Robert Phillips6f0e02f2019-02-13 11:02:28 -050094 /*
95 * This method will attempt to create a renderTargetContext that has, at least, the number of
96 * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
97 * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
98 * SRGB-ness will be preserved.
99 */
100 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
101 const GrBackendFormat& format,
102 SkBackingFit fit,
103 int width, int height,
104 GrPixelConfig config,
105 sk_sp<SkColorSpace> colorSpace,
106 int sampleCnt = 1,
107 GrMipMapped = GrMipMapped::kNo,
108 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
109 const SkSurfaceProps* surfaceProps = nullptr,
110 SkBudgeted budgeted = SkBudgeted::kYes);
111
Robert Phillipsd6841482019-02-08 10:29:20 -0500112 GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
Robert Phillips4217ea72019-01-30 13:08:28 -0500113
Robert Phillips9338c602019-02-19 12:52:29 -0500114 // CONTEXT TODO: remove this backdoor
115 // In order to make progress we temporarily need a way to break CL impasses.
116 GrContext* backdoor();
117
Robert Phillips4217ea72019-01-30 13:08:28 -0500118private:
119 explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
120 GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl
121 GrRecordingContextPriv& operator=(const GrRecordingContextPriv&); // unimpl
122
123 // No taking addresses of this type.
124 const GrRecordingContextPriv* operator&() const;
125 GrRecordingContextPriv* operator&();
126
127 GrRecordingContext* fContext;
128
129 friend class GrRecordingContext; // to construct/copy this type.
130};
131
132inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
133
134inline const GrRecordingContextPriv GrRecordingContext::priv () const {
135 return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
136}
137
138#endif