blob: bc18ac0f898bef85f29db527b39724e632d23161 [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
11#include "SkRefCnt.h"
Robert Phillipsc1541ae2019-02-04 12:05:37 -050012#include "GrContextOptions.h"
Robert Phillips4217ea72019-01-30 13:08:28 -050013#include "GrTypes.h"
14
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 Phillipsfd0d9702019-02-01 10:19:42 -050040 /**
41 * An identifier for this context. The id is used by all compatible contexts. For example,
42 * if SkImages are created on one thread using an image creation context, then fed into a
43 * DDL Recorder on second thread (which has a recording context) and finally replayed on
44 * a third thread with a direct context, then all three contexts will report the same id.
45 * It is an error for an image to be used with contexts that report different ids.
46 */
47 uint32_t contextID() const { return fContextID; }
48
Robert Phillipsfe0963c2019-02-07 13:25:07 -050049 bool matches(GrContext_Base* candidate) const {
50 return candidate->contextID() == this->contextID();
51 }
52
Robert Phillipsc1541ae2019-02-04 12:05:37 -050053 /*
54 * The options in effect for this context
55 */
56 const GrContextOptions& options() const { return fOptions; }
57
Robert Phillipsbb606772019-02-04 17:50:57 -050058 const GrCaps* caps() const;
59 sk_sp<const GrCaps> refCaps() const;
60
61 sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
62
Robert Phillips4217ea72019-01-30 13:08:28 -050063 virtual GrImageContext* asImageContext() { return nullptr; }
64 virtual GrRecordingContext* asRecordingContext() { return nullptr; }
65 virtual GrContext* asDirectContext() { return nullptr; }
66
Robert Phillipsbb606772019-02-04 17:50:57 -050067 virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>);
68
Robert Phillips4217ea72019-01-30 13:08:28 -050069private:
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