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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrRecordingContext.h" |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 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 | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 25 | const GrCaps* caps() const { return fContext->caps(); } |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 26 | sk_sp<const GrCaps> refCaps() const; |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 27 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 28 | sk_sp<GrSkSLFPFactoryCache> fpFactoryCache(); |
| 29 | |
| 30 | GrImageContext* asImageContext() { return fContext->asImageContext(); } |
| 31 | GrRecordingContext* asRecordingContext() { return fContext->asRecordingContext(); } |
| 32 | GrContext* asDirectContext() { return fContext->asDirectContext(); } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 33 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 34 | // from GrImageContext |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 35 | GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); } |
| 36 | const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); } |
| 37 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 38 | bool abandoned() const { return fContext->abandoned(); } |
| 39 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 40 | /** This is only useful for debug purposes */ |
| 41 | SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } ) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 42 | |
| 43 | // from GrRecordingContext |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 44 | GrDrawingManager* drawingManager() { return fContext->drawingManager(); } |
| 45 | |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 46 | sk_sp<GrOpMemoryPool> refOpMemoryPool(); |
| 47 | GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); } |
| 48 | |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame^] | 49 | SkArenaAlloc* opPODAllocator() { return fContext->opPODAllocator(); } |
| 50 | std::unique_ptr<SkArenaAlloc> detachOpPOD(); |
| 51 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 52 | GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); } |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 53 | GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); } |
| 54 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 55 | /** |
| 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 Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 63 | std::unique_ptr<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, |
| 64 | GrColorType, |
| 65 | SkAlphaType, |
| 66 | sk_sp<SkColorSpace> = nullptr, |
| 67 | const SkSurfaceProps* = nullptr); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 68 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 69 | /** Create a new texture context backed by a deferred-style GrTextureProxy. */ |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 70 | std::unique_ptr<GrTextureContext> makeDeferredTextureContext( |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 71 | 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 Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 81 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 82 | /* |
| 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 Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 87 | std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 88 | SkBackingFit fit, |
| 89 | int width, |
| 90 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 91 | 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 Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 98 | GrProtected isProtected = GrProtected::kNo); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 99 | |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 100 | /* |
| 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 Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 106 | std::unique_ptr<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 107 | SkBackingFit fit, |
| 108 | int width, |
| 109 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 110 | 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 Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 117 | GrProtected isProtected = GrProtected::kNo); |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 118 | |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 119 | GrAuditTrail* auditTrail() { return fContext->auditTrail(); } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 120 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 121 | // 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 Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 125 | private: |
| 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 | |
| 139 | inline GrRecordingContextPriv GrRecordingContext::priv() { return GrRecordingContextPriv(this); } |
| 140 | |
| 141 | inline const GrRecordingContextPriv GrRecordingContext::priv () const { |
| 142 | return GrRecordingContextPriv(const_cast<GrRecordingContext*>(this)); |
| 143 | } |
| 144 | |
| 145 | #endif |