Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 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 "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 |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 19 | uint32_t contextID() const { return fContext->contextID(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 20 | |
Robert Phillips | fe0963c | 2019-02-07 13:25:07 -0500 | [diff] [blame] | 21 | bool matches(GrContext_Base* candidate) const { return fContext->matches(candidate); } |
| 22 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 23 | const GrContextOptions& options() const { return fContext->options(); } |
| 24 | |
Robert Phillips | 7e90be9 | 2019-02-15 12:22:59 -0500 | [diff] [blame] | 25 | bool explicitlyAllocateGPUResources() const { |
| 26 | return fContext->explicitlyAllocateGPUResources(); |
| 27 | } |
| 28 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 29 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 30 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 31 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 32 | sk_sp<GrSkSLFPFactoryCache> fpFactoryCache(); |
| 33 | |
| 34 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 35 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
| 36 | GrContext* asDirectContext() { return fContext->asDirectContext(); } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 37 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 38 | // from GrImageContext |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 39 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
| 40 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
| 41 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 42 | bool abandoned() const { return fContext->abandoned(); } |
| 43 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 44 | /** This is only useful for debug purposes */ |
| 45 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 46 | |
| 47 | // from GrRecordingContext |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 48 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
| 49 | |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 50 | sk_sp<GrOpMemoryPool> refOpMemoryPool(); |
| 51 | GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); } |
| 52 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 53 | GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); } |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 54 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
| 55 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 56 | /** |
| 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 Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 64 | 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 Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 77 | /* |
| 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 Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 94 | /* |
| 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 Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 112 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 113 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 114 | // 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 Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 118 | private: |
| 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 | |
| 132 | inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); } |
| 133 | |
| 134 | inline const GrRecordingContextPriv GrRecordingContext::priv () const { |
| 135 | return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this)); |
| 136 | } |
| 137 | |
| 138 | #endif |