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 "include/private/GrContext_Base.h" 9 10 #include "src/gpu/GrBaseContextPriv.h" 11 #include "src/gpu/GrCaps.h" 12 #include "src/gpu/GrContextThreadSafeProxyPriv.h" 13 #include "src/gpu/GrShaderUtils.h" 14 #include "src/gpu/effects/GrSkSLFP.h" 15 GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy)16GrContext_Base::GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy) 17 : fThreadSafeProxy(std::move(proxy)) { 18 } 19 ~GrContext_Base()20GrContext_Base::~GrContext_Base() { } 21 init()22bool GrContext_Base::init() { 23 SkASSERT(fThreadSafeProxy->isValid()); 24 25 return true; 26 } 27 contextID() const28uint32_t GrContext_Base::contextID() const { return fThreadSafeProxy->priv().contextID(); } backend() const29GrBackendApi GrContext_Base::backend() const { return fThreadSafeProxy->priv().backend(); } 30 options() const31const GrContextOptions& GrContext_Base::options() const { 32 return fThreadSafeProxy->priv().options(); 33 } 34 caps() const35const GrCaps* GrContext_Base::caps() const { return fThreadSafeProxy->priv().caps(); } refCaps() const36sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fThreadSafeProxy->priv().refCaps(); } 37 defaultBackendFormat(SkColorType skColorType,GrRenderable renderable) const38GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType, 39 GrRenderable renderable) const { 40 return fThreadSafeProxy->defaultBackendFormat(skColorType, renderable); 41 } 42 compressedBackendFormat(SkImage::CompressionType c) const43GrBackendFormat 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 threadSafeProxy()52sk_sp<GrContextThreadSafeProxy> GrContext_Base::threadSafeProxy() { return fThreadSafeProxy; } 53 54 /////////////////////////////////////////////////////////////////////////////////////////////////// refCaps() const55sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const { 56 return fContext->refCaps(); 57 } 58 getShaderErrorHandler() const59GrContextOptions::ShaderErrorHandler* GrBaseContextPriv::getShaderErrorHandler() const { 60 const GrContextOptions& options(this->options()); 61 return options.fShaderErrorHandler ? options.fShaderErrorHandler 62 : GrShaderUtils::DefaultShaderErrorHandler(); 63 } 64