blob: 3d194a0aeafe496367e35dba8f821e0052765845 [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#include "GrContext_Base.h"
9
Robert Phillipsa41c6852019-02-07 10:44:10 -050010#include "GrBaseContextPriv.h"
Robert Phillipsbb606772019-02-04 17:50:57 -050011#include "GrCaps.h"
12#include "GrSkSLFPFactoryCache.h"
13
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 -050041bool GrContext_Base::explicitlyAllocateGPUResources() const {
Robert Phillips570f4e52019-03-12 12:55:30 -040042#ifdef SK_OLD_STYLE_RESOURCE_ALLOCATION
43 return false;
44#else
45 return true;
46#endif
Robert Phillips292a6b22019-02-14 14:49:02 -050047}
48
49const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
50sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
51
52sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; }
53
Robert Phillipsa41c6852019-02-07 10:44:10 -050054///////////////////////////////////////////////////////////////////////////////////////////////////
55sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
56 return fContext->refCaps();
57}
58
59sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() {
60 return fContext->fpFactoryCache();
61}