blob: 31e7ff126bfd4315d9786e092a89c02c3042401c [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/GrContext_Base.h"
Robert Phillips4217ea72019-01-30 13:08:28 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrBaseContextPriv.h"
11#include "src/gpu/GrCaps.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrSkSLFPFactoryCache.h"
Robert Phillipsbb606772019-02-04 17:50:57 -050013
Robert Phillips4217ea72019-01-30 13:08:28 -050014static int32_t next_id() {
15 static std::atomic<int32_t> nextID{1};
16 int32_t id;
17 do {
18 id = nextID++;
19 } while (id == SK_InvalidGenID);
20 return id;
21}
22
23GrContext_Base::GrContext_Base(GrBackendApi backend,
Robert Phillipsc1541ae2019-02-04 12:05:37 -050024 const GrContextOptions& options,
Robert Phillipsfd0d9702019-02-01 10:19:42 -050025 uint32_t contextID)
Robert Phillips4217ea72019-01-30 13:08:28 -050026 : fBackend(backend)
Robert Phillipsc1541ae2019-02-04 12:05:37 -050027 , fOptions(options)
Robert Phillipsfd0d9702019-02-01 10:19:42 -050028 , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
Robert Phillips4217ea72019-01-30 13:08:28 -050029}
30
Robert Phillipsc1541ae2019-02-04 12:05:37 -050031GrContext_Base::~GrContext_Base() { }
Robert Phillips4217ea72019-01-30 13:08:28 -050032
Robert Phillipsbb606772019-02-04 17:50:57 -050033bool GrContext_Base::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
34 SkASSERT(caps && FPFactoryCache);
35
36 fCaps = caps;
37 fFPFactoryCache = FPFactoryCache;
38 return true;
39}
Robert Phillips4217ea72019-01-30 13:08:28 -050040
Robert Phillips292a6b22019-02-14 14:49:02 -050041const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
42sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
43
44sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; }
45
Robert Phillipsa41c6852019-02-07 10:44:10 -050046///////////////////////////////////////////////////////////////////////////////////////////////////
47sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
48 return fContext->refCaps();
49}
50
51sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() {
52 return fContext->fpFactoryCache();
53}