blob: 572605877ef7069344b048c24f17907f136a2665 [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;
16class GrContext;
17class GrImageContext;
18class GrRecordingContext;
19
20class SK_API GrContext_Base : public SkRefCnt {
21public:
22 virtual ~GrContext_Base();
23
24 /*
25 * The 3D API backing this context
26 */
27 GrBackendApi backend() const { return fBackend; }
28
Robert Phillips4217ea72019-01-30 13:08:28 -050029 // Provides access to functions that aren't part of the public API.
30 GrBaseContextPriv priv();
31 const GrBaseContextPriv priv() const;
32
33protected:
34 friend class GrBaseContextPriv; // for hidden functions
35
Robert Phillipsc1541ae2019-02-04 12:05:37 -050036 GrContext_Base(GrBackendApi backend, const GrContextOptions& options, uint32_t uniqueID);
Robert Phillips4217ea72019-01-30 13:08:28 -050037
Robert Phillipsfd0d9702019-02-01 10:19:42 -050038 /**
39 * An identifier for this context. The id is used by all compatible contexts. For example,
40 * if SkImages are created on one thread using an image creation context, then fed into a
41 * DDL Recorder on second thread (which has a recording context) and finally replayed on
42 * a third thread with a direct context, then all three contexts will report the same id.
43 * It is an error for an image to be used with contexts that report different ids.
44 */
45 uint32_t contextID() const { return fContextID; }
46
Robert Phillipsc1541ae2019-02-04 12:05:37 -050047 /*
48 * The options in effect for this context
49 */
50 const GrContextOptions& options() const { return fOptions; }
51
Robert Phillips4217ea72019-01-30 13:08:28 -050052 GrContext_Base* asBaseContext() { return this; }
53 virtual GrImageContext* asImageContext() { return nullptr; }
54 virtual GrRecordingContext* asRecordingContext() { return nullptr; }
55 virtual GrContext* asDirectContext() { return nullptr; }
56
57private:
Robert Phillipsc1541ae2019-02-04 12:05:37 -050058 const GrBackendApi fBackend;
59 const GrContextOptions fOptions;
60 const uint32_t fContextID;
Robert Phillips4217ea72019-01-30 13:08:28 -050061
62 typedef SkRefCnt INHERITED;
63};
64
65#endif