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 GrContextThreadSafeProxy_DEFINED 9 #define GrContextThreadSafeProxy_DEFINED 10 11 #include "GrContextOptions.h" 12 #include "SkRefCnt.h" 13 14 class GrBackendFormat; 15 class GrCaps; 16 class GrContext; 17 class GrContext_Base; 18 class GrContextThreadSafeProxyPriv; 19 class GrSkSLFPFactoryCache; 20 struct SkImageInfo; 21 class SkSurfaceCharacterization; 22 23 /** 24 * Can be used to perform actions related to the generating GrContext in a thread safe manner. The 25 * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext. 26 */ 27 class SK_API GrContextThreadSafeProxy : public SkRefCnt { 28 public: 29 ~GrContextThreadSafeProxy() override; 30 31 bool matches(GrContext_Base* context) const; 32 33 /** 34 * Create a surface characterization for a DDL that will be replayed into the GrContext 35 * that created this proxy. On failure the resulting characterization will be invalid (i.e., 36 * "!c.isValid()"). 37 * 38 * @param cacheMaxResourceBytes The max resource bytes limit that will be in effect when the 39 * DDL created with this characterization is replayed. 40 * Note: the contract here is that the DDL will be created as 41 * if it had a full 'cacheMaxResourceBytes' to use. If replayed 42 * into a GrContext that already has locked GPU memory, the 43 * replay can exceed the budget. To rephrase, all resource 44 * allocation decisions are made at record time and at playback 45 * time the budget limits will be ignored. 46 * @param ii The image info specifying properties of the SkSurface that 47 * the DDL created with this characterization will be replayed 48 * into. 49 * Note: Ganesh doesn't make use of the SkImageInfo's alphaType 50 * @param backendFormat Information about the format of the GPU surface that will 51 * back the SkSurface upon replay 52 * @param sampleCount The sample count of the SkSurface that the DDL created with 53 * this characterization will be replayed into 54 * @param origin The origin of the SkSurface that the DDL created with this 55 * characterization will be replayed into 56 * @param surfaceProps The surface properties of the SkSurface that the DDL created 57 * with this characterization will be replayed into 58 * @param isMipMapped Will the surface the DDL will be replayed into have space 59 * allocated for mipmaps? 60 * @param willUseGLFBO0 Will the surface the DDL will be replayed into be backed by GL 61 * FBO 0. This flag is only valid if using an GL backend. 62 * @param isTextureable Will the surface be able to act as a texture? 63 */ 64 SkSurfaceCharacterization createCharacterization( 65 size_t cacheMaxResourceBytes, 66 const SkImageInfo& ii, const GrBackendFormat& backendFormat, 67 int sampleCount, GrSurfaceOrigin origin, 68 const SkSurfaceProps& surfaceProps, 69 bool isMipMapped, 70 bool willUseGLFBO0 = false, 71 bool isTextureable = true); 72 73 bool operator==(const GrContextThreadSafeProxy& that) const { 74 // Each GrContext should only ever have a single thread-safe proxy. 75 SkASSERT((this == &that) == (fContextID == that.fContextID)); 76 return this == &that; 77 } 78 79 bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); } 80 81 // Provides access to functions that aren't part of the public API. 82 GrContextThreadSafeProxyPriv priv(); 83 const GrContextThreadSafeProxyPriv priv() const; 84 85 private: 86 // DDL TODO: need to add unit tests for backend & maybe options 87 GrContextThreadSafeProxy(sk_sp<const GrCaps> caps, 88 uint32_t uniqueID, 89 GrBackendApi backend, 90 const GrContextOptions& options, 91 sk_sp<GrSkSLFPFactoryCache> cache); 92 93 sk_sp<const GrCaps> fCaps; 94 const uint32_t fContextID; 95 const GrBackendApi fBackend; 96 const GrContextOptions fOptions; 97 sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache; 98 99 friend class GrDirectContext; // To construct this object 100 friend class GrContextThreadSafeProxyPriv; 101 102 typedef SkRefCnt INHERITED; 103 }; 104 105 #endif 106