blob: 6fe042d4edfe8d7fc75a112be82da407afe7bac5 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/gpu/GrContextThreadSafeProxy.h"
9#include "src/gpu/GrContextThreadSafeProxyPriv.h"
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkSurfaceCharacterization.h"
12#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrBaseContextPriv.h"
14#include "src/gpu/GrCaps.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040015#include "src/gpu/GrSkSLFPFactoryCache.h"
Robert Phillips7f11fb52019-12-03 13:35:19 -050016#include "src/gpu/effects/GrSkSLFP.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/image/SkSurface_Gpu.h"
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050018
Robert Phillips3cd54322019-07-10 09:28:59 -040019#ifdef SK_VULKAN
20#include "src/gpu/vk/GrVkCaps.h"
21#endif
22
Robert Phillipsbb606772019-02-04 17:50:57 -050023GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend,
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050024 const GrContextOptions& options,
Robert Phillipsbb606772019-02-04 17:50:57 -050025 uint32_t contextID)
26 : INHERITED(backend, options, contextID) {
27}
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050028
29GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
30
Robert Phillipsbb606772019-02-04 17:50:57 -050031bool GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
32 sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
33 return INHERITED::init(std::move(caps), std::move(FPFactoryCache));
34}
35
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050036SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
37 size_t cacheMaxResourceBytes,
38 const SkImageInfo& ii, const GrBackendFormat& backendFormat,
39 int sampleCnt, GrSurfaceOrigin origin,
40 const SkSurfaceProps& surfaceProps,
Robert Phillips3cd54322019-07-10 09:28:59 -040041 bool isMipMapped, bool willUseGLFBO0, bool isTextureable,
42 GrProtected isProtected) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050043 if (!backendFormat.isValid()) {
44 return SkSurfaceCharacterization(); // return an invalid characterization
45 }
46
Robert Phillipsc046ff02019-07-01 10:34:03 -040047 SkASSERT(isTextureable || !isMipMapped);
48
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050049 if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
50 // The willUseGLFBO0 flags can only be used for a GL backend.
51 return SkSurfaceCharacterization(); // return an invalid characterization
52 }
53
Robert Phillipsbb606772019-02-04 17:50:57 -050054 if (!this->caps()->mipMapSupport()) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050055 isMipMapped = false;
56 }
57
Greg Daniel2f2caea2019-07-08 14:24:47 -040058 GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
Robert Phillipsb2adbef2019-07-02 16:33:05 -040059
Greg Daniel627d0532019-07-08 16:48:14 -040060 if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, backendFormat)) {
Robert Phillipsb2adbef2019-07-02 16:33:05 -040061 return SkSurfaceCharacterization(); // return an invalid characterization
62 }
63
Greg Daniel6fa62e22019-08-07 15:52:37 -040064 if (!this->caps()->isFormatAsColorTypeRenderable(grColorType, backendFormat, sampleCnt)) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050065 return SkSurfaceCharacterization(); // return an invalid characterization
66 }
67
Greg Daniel6fa62e22019-08-07 15:52:37 -040068 sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendFormat);
69 SkASSERT(sampleCnt);
70
Robert Phillipsb45f47d2019-02-03 17:17:54 -050071 if (willUseGLFBO0 && isTextureable) {
72 return SkSurfaceCharacterization(); // return an invalid characterization
73 }
74
Greg Daniel7bfc9132019-08-14 14:23:53 -040075 if (isTextureable && !this->caps()->isFormatTexturable(backendFormat)) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -050076 // Skia doesn't agree that this is textureable.
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050077 return SkSurfaceCharacterization(); // return an invalid characterization
78 }
79
Robert Phillips3cd54322019-07-10 09:28:59 -040080 if (GrBackendApi::kVulkan == backendFormat.backend()) {
81 if (GrBackendApi::kVulkan != this->backend()) {
82 return SkSurfaceCharacterization(); // return an invalid characterization
83 }
84
85#ifdef SK_VULKAN
86 const GrVkCaps* vkCaps = (const GrVkCaps*) this->caps();
87
88 // The protection status of the characterization and the context need to match
89 if (isProtected != GrProtected(vkCaps->supportsProtectedMemory())) {
90 return SkSurfaceCharacterization(); // return an invalid characterization
91 }
92#endif
93 }
94
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050095 return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
Robert Phillipsb2adbef2019-07-02 16:33:05 -040096 cacheMaxResourceBytes, ii, backendFormat,
97 origin, sampleCnt,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050098 SkSurfaceCharacterization::Textureable(isTextureable),
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050099 SkSurfaceCharacterization::MipMapped(isMipMapped),
100 SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
101 SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
Robert Phillips3cd54322019-07-10 09:28:59 -0400102 isProtected,
Robert Phillipsa0bc39d2019-01-29 13:14:47 -0500103 surfaceProps);
104}
105
106////////////////////////////////////////////////////////////////////////////////
Robert Phillipsbb606772019-02-04 17:50:57 -0500107sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
108 return fProxy->fpFactoryCache();
Robert Phillipsa0bc39d2019-01-29 13:14:47 -0500109}
Robert Phillipsbb606772019-02-04 17:50:57 -0500110
111sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
112 GrBackendApi backend,
113 const GrContextOptions& options,
114 uint32_t contextID,
115 sk_sp<const GrCaps> caps,
116 sk_sp<GrSkSLFPFactoryCache> cache) {
117 sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
118 contextID));
119
120 if (!proxy->init(std::move(caps), std::move(cache))) {
121 return nullptr;
122 }
123 return proxy;
124}
125