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 GrRecordingContext_DEFINED 9 #define GrRecordingContext_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/private/GrImageContext.h" 13 14 class GrAuditTrail; 15 class GrBackendFormat; 16 class GrDrawingManager; 17 class GrOnFlushCallbackObject; 18 class GrOpMemoryPool; 19 class GrRecordingContextPriv; 20 class GrStrikeCache; 21 class GrSurfaceContext; 22 class GrSurfaceProxy; 23 class GrTextBlobCache; 24 class GrTextureContext; 25 26 class SK_API GrRecordingContext : public GrImageContext { 27 public: 28 ~GrRecordingContext() override; 29 defaultBackendFormat(SkColorType ct,GrRenderable renderable)30 GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const { 31 return INHERITED::defaultBackendFormat(ct, renderable); 32 } 33 34 // Provides access to functions that aren't part of the public API. 35 GrRecordingContextPriv priv(); 36 const GrRecordingContextPriv priv() const; 37 38 protected: 39 friend class GrRecordingContextPriv; // for hidden functions 40 41 GrRecordingContext(GrBackendApi, const GrContextOptions&, uint32_t contextID); 42 bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override; 43 void setupDrawingManager(bool sortOpLists, bool reduceOpListSplitting); 44 45 void abandonContext() override; 46 47 GrDrawingManager* drawingManager(); 48 49 sk_sp<GrOpMemoryPool> refOpMemoryPool(); 50 GrOpMemoryPool* opMemoryPool(); 51 getGrStrikeCache()52 GrStrikeCache* getGrStrikeCache() { return fStrikeCache.get(); } 53 GrTextBlobCache* getTextBlobCache(); 54 const GrTextBlobCache* getTextBlobCache() const; 55 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 64 sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>, 65 GrColorType, 66 SkAlphaType, 67 sk_sp<SkColorSpace> = nullptr, 68 const SkSurfaceProps* = nullptr); 69 70 /** Create a new texture context backed by a deferred-style GrTextureProxy. */ 71 sk_sp<GrTextureContext> makeDeferredTextureContext( 72 SkBackingFit, 73 int width, 74 int height, 75 GrColorType, 76 SkAlphaType, 77 sk_sp<SkColorSpace>, 78 GrMipMapped = GrMipMapped::kNo, 79 GrSurfaceOrigin = kTopLeft_GrSurfaceOrigin, 80 SkBudgeted = SkBudgeted::kYes, 81 GrProtected = GrProtected::kNo); 82 83 /* 84 * Create a new render target context backed by a deferred-style 85 * GrRenderTargetProxy. We guarantee that "asTextureProxy" will succeed for 86 * renderTargetContexts created via this entry point. 87 */ 88 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext( 89 SkBackingFit fit, 90 int width, 91 int height, 92 GrColorType colorType, 93 sk_sp<SkColorSpace> colorSpace, 94 int sampleCnt = 1, 95 GrMipMapped = GrMipMapped::kNo, 96 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, 97 const SkSurfaceProps* surfaceProps = nullptr, 98 SkBudgeted = SkBudgeted::kYes, 99 GrProtected isProtected = GrProtected::kNo); 100 101 /* 102 * This method will attempt to create a renderTargetContext that has, at least, the number of 103 * channels and precision per channel as requested in 'config' (e.g., A8 and 888 can be 104 * converted to 8888). It may also swizzle the channels (e.g., BGRA -> RGBA). 105 * SRGB-ness will be preserved. 106 */ 107 sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback( 108 SkBackingFit fit, 109 int width, 110 int height, 111 GrColorType colorType, 112 sk_sp<SkColorSpace> colorSpace, 113 int sampleCnt = 1, 114 GrMipMapped = GrMipMapped::kNo, 115 GrSurfaceOrigin origin = kBottomLeft_GrSurfaceOrigin, 116 const SkSurfaceProps* surfaceProps = nullptr, 117 SkBudgeted budgeted = SkBudgeted::kYes, 118 GrProtected isProtected = GrProtected::kNo); 119 auditTrail()120 GrAuditTrail* auditTrail() { return fAuditTrail.get(); } 121 asRecordingContext()122 GrRecordingContext* asRecordingContext() override { return this; } 123 124 private: 125 std::unique_ptr<GrDrawingManager> fDrawingManager; 126 // All the GrOp-derived classes use this pool. 127 sk_sp<GrOpMemoryPool> fOpMemoryPool; 128 129 std::unique_ptr<GrStrikeCache> fStrikeCache; 130 std::unique_ptr<GrTextBlobCache> fTextBlobCache; 131 132 std::unique_ptr<GrAuditTrail> fAuditTrail; 133 134 typedef GrImageContext INHERITED; 135 }; 136 137 #endif 138