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