• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GrSkSLFPFactoryCache.h"
13 
next_id()14 static int32_t next_id() {
15     static std::atomic<int32_t> nextID{1};
16     int32_t id;
17     do {
18         id = nextID++;
19     } while (id == SK_InvalidGenID);
20     return id;
21 }
22 
GrContext_Base(GrBackendApi backend,const GrContextOptions & options,uint32_t contextID)23 GrContext_Base::GrContext_Base(GrBackendApi backend,
24                                const GrContextOptions& options,
25                                uint32_t contextID)
26         : fBackend(backend)
27         , fOptions(options)
28         , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
29 }
30 
~GrContext_Base()31 GrContext_Base::~GrContext_Base() { }
32 
init(sk_sp<const GrCaps> caps,sk_sp<GrSkSLFPFactoryCache> FPFactoryCache)33 bool GrContext_Base::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
34     SkASSERT(caps && FPFactoryCache);
35 
36     fCaps = caps;
37     fFPFactoryCache = FPFactoryCache;
38     return true;
39 }
40 
caps() const41 const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
refCaps() const42 sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
43 
fpFactoryCache()44 sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; }
45 
defaultBackendFormat(SkColorType skColorType,GrRenderable renderable) const46 GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
47                                                      GrRenderable renderable) const {
48     const GrCaps* caps = this->caps();
49 
50     GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
51 
52     GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable);
53     if (!format.isValid()) {
54         return GrBackendFormat();
55     }
56 
57     SkASSERT(caps->isFormatTexturableAndUploadable(grColorType, format));
58     SkASSERT(renderable == GrRenderable::kNo ||
59              caps->isFormatAsColorTypeRenderable(grColorType, format));
60 
61     return format;
62 }
63 
64 ///////////////////////////////////////////////////////////////////////////////////////////////////
refCaps() const65 sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
66     return fContext->refCaps();
67 }
68 
fpFactoryCache()69 sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() {
70     return fContext->fpFactoryCache();
71 }
72