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