blob: d27c25eec2eb39f8e0a634f59b5178cddb621b3b [file] [log] [blame]
Robert Phillipsa0bc39d2019-01-29 13:14:47 -05001/*
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
14class GrBackendFormat;
15class GrCaps;
16class GrContext;
Robert Phillipsfd0d9702019-02-01 10:19:42 -050017class GrContext_Base;
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050018class GrContextThreadSafeProxyPriv;
19class GrSkSLFPFactoryCache;
20struct SkImageInfo;
21class 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 */
27class SK_API GrContextThreadSafeProxy : public SkRefCnt {
28public:
29 ~GrContextThreadSafeProxy() override;
30
Robert Phillipsfd0d9702019-02-01 10:19:42 -050031 bool matches(GrContext_Base* context) const;
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050032
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.
Robert Phillipsb45f47d2019-02-03 17:17:54 -050062 * @param isTextureable Will the surface be able to act as a texture?
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050063 */
64 SkSurfaceCharacterization createCharacterization(
65 size_t cacheMaxResourceBytes,
66 const SkImageInfo& ii, const GrBackendFormat& backendFormat,
67 int sampleCount, GrSurfaceOrigin origin,
68 const SkSurfaceProps& surfaceProps,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050069 bool isMipMapped,
70 bool willUseGLFBO0 = false,
71 bool isTextureable = true);
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050072
73 bool operator==(const GrContextThreadSafeProxy& that) const {
74 // Each GrContext should only ever have a single thread-safe proxy.
Robert Phillipsfd0d9702019-02-01 10:19:42 -050075 SkASSERT((this == &that) == (fContextID == that.fContextID));
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050076 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
85private:
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;
Robert Phillipsfd0d9702019-02-01 10:19:42 -050094 const uint32_t fContextID;
95 const GrBackendApi fBackend;
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050096 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