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" |
Adlai Holler | 43b1579 | 2020-06-01 10:11:49 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
Brian Osman | bd4f872 | 2020-03-06 15:23:54 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrShaderUtils.h" |
Robert Phillips | 7f11fb5 | 2019-12-03 13:35:19 -0500 | [diff] [blame] | 14 | #include "src/gpu/effects/GrSkSLFP.h" |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 15 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame^] | 16 | GrContext_Base::GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy) |
| 17 | : fThreadSafeProxy(std::move(proxy)) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 18 | } |
| 19 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 20 | GrContext_Base::~GrContext_Base() { } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 21 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame^] | 22 | bool GrContext_Base::init() { |
| 23 | SkASSERT(fThreadSafeProxy->isValid()); |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 24 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 25 | return true; |
| 26 | } |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 27 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame^] | 28 | uint32_t GrContext_Base::contextID() const { return fThreadSafeProxy->priv().contextID(); } |
| 29 | GrBackendApi GrContext_Base::backend() const { return fThreadSafeProxy->priv().backend(); } |
| 30 | |
| 31 | const GrContextOptions& GrContext_Base::options() const { |
| 32 | return fThreadSafeProxy->priv().options(); |
| 33 | } |
| 34 | |
| 35 | const GrCaps* GrContext_Base::caps() const { return fThreadSafeProxy->priv().caps(); } |
| 36 | sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fThreadSafeProxy->priv().refCaps(); } |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 37 | |
Robert Phillips | f759964 | 2019-08-13 16:16:42 -0400 | [diff] [blame] | 38 | GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType, |
| 39 | GrRenderable renderable) const { |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame^] | 40 | return fThreadSafeProxy->defaultBackendFormat(skColorType, renderable); |
Robert Phillips | f759964 | 2019-08-13 16:16:42 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 43 | GrBackendFormat GrContext_Base::compressedBackendFormat(SkImage::CompressionType c) const { |
| 44 | const GrCaps* caps = this->caps(); |
| 45 | |
| 46 | GrBackendFormat format = caps->getBackendFormatFromCompressionType(c); |
| 47 | |
| 48 | SkASSERT(!format.isValid() || caps->isFormatTexturable(format)); |
| 49 | return format; |
| 50 | } |
| 51 | |
Adlai Holler | e219d1c | 2020-06-02 11:23:16 -0400 | [diff] [blame^] | 52 | sk_sp<GrContextThreadSafeProxy> GrContext_Base::threadSafeProxy() { return fThreadSafeProxy; } |
| 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 | } |
Brian Osman | bd4f872 | 2020-03-06 15:23:54 -0500 | [diff] [blame] | 58 | |
| 59 | GrContextOptions::ShaderErrorHandler* GrBaseContextPriv::getShaderErrorHandler() const { |
| 60 | const GrContextOptions& options(this->options()); |
| 61 | return options.fShaderErrorHandler ? options.fShaderErrorHandler |
| 62 | : GrShaderUtils::DefaultShaderErrorHandler(); |
| 63 | } |