blob: dfaf914999cc14b669d717e919e9bef4931c2f14 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/GrRecordingContext.h"
Robert Phillips4217ea72019-01-30 13:08:28 -050012
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 Phillipsbb606772019-02-04 17:50:57 -050025 const GrCaps* caps() const { return fContext->caps(); }
Robert Phillipsa41c6852019-02-07 10:44:10 -050026 sk_sp<const GrCaps> refCaps() const;
Robert Phillipsbb606772019-02-04 17:50:57 -050027
Robert Phillipsa41c6852019-02-07 10:44:10 -050028 sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
29
30 GrImageContext* asImageContext() { return fContext->asImageContext(); }
31 GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); }
32 GrContext* asDirectContext() { return fContext->asDirectContext(); }
Robert Phillipsbb606772019-02-04 17:50:57 -050033
Robert Phillips4217ea72019-01-30 13:08:28 -050034 // from GrImageContext
Robert Phillipsa41c6852019-02-07 10:44:10 -050035 GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
36 const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
37
Robert Phillipsa9162df2019-02-11 14:12:03 -050038 bool abandoned() const { return fContext->abandoned(); }
39
Robert Phillipsa41c6852019-02-07 10:44:10 -050040 /** This is only useful for debug purposes */
41 SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
Robert Phillips4217ea72019-01-30 13:08:28 -050042
43 // from GrRecordingContext
Robert Phillips6f0e02f2019-02-13 11:02:28 -050044 GrDrawingManager* drawingManager() { return fContext->drawingManager(); }
45
Robert Phillipsd6841482019-02-08 10:29:20 -050046 sk_sp<GrOpMemoryPool> refOpMemoryPool();
47 GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
48
Robert Phillips61fc7992019-10-22 11:58:17 -040049 SkArenaAlloc* opPODAllocator() { return fContext->opPODAllocator(); }
50 std::unique_ptr<SkArenaAlloc> detachOpPOD();
51
Herb Derbya00da612019-03-04 17:10:01 -050052 GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
Robert Phillips2184fb72019-02-21 16:11:41 -050053 GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
54
Robert Phillipsc5058a62019-02-15 12:52:59 -050055 /**
56 * Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
57 *
58 * NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
59 * ensure its lifetime is tied to that of the context.
60 */
61 void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
62
Brian Salomonbf6b9792019-08-21 09:38:10 -040063 std::unique_ptr<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
64 GrColorType,
65 SkAlphaType,
66 sk_sp<SkColorSpace> = nullptr,
67 const SkSurfaceProps* = nullptr);
Robert Phillips292a6b22019-02-14 14:49:02 -050068
Brian Salomon947efe22019-07-16 15:36:11 -040069 /** Create a new texture context backed by a deferred-style GrTextureProxy. */
Brian Salomonbf6b9792019-08-21 09:38:10 -040070 std::unique_ptr<GrTextureContext> makeDeferredTextureContext(
Brian Salomon947efe22019-07-16 15:36:11 -040071 SkBackingFit,
72 int width,
73 int height,
74 GrColorType,
75 SkAlphaType,
76 sk_sp<SkColorSpace>,
77 GrMipMapped = GrMipMapped::kNo,
78 GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin,
79 SkBudgeted = SkBudgeted::kYes,
80 GrProtected = GrProtected::kNo);
Robert Phillips292a6b22019-02-14 14:49:02 -050081
Robert Phillipsb97da532019-02-12 15:24:12 -050082 /*
83 * Create a new render target context backed by a deferred-style
84 * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for
85 * renderTargetContexts created via this entry point.
86 */
Brian Salomonbf6b9792019-08-21 09:38:10 -040087 std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -040088 SkBackingFit fit,
89 int width,
90 int height,
Brian Salomond6287472019-06-24 15:50:07 -040091 GrColorType,
92 sk_sp<SkColorSpace> colorSpace,
93 int sampleCnt = 1,
94 GrMipMapped = GrMipMapped::kNo,
95 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
96 const SkSurfaceProps* surfaceProps = nullptr,
97 SkBudgeted = SkBudgeted::kYes,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040098 GrProtected isProtected = GrProtected::kNo);
Robert Phillipsb97da532019-02-12 15:24:12 -050099
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500100 /*
101 * This method will attempt to create a renderTargetContext that has, at least, the number of
102 * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be
103 * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA).
104 * SRGB-ness will be preserved.
105 */
Brian Salomonbf6b9792019-08-21 09:38:10 -0400106 std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
Brian Salomond6287472019-06-24 15:50:07 -0400107 SkBackingFit fit,
108 int width,
109 int height,
Brian Salomond6287472019-06-24 15:50:07 -0400110 GrColorType,
111 sk_sp<SkColorSpace> colorSpace,
112 int sampleCnt = 1,
113 GrMipMapped = GrMipMapped::kNo,
114 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin,
115 const SkSurfaceProps* surfaceProps = nullptr,
116 SkBudgeted budgeted = SkBudgeted::kYes,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400117 GrProtected isProtected = GrProtected::kNo);
Robert Phillips6f0e02f2019-02-13 11:02:28 -0500118
Robert Phillipsd6841482019-02-08 10:29:20 -0500119 GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
Robert Phillips4217ea72019-01-30 13:08:28 -0500120
Robert Phillips9338c602019-02-19 12:52:29 -0500121 // CONTEXT TODO: remove this backdoor
122 // In order to make progress we temporarily need a way to break CL impasses.
123 GrContext* backdoor();
124
Robert Phillips4217ea72019-01-30 13:08:28 -0500125private:
126 explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
127 GrRecordingContextPriv(const GrRecordingContextPriv&); // unimpl
128 GrRecordingContextPriv& operator=(const GrRecordingContextPriv&); // unimpl
129
130 // No taking addresses of this type.
131 const GrRecordingContextPriv* operator&() const;
132 GrRecordingContextPriv* operator&();
133
134 GrRecordingContext* fContext;
135
136 friend class GrRecordingContext; // to construct/copy this type.
137};
138
139inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); }
140
141inline const GrRecordingContextPriv GrRecordingContext::priv () const {
142 return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this));
143}
144
145#endif