blob: c66ab853bd56e75eaacf5ad4ef2eb0a0db5ad53b [file] [log] [blame]
Robert Phillips4217ea72019-01-30 13:08:28 -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 GrContext_Base_DEFINED
9#define GrContext_Base_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkRefCnt.h"
12#include "include/gpu/GrContextOptions.h"
13#include "include/gpu/GrTypes.h"
Robert Phillips4217ea72019-01-30 13:08:28 -050014
15class GrBaseContextPriv;
Robert Phillipsbb606772019-02-04 17:50:57 -050016class GrCaps;
Robert Phillips4217ea72019-01-30 13:08:28 -050017class GrContext;
18class GrImageContext;
19class GrRecordingContext;
Robert Phillipsbb606772019-02-04 17:50:57 -050020class GrSkSLFPFactoryCache;
Robert Phillips4217ea72019-01-30 13:08:28 -050021
22class SK_API GrContext_Base : public SkRefCnt {
23public:
24 virtual ~GrContext_Base();
25
26 /*
27 * The 3D API backing this context
28 */
29 GrBackendApi backend() const { return fBackend; }
30
Robert Phillips4217ea72019-01-30 13:08:28 -050031 // Provides access to functions that aren't part of the public API.
32 GrBaseContextPriv priv();
33 const GrBaseContextPriv priv() const;
34
35protected:
36 friend class GrBaseContextPriv; // for hidden functions
37
Robert Phillipsa41c6852019-02-07 10:44:10 -050038 GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t contextID);
Robert Phillips4217ea72019-01-30 13:08:28 -050039
Robert Phillips292a6b22019-02-14 14:49:02 -050040 virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>);
41
Robert Phillipsfd0d9702019-02-01 10:19:42 -050042 /**
43 * An identifier for this context. The id is used by all compatible contexts. For example,
44 * if SkImages are created on one thread using an image creation context, then fed into a
45 * DDL Recorder on second thread (which has a recording context) and finally replayed on
46 * a third thread with a direct context, then all three contexts will report the same id.
47 * It is an error for an image to be used with contexts that report different ids.
48 */
49 uint32_t contextID() const { return fContextID; }
50
Robert Phillipsfe0963c2019-02-07 13:25:07 -050051 bool matches(GrContext_Base* candidate) const {
52 return candidate->contextID() == this->contextID();
53 }
54
Robert Phillipsc1541ae2019-02-04 12:05:37 -050055 /*
56 * The options in effect for this context
57 */
58 const GrContextOptions& options() const { return fOptions; }
59
Robert Phillipsbb606772019-02-04 17:50:57 -050060 const GrCaps* caps() const;
61 sk_sp<const GrCaps> refCaps() const;
62
63 sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
64
Robert Phillips4217ea72019-01-30 13:08:28 -050065 virtual GrImageContext* asImageContext() { return nullptr; }
66 virtual GrRecordingContext* asRecordingContext() { return nullptr; }
67 virtual GrContext* asDirectContext() { return nullptr; }
68
69private:
Robert Phillipsbb606772019-02-04 17:50:57 -050070 const GrBackendApi fBackend;
71 const GrContextOptions fOptions;
72 const uint32_t fContextID;
73 sk_sp<const GrCaps> fCaps;
74 sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
Robert Phillips4217ea72019-01-30 13:08:28 -050075
76 typedef SkRefCnt INHERITED;
77};
78
79#endif