blob: 826867f55cd0d34ce3032da701674a7c3f7e0fc6 [file] [log] [blame]
Robert Phillipsa0bc39d2019-01-29 13:14:47 -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
8#include "GrContextThreadSafeProxy.h"
9#include "GrContextThreadSafeProxyPriv.h"
10
Robert Phillipsfd0d9702019-02-01 10:19:42 -050011#include "GrBaseContextPriv.h"
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050012#include "GrCaps.h"
13#include "GrContext.h"
14#include "GrSkSLFPFactoryCache.h"
15#include "SkSurface_Gpu.h"
16#include "SkSurfaceCharacterization.h"
17
Robert Phillipsbb606772019-02-04 17:50:57 -050018GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend,
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050019 const GrContextOptions& options,
Robert Phillipsbb606772019-02-04 17:50:57 -050020 uint32_t contextID)
21 : INHERITED(backend, options, contextID) {
22}
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050023
24GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
25
Robert Phillipsbb606772019-02-04 17:50:57 -050026bool GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
27 sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
28 return INHERITED::init(std::move(caps), std::move(FPFactoryCache));
29}
30
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050031SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
32 size_t cacheMaxResourceBytes,
33 const SkImageInfo& ii, const GrBackendFormat& backendFormat,
34 int sampleCnt, GrSurfaceOrigin origin,
35 const SkSurfaceProps& surfaceProps,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050036 bool isMipMapped, bool willUseGLFBO0, bool isTextureable) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050037 if (!backendFormat.isValid()) {
38 return SkSurfaceCharacterization(); // return an invalid characterization
39 }
40
41 if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
42 // The willUseGLFBO0 flags can only be used for a GL backend.
43 return SkSurfaceCharacterization(); // return an invalid characterization
44 }
45
Robert Phillipsbb606772019-02-04 17:50:57 -050046 if (!this->caps()->mipMapSupport()) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050047 isMipMapped = false;
48 }
49
Robert Phillipsbb606772019-02-04 17:50:57 -050050 GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, ii.colorType());
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050051 if (config == kUnknown_GrPixelConfig) {
52 return SkSurfaceCharacterization(); // return an invalid characterization
53 }
54
Robert Phillipsbb606772019-02-04 17:50:57 -050055 if (!SkSurface_Gpu::Valid(this->caps(), config, ii.colorSpace())) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050056 return SkSurfaceCharacterization(); // return an invalid characterization
57 }
58
Robert Phillipsbb606772019-02-04 17:50:57 -050059 sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, config);
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050060 if (!sampleCnt) {
61 return SkSurfaceCharacterization(); // return an invalid characterization
62 }
63
64 GrFSAAType FSAAType = GrFSAAType::kNone;
65 if (sampleCnt > 1) {
Robert Phillipsbb606772019-02-04 17:50:57 -050066 FSAAType = this->caps()->usesMixedSamples() ? GrFSAAType::kMixedSamples
67 : GrFSAAType::kUnifiedMSAA;
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050068 }
69
Robert Phillipsb45f47d2019-02-03 17:17:54 -050070 if (willUseGLFBO0 && isTextureable) {
71 return SkSurfaceCharacterization(); // return an invalid characterization
72 }
73
Robert Phillipsbb606772019-02-04 17:50:57 -050074 if (isTextureable && !this->caps()->isConfigTexturable(config)) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -050075 // Skia doesn't agree that this is textureable.
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050076 return SkSurfaceCharacterization(); // return an invalid characterization
77 }
78
79 return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
80 cacheMaxResourceBytes, ii,
81 origin, config, FSAAType, sampleCnt,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050082 SkSurfaceCharacterization::Textureable(isTextureable),
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050083 SkSurfaceCharacterization::MipMapped(isMipMapped),
84 SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
85 SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
86 surfaceProps);
87}
88
89////////////////////////////////////////////////////////////////////////////////
Robert Phillipsbb606772019-02-04 17:50:57 -050090sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
91 return fProxy->fpFactoryCache();
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050092}
Robert Phillipsbb606772019-02-04 17:50:57 -050093
94sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
95 GrBackendApi backend,
96 const GrContextOptions& options,
97 uint32_t contextID,
98 sk_sp<const GrCaps> caps,
99 sk_sp<GrSkSLFPFactoryCache> cache) {
100 sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
101 contextID));
102
103 if (!proxy->init(std::move(caps), std::move(cache))) {
104 return nullptr;
105 }
106 return proxy;
107}
108