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 | 7f11fb5 | 2019-12-03 13:35:19 -0500 | [diff] [blame] | 13 | #include "src/gpu/effects/GrSkSLFP.h" |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 14 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 15 | static int32_t next_id() { |
| 16 | static std::atomic<int32_t> nextID{1}; |
| 17 | int32_t id; |
| 18 | do { |
| 19 | id = nextID++; |
| 20 | } while (id == SK_InvalidGenID); |
| 21 | return id; |
| 22 | } |
| 23 | |
| 24 | GrContext_Base::GrContext_Base(GrBackendApi backend, |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 25 | const GrContextOptions& options, |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 26 | uint32_t contextID) |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 27 | : fBackend(backend) |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 28 | , fOptions(options) |
Robert Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 29 | , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 32 | GrContext_Base::~GrContext_Base() { } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 33 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 34 | bool GrContext_Base::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) { |
| 35 | SkASSERT(caps && FPFactoryCache); |
| 36 | |
| 37 | fCaps = caps; |
| 38 | fFPFactoryCache = FPFactoryCache; |
| 39 | return true; |
| 40 | } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 41 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 42 | const GrCaps* GrContext_Base::caps() const { return fCaps.get(); } |
| 43 | sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; } |
| 44 | |
| 45 | sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; } |
| 46 | |
Robert Phillips | f759964 | 2019-08-13 16:16:42 -0400 | [diff] [blame] | 47 | GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType, |
| 48 | GrRenderable renderable) const { |
| 49 | const GrCaps* caps = this->caps(); |
| 50 | |
| 51 | GrColorType grColorType = SkColorTypeToGrColorType(skColorType); |
| 52 | |
| 53 | GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable); |
| 54 | if (!format.isValid()) { |
| 55 | return GrBackendFormat(); |
| 56 | } |
| 57 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 58 | SkASSERT(caps->isFormatTexturableAndUploadable(grColorType, format)); |
Robert Phillips | f759964 | 2019-08-13 16:16:42 -0400 | [diff] [blame] | 59 | SkASSERT(renderable == GrRenderable::kNo || |
| 60 | caps->isFormatAsColorTypeRenderable(grColorType, format)); |
| 61 | |
| 62 | return format; |
| 63 | } |
| 64 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 65 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 66 | sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const { |
| 67 | return fContext->refCaps(); |
| 68 | } |
| 69 | |
| 70 | sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() { |
| 71 | return fContext->fpFactoryCache(); |
| 72 | } |