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 | |
| 8 | #include "GrContext_Base.h" |
| 9 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 10 | #include "GrBaseContextPriv.h" |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 11 | #include "GrCaps.h" |
| 12 | #include "GrSkSLFPFactoryCache.h" |
| 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 | bool GrContext_Base::explicitlyAllocateGPUResources() const { |
Robert Phillips | 570f4e5 | 2019-03-12 12:55:30 -0400 | [diff] [blame] | 42 | #ifdef SK_OLD_STYLE_RESOURCE_ALLOCATION |
| 43 | return false; |
| 44 | #else |
| 45 | return true; |
| 46 | #endif |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | const GrCaps* GrContext_Base::caps() const { return fCaps.get(); } |
| 50 | sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; } |
| 51 | |
| 52 | sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; } |
| 53 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 54 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const { |
| 56 | return fContext->refCaps(); |
| 57 | } |
| 58 | |
| 59 | sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() { |
| 60 | return fContext->fpFactoryCache(); |
| 61 | } |