blob: 2d119387fb634c1b97c550e2aedb9d1221eee513 [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.
62 */
63 SkSurfaceCharacterization createCharacterization(
64 size_t cacheMaxResourceBytes,
65 const SkImageInfo& ii, const GrBackendFormat& backendFormat,
66 int sampleCount, GrSurfaceOrigin origin,
67 const SkSurfaceProps& surfaceProps,
68 bool isMipMapped, bool willUseGLFBO0 = false);
69
70 bool operator==(const GrContextThreadSafeProxy& that) const {
71 // Each GrContext should only ever have a single thread-safe proxy.
Robert Phillipsfd0d9702019-02-01 10:19:42 -050072 SkASSERT((this == &that) == (fContextID == that.fContextID));
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050073 return this == &that;
74 }
75
76 bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); }
77
78 // Provides access to functions that aren't part of the public API.
79 GrContextThreadSafeProxyPriv priv();
80 const GrContextThreadSafeProxyPriv priv() const;
81
82private:
83 // DDL TODO: need to add unit tests for backend & maybe options
84 GrContextThreadSafeProxy(sk_sp<const GrCaps> caps,
85 uint32_t uniqueID,
86 GrBackendApi backend,
87 const GrContextOptions& options,
88 sk_sp<GrSkSLFPFactoryCache> cache);
89
90 sk_sp<const GrCaps> fCaps;
Robert Phillipsfd0d9702019-02-01 10:19:42 -050091 const uint32_t fContextID;
92 const GrBackendApi fBackend;
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050093 const GrContextOptions fOptions;
94 sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
95
96 friend class GrDirectContext; // To construct this object
97 friend class GrContextThreadSafeProxyPriv;
98
99 typedef SkRefCnt INHERITED;
100};
101
102#endif