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