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