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 GrContext_Base_DEFINED 9 #define GrContext_Base_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/gpu/GrBackendSurface.h" 13 #include "include/gpu/GrContextOptions.h" 14 #include "include/gpu/GrTypes.h" 15 16 class GrBaseContextPriv; 17 class GrCaps; 18 class GrContext; 19 class GrImageContext; 20 class GrRecordingContext; 21 class GrSkSLFPFactoryCache; 22 23 class SK_API GrContext_Base : public SkRefCnt { 24 public: 25 virtual ~GrContext_Base(); 26 27 /* 28 * The 3D API backing this context 29 */ backend()30 GrBackendApi backend() const { return fBackend; } 31 32 /* 33 * Retrieve the default GrBackendFormat for a given SkColorType and renderability. 34 * It is guaranteed that this backend format will be the one used by the GrContext 35 * SkColorType and SkSurfaceCharacterization-based createBackendTexture methods. 36 * 37 * The caller should check that the returned format is valid. 38 */ 39 GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const; 40 41 // Provides access to functions that aren't part of the public API. 42 GrBaseContextPriv priv(); 43 const GrBaseContextPriv priv() const; 44 45 protected: 46 friend class GrBaseContextPriv; // for hidden functions 47 48 GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t contextID); 49 50 virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>); 51 52 /** 53 * An identifier for this context. The id is used by all compatible contexts. For example, 54 * if SkImages are created on one thread using an image creation context, then fed into a 55 * DDL Recorder on second thread (which has a recording context) and finally replayed on 56 * a third thread with a direct context, then all three contexts will report the same id. 57 * It is an error for an image to be used with contexts that report different ids. 58 */ contextID()59 uint32_t contextID() const { return fContextID; } 60 matches(GrContext_Base * candidate)61 bool matches(GrContext_Base* candidate) const { 62 return candidate->contextID() == this->contextID(); 63 } 64 65 /* 66 * The options in effect for this context 67 */ options()68 const GrContextOptions& options() const { return fOptions; } 69 70 const GrCaps* caps() const; 71 sk_sp<const GrCaps> refCaps() const; 72 73 sk_sp<GrSkSLFPFactoryCache> fpFactoryCache(); 74 asImageContext()75 virtual GrImageContext* asImageContext() { return nullptr; } asRecordingContext()76 virtual GrRecordingContext* asRecordingContext() { return nullptr; } asDirectContext()77 virtual GrContext* asDirectContext() { return nullptr; } 78 79 private: 80 const GrBackendApi fBackend; 81 const GrContextOptions fOptions; 82 const uint32_t fContextID; 83 sk_sp<const GrCaps> fCaps; 84 sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache; 85 86 typedef SkRefCnt INHERITED; 87 }; 88 89 #endif 90