blob: f7d3f77e4fa6a43d9deaa87dad58298e1ac40ac9 [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"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrSkSLFPFactoryCache.h"
Robert Phillips7f11fb52019-12-03 13:35:19 -050013#include "src/gpu/effects/GrSkSLFP.h"
Robert Phillipsbb606772019-02-04 17:50:57 -050014
Robert Phillips4217ea72019-01-30 13:08:28 -050015static int32_t next_id() {
16 static std::atomic<int32_t> nextID{1};
17 int32_t id;
18 do {
19 id = nextID++;
20 } while (id == SK_InvalidGenID);
21 return id;
22}
23
24GrContext_Base::GrContext_Base(GrBackendApi backend,
Robert Phillipsc1541ae2019-02-04 12:05:37 -050025 const GrContextOptions& options,
Robert Phillipsfd0d9702019-02-01 10:19:42 -050026 uint32_t contextID)
Robert Phillips4217ea72019-01-30 13:08:28 -050027 : fBackend(backend)
Robert Phillipsc1541ae2019-02-04 12:05:37 -050028 , fOptions(options)
Robert Phillipsfd0d9702019-02-01 10:19:42 -050029 , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
Robert Phillips4217ea72019-01-30 13:08:28 -050030}
31
Robert Phillipsc1541ae2019-02-04 12:05:37 -050032GrContext_Base::~GrContext_Base() { }
Robert Phillips4217ea72019-01-30 13:08:28 -050033
Robert Phillipsbb606772019-02-04 17:50:57 -050034bool GrContext_Base::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
35 SkASSERT(caps && FPFactoryCache);
36
37 fCaps = caps;
38 fFPFactoryCache = FPFactoryCache;
39 return true;
40}
Robert Phillips4217ea72019-01-30 13:08:28 -050041
Robert Phillips292a6b22019-02-14 14:49:02 -050042const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
43sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
44
45sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; }
46
Robert Phillipsf7599642019-08-13 16:16:42 -040047GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
48 GrRenderable renderable) const {
49 const GrCaps* caps = this->caps();
50
51 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
52
53 GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable);
54 if (!format.isValid()) {
55 return GrBackendFormat();
56 }
57
Greg Daniel7bfc9132019-08-14 14:23:53 -040058 SkASSERT(caps->isFormatTexturableAndUploadable(grColorType, format));
Robert Phillipsf7599642019-08-13 16:16:42 -040059 SkASSERT(renderable == GrRenderable::kNo ||
60 caps->isFormatAsColorTypeRenderable(grColorType, format));
61
62 return format;
63}
64
Robert Phillipsa41c6852019-02-07 10:44:10 -050065///////////////////////////////////////////////////////////////////////////////////////////////////
66sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
67 return fContext->refCaps();
68}
69
70sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() {
71 return fContext->fpFactoryCache();
72}