xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrContext_Base.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/gpu/ganesh/GrContext_Base.h"
9 
10 #include "include/gpu/ganesh/GrBackendSurface.h"
11 #include "include/gpu/ganesh/GrContextOptions.h"
12 #include "include/gpu/ganesh/GrContextThreadSafeProxy.h"
13 #include "include/gpu/ShaderErrorHandler.h"
14 #include "include/private/base/SkAssert.h"
15 #include "src/gpu/ganesh/GrBaseContextPriv.h"
16 #include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h"
17 
18 #include <utility>
19 
20 enum SkColorType : int;
21 
GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy)22 GrContext_Base::GrContext_Base(sk_sp<GrContextThreadSafeProxy> proxy)
23         : fThreadSafeProxy(std::move(proxy)) {
24 }
25 
~GrContext_Base()26 GrContext_Base::~GrContext_Base() { }
27 
init()28 bool GrContext_Base::init() {
29     SkASSERT(fThreadSafeProxy->isValid());
30 
31     return true;
32 }
33 
contextID() const34 uint32_t GrContext_Base::contextID() const { return fThreadSafeProxy->priv().contextID(); }
backend() const35 GrBackendApi GrContext_Base::backend() const { return fThreadSafeProxy->priv().backend(); }
36 
options() const37 const GrContextOptions& GrContext_Base::options() const {
38     return fThreadSafeProxy->priv().options();
39 }
40 
caps() const41 const GrCaps* GrContext_Base::caps() const { return fThreadSafeProxy->priv().caps(); }
refCaps() const42 sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fThreadSafeProxy->priv().refCaps(); }
43 
defaultBackendFormat(SkColorType skColorType,GrRenderable renderable) const44 GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
45                                                      GrRenderable renderable) const {
46     return fThreadSafeProxy->defaultBackendFormat(skColorType, renderable);
47 }
48 
compressedBackendFormat(SkTextureCompressionType c) const49 GrBackendFormat GrContext_Base::compressedBackendFormat(SkTextureCompressionType c) const {
50     return fThreadSafeProxy->compressedBackendFormat(c);
51 }
52 
maxSurfaceSampleCountForColorType(SkColorType colorType) const53 int GrContext_Base::maxSurfaceSampleCountForColorType(SkColorType colorType) const {
54     return fThreadSafeProxy->maxSurfaceSampleCountForColorType(colorType);
55 }
56 
threadSafeProxy()57 sk_sp<GrContextThreadSafeProxy> GrContext_Base::threadSafeProxy() { return fThreadSafeProxy; }
58 
59 ///////////////////////////////////////////////////////////////////////////////////////////////////
refCaps() const60 sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
61     return this->context()->refCaps();
62 }
63 
getShaderErrorHandler() const64 GrContextOptions::ShaderErrorHandler* GrBaseContextPriv::getShaderErrorHandler() const {
65     const GrContextOptions& options(this->options());
66     return options.fShaderErrorHandler ? options.fShaderErrorHandler
67                                        : skgpu::DefaultShaderErrorHandler();
68 }
69