blob: 34262997f02072fd333253d2d820a204fadb0fec [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/private/GrContext_Base.h"
Robert Phillips4217ea72019-01-30 13:08:28 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrBaseContextPriv.h"
11#include "src/gpu/GrCaps.h"
Adlai Holler43b15792020-06-01 10:11:49 -040012#include "src/gpu/GrContextThreadSafeProxyPriv.h"
Brian Osmanbd4f8722020-03-06 15:23:54 -050013#include "src/gpu/GrShaderUtils.h"
Robert Phillips7f11fb52019-12-03 13:35:19 -050014#include "src/gpu/effects/GrSkSLFP.h"
Robert Phillipsbb606772019-02-04 17:50:57 -050015
Adlai Hollere219d1c2020-06-02 11:23:16 -040016GrContext_Base::GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy)
17 : fThreadSafeProxy(std::move(proxy)) {
Robert Phillips4217ea72019-01-30 13:08:28 -050018}
19
Robert Phillipsc1541ae2019-02-04 12:05:37 -050020GrContext_Base::~GrContext_Base() { }
Robert Phillips4217ea72019-01-30 13:08:28 -050021
Adlai Hollere219d1c2020-06-02 11:23:16 -040022bool GrContext_Base::init() {
23 SkASSERT(fThreadSafeProxy->isValid());
Robert Phillipsbb606772019-02-04 17:50:57 -050024
Robert Phillipsbb606772019-02-04 17:50:57 -050025 return true;
26}
Robert Phillips4217ea72019-01-30 13:08:28 -050027
Adlai Hollere219d1c2020-06-02 11:23:16 -040028uint32_t GrContext_Base::contextID() const { return fThreadSafeProxy->priv().contextID(); }
29GrBackendApi GrContext_Base::backend() const { return fThreadSafeProxy->priv().backend(); }
30
31const GrContextOptions& GrContext_Base::options() const {
32 return fThreadSafeProxy->priv().options();
33}
34
35const GrCaps* GrContext_Base::caps() const { return fThreadSafeProxy->priv().caps(); }
36sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fThreadSafeProxy->priv().refCaps(); }
Robert Phillips292a6b22019-02-14 14:49:02 -050037
Robert Phillipsf7599642019-08-13 16:16:42 -040038GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
39 GrRenderable renderable) const {
Adlai Hollere219d1c2020-06-02 11:23:16 -040040 return fThreadSafeProxy->defaultBackendFormat(skColorType, renderable);
Robert Phillipsf7599642019-08-13 16:16:42 -040041}
42
Robert Phillipsb915c942019-12-17 14:44:37 -050043GrBackendFormat 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 Hollere219d1c2020-06-02 11:23:16 -040052sk_sp<GrContextThreadSafeProxy> GrContext_Base::threadSafeProxy() { return fThreadSafeProxy; }
53
Robert Phillipsa41c6852019-02-07 10:44:10 -050054///////////////////////////////////////////////////////////////////////////////////////////////////
55sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
56 return fContext->refCaps();
57}
Brian Osmanbd4f8722020-03-06 15:23:54 -050058
59GrContextOptions::ShaderErrorHandler* GrBaseContextPriv::getShaderErrorHandler() const {
60 const GrContextOptions& options(this->options());
61 return options.fShaderErrorHandler ? options.fShaderErrorHandler
62 : GrShaderUtils::DefaultShaderErrorHandler();
63}