Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/GrContext_Base.h" |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrBaseContextPriv.h" |
| 11 | #include "src/gpu/GrCaps.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame^] | 12 | #include "src/gpu/GrSkSLFPFactoryCache.h" |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 13 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 14 | static 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 | |
| 23 | GrContext_Base::GrContext_Base(GrBackendApi backend, |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 24 | const GrContextOptions& options, |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 25 | uint32_t contextID) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 26 | : fBackend(backend) |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 27 | , fOptions(options) |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 28 | , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 29 | } |
| 30 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 31 | GrContext_Base::~GrContext_Base() { } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 32 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 33 | bool 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 Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 40 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 41 | const GrCaps* GrContext_Base::caps() const { return fCaps.get(); } |
| 42 | sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; } |
| 43 | |
| 44 | sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; } |
| 45 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 46 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const { |
| 48 | return fContext->refCaps(); |
| 49 | } |
| 50 | |
| 51 | sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() { |
| 52 | return fContext->fpFactoryCache(); |
| 53 | } |