blob: 64c7bf6a4ca67a043b4842beb246f7d7d724485f [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/image/SkSurface_Gpu.h"
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050017
Robert Phillips3cd54322019-07-10 09:28:59 -040018#ifdef SK_VULKAN
19#include "src/gpu/vk/GrVkCaps.h"
20#endif
21
Robert Phillipsbb606772019-02-04 17:50:57 -050022GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend,
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050023 const GrContextOptions& options,
Robert Phillipsbb606772019-02-04 17:50:57 -050024 uint32_t contextID)
25 : INHERITED(backend, options, contextID) {
26}
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050027
28GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
29
Robert Phillipsbb606772019-02-04 17:50:57 -050030bool GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
31 sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
32 return INHERITED::init(std::move(caps), std::move(FPFactoryCache));
33}
34
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050035SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
36 size_t cacheMaxResourceBytes,
37 const SkImageInfo& ii, const GrBackendFormat& backendFormat,
38 int sampleCnt, GrSurfaceOrigin origin,
39 const SkSurfaceProps& surfaceProps,
Robert Phillips3cd54322019-07-10 09:28:59 -040040 bool isMipMapped, bool willUseGLFBO0, bool isTextureable,
41 GrProtected isProtected) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050042 if (!backendFormat.isValid()) {
43 return SkSurfaceCharacterization(); // return an invalid characterization
44 }
45
Robert Phillipsc046ff02019-07-01 10:34:03 -040046 SkASSERT(isTextureable || !isMipMapped);
47
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050048 if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
49 // The willUseGLFBO0 flags can only be used for a GL backend.
50 return SkSurfaceCharacterization(); // return an invalid characterization
51 }
52
Robert Phillipsbb606772019-02-04 17:50:57 -050053 if (!this->caps()->mipMapSupport()) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050054 isMipMapped = false;
55 }
56
Greg Daniel2f2caea2019-07-08 14:24:47 -040057 GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
Robert Phillipsb2adbef2019-07-02 16:33:05 -040058
Greg Daniel627d0532019-07-08 16:48:14 -040059 if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, backendFormat)) {
Robert Phillipsb2adbef2019-07-02 16:33:05 -040060 return SkSurfaceCharacterization(); // return an invalid characterization
61 }
62
Greg Daniel6fa62e22019-08-07 15:52:37 -040063 if (!this->caps()->isFormatAsColorTypeRenderable(grColorType, backendFormat, sampleCnt)) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050064 return SkSurfaceCharacterization(); // return an invalid characterization
65 }
66
Greg Daniel6fa62e22019-08-07 15:52:37 -040067 sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendFormat);
68 SkASSERT(sampleCnt);
69
Robert Phillipsb45f47d2019-02-03 17:17:54 -050070 if (willUseGLFBO0 && isTextureable) {
71 return SkSurfaceCharacterization(); // return an invalid characterization
72 }
73
Greg Daniel7bfc9132019-08-14 14:23:53 -040074 if (isTextureable && !this->caps()->isFormatTexturable(backendFormat)) {
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
Robert Phillips3cd54322019-07-10 09:28:59 -040079 if (GrBackendApi::kVulkan == backendFormat.backend()) {
80 if (GrBackendApi::kVulkan != this->backend()) {
81 return SkSurfaceCharacterization(); // return an invalid characterization
82 }
83
84#ifdef SK_VULKAN
85 const GrVkCaps* vkCaps = (const GrVkCaps*) this->caps();
86
87 // The protection status of the characterization and the context need to match
88 if (isProtected != GrProtected(vkCaps->supportsProtectedMemory())) {
89 return SkSurfaceCharacterization(); // return an invalid characterization
90 }
91#endif
92 }
93
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050094 return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
Robert Phillipsb2adbef2019-07-02 16:33:05 -040095 cacheMaxResourceBytes, ii, backendFormat,
96 origin, sampleCnt,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050097 SkSurfaceCharacterization::Textureable(isTextureable),
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050098 SkSurfaceCharacterization::MipMapped(isMipMapped),
99 SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
100 SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
Robert Phillips3cd54322019-07-10 09:28:59 -0400101 isProtected,
Robert Phillipsa0bc39d2019-01-29 13:14:47 -0500102 surfaceProps);
103}
104
105////////////////////////////////////////////////////////////////////////////////
Robert Phillipsbb606772019-02-04 17:50:57 -0500106sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
107 return fProxy->fpFactoryCache();
Robert Phillipsa0bc39d2019-01-29 13:14:47 -0500108}
Robert Phillipsbb606772019-02-04 17:50:57 -0500109
110sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
111 GrBackendApi backend,
112 const GrContextOptions& options,
113 uint32_t contextID,
114 sk_sp<const GrCaps> caps,
115 sk_sp<GrSkSLFPFactoryCache> cache) {
116 sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
117 contextID));
118
119 if (!proxy->init(std::move(caps), std::move(cache))) {
120 return nullptr;
121 }
122 return proxy;
123}
124