blob: c62f5610ba1ae915746688c641383c945d292d93 [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"
Robert Phillips7f11fb52019-12-03 13:35:19 -050012#include "src/gpu/effects/GrSkSLFP.h"
Robert Phillipsbb606772019-02-04 17:50:57 -050013
Robert Phillips4217ea72019-01-30 13:08:28 -050014static 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
23GrContext_Base::GrContext_Base(GrBackendApi backend,
Robert Phillipsc1541ae2019-02-04 12:05:37 -050024 const GrContextOptions& options,
Robert Phillipsfd0d9702019-02-01 10:19:42 -050025 uint32_t contextID)
Robert Phillips4217ea72019-01-30 13:08:28 -050026 : fBackend(backend)
Robert Phillipsc1541ae2019-02-04 12:05:37 -050027 , fOptions(options)
Robert Phillipsfd0d9702019-02-01 10:19:42 -050028 , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
Robert Phillips4217ea72019-01-30 13:08:28 -050029}
30
Robert Phillipsc1541ae2019-02-04 12:05:37 -050031GrContext_Base::~GrContext_Base() { }
Robert Phillips4217ea72019-01-30 13:08:28 -050032
Brian Osman7b1678a2019-12-16 09:17:25 -050033bool GrContext_Base::init(sk_sp<const GrCaps> caps) {
34 SkASSERT(caps);
Robert Phillipsbb606772019-02-04 17:50:57 -050035
36 fCaps = caps;
Robert Phillipsbb606772019-02-04 17:50:57 -050037 return true;
38}
Robert Phillips4217ea72019-01-30 13:08:28 -050039
Robert Phillips292a6b22019-02-14 14:49:02 -050040const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
41sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
42
Robert Phillipsf7599642019-08-13 16:16:42 -040043GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType,
44 GrRenderable renderable) const {
45 const GrCaps* caps = this->caps();
46
47 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
48
49 GrBackendFormat format = caps->getDefaultBackendFormat(grColorType, renderable);
50 if (!format.isValid()) {
51 return GrBackendFormat();
52 }
53
Greg Daniel7bfc9132019-08-14 14:23:53 -040054 SkASSERT(caps->isFormatTexturableAndUploadable(grColorType, format));
Robert Phillipsf7599642019-08-13 16:16:42 -040055 SkASSERT(renderable == GrRenderable::kNo ||
56 caps->isFormatAsColorTypeRenderable(grColorType, format));
57
58 return format;
59}
60
Robert Phillipsa41c6852019-02-07 10:44:10 -050061///////////////////////////////////////////////////////////////////////////////////////////////////
62sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
63 return fContext->refCaps();
64}