blob: 7af25ec9f0a7be8d75cc31a96b237c65e3b5ff56 [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"
12#include "GrTypes.h"
13
14class GrBaseContextPriv;
15class GrContext;
16class GrImageContext;
17class GrRecordingContext;
18
19class SK_API GrContext_Base : public SkRefCnt {
20public:
21 virtual ~GrContext_Base();
22
23 /*
24 * The 3D API backing this context
25 */
26 GrBackendApi backend() const { return fBackend; }
27
Robert Phillips4217ea72019-01-30 13:08:28 -050028 // Provides access to functions that aren't part of the public API.
29 GrBaseContextPriv priv();
30 const GrBaseContextPriv priv() const;
31
32protected:
33 friend class GrBaseContextPriv; // for hidden functions
34
35 GrContext_Base(GrBackendApi backend, uint32_t uniqueID);
36
Robert Phillipsfd0d9702019-02-01 10:19:42 -050037 /**
38 * An identifier for this context. The id is used by all compatible contexts. For example,
39 * if SkImages are created on one thread using an image creation context, then fed into a
40 * DDL Recorder on second thread (which has a recording context) and finally replayed on
41 * a third thread with a direct context, then all three contexts will report the same id.
42 * It is an error for an image to be used with contexts that report different ids.
43 */
44 uint32_t contextID() const { return fContextID; }
45
Robert Phillips4217ea72019-01-30 13:08:28 -050046 GrContext_Base* asBaseContext() { return this; }
47 virtual GrImageContext* asImageContext() { return nullptr; }
48 virtual GrRecordingContext* asRecordingContext() { return nullptr; }
49 virtual GrContext* asDirectContext() { return nullptr; }
50
51private:
52 const GrBackendApi fBackend;
Robert Phillipsfd0d9702019-02-01 10:19:42 -050053 const uint32_t fContextID;
Robert Phillips4217ea72019-01-30 13:08:28 -050054
55 typedef SkRefCnt INHERITED;
56};
57
58#endif