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