blob: ddf00840ae0ac880cb43524910218b2f876f5a2b [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 Phillipsc1541ae2019-02-04 12:05:37 -050038 GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t uniqueID);
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 Phillipsc1541ae2019-02-04 12:05:37 -050049 /*
50 * The options in effect for this context
51 */
52 const GrContextOptions& options() const { return fOptions; }
53
Robert Phillipsbb606772019-02-04 17:50:57 -050054 const GrCaps* caps() const;
55 sk_sp<const GrCaps> refCaps() const;
56
57 sk_sp<GrSkSLFPFactoryCache> fpFactoryCache();
58
Robert Phillips4217ea72019-01-30 13:08:28 -050059 GrContext_Base* asBaseContext() { return this; }
60 virtual GrImageContext* asImageContext() { return nullptr; }
61 virtual GrRecordingContext* asRecordingContext() { return nullptr; }
62 virtual GrContext* asDirectContext() { return nullptr; }
63
Robert Phillipsbb606772019-02-04 17:50:57 -050064 virtual bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>);
65
Robert Phillips4217ea72019-01-30 13:08:28 -050066private:
Robert Phillipsbb606772019-02-04 17:50:57 -050067 const GrBackendApi fBackend;
68 const GrContextOptions fOptions;
69 const uint32_t fContextID;
70 sk_sp<const GrCaps> fCaps;
71 sk_sp<GrSkSLFPFactoryCache> fFPFactoryCache;
Robert Phillips4217ea72019-01-30 13:08:28 -050072
73 typedef SkRefCnt INHERITED;
74};
75
76#endif