Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 1 | /* |
| 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 Phillips | fd0d970 | 2019-02-01 10:19:42 -0500 | [diff] [blame] | 11 | #include "GrBaseContextPriv.h" |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 12 | #include "GrCaps.h" |
| 13 | #include "GrContext.h" |
| 14 | #include "GrSkSLFPFactoryCache.h" |
| 15 | #include "SkSurface_Gpu.h" |
| 16 | #include "SkSurfaceCharacterization.h" |
| 17 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 18 | GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend, |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 19 | const GrContextOptions& options, |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 20 | uint32_t contextID) |
| 21 | : INHERITED(backend, options, contextID) { |
| 22 | } |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 23 | |
| 24 | GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default; |
| 25 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 26 | bool 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 Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 31 | SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization( |
| 32 | size_t cacheMaxResourceBytes, |
| 33 | const SkImageInfo& ii, const GrBackendFormat& backendFormat, |
| 34 | int sampleCnt, GrSurfaceOrigin origin, |
| 35 | const SkSurfaceProps& surfaceProps, |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 36 | bool isMipMapped, bool willUseGLFBO0, bool isTextureable) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 37 | 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 Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 46 | if (!this->caps()->mipMapSupport()) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 47 | isMipMapped = false; |
| 48 | } |
| 49 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 50 | GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, ii.colorType()); |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 51 | if (config == kUnknown_GrPixelConfig) { |
| 52 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 53 | } |
| 54 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 55 | if (!SkSurface_Gpu::Valid(this->caps(), config, ii.colorSpace())) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 56 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 57 | } |
| 58 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 59 | sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, config); |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 60 | if (!sampleCnt) { |
| 61 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 62 | } |
| 63 | |
| 64 | GrFSAAType FSAAType = GrFSAAType::kNone; |
| 65 | if (sampleCnt > 1) { |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 66 | FSAAType = this->caps()->usesMixedSamples() ? GrFSAAType::kMixedSamples |
| 67 | : GrFSAAType::kUnifiedMSAA; |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 70 | if (willUseGLFBO0 && isTextureable) { |
| 71 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 72 | } |
| 73 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 74 | if (isTextureable && !this->caps()->isConfigTexturable(config)) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 75 | // Skia doesn't agree that this is textureable. |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 76 | 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 Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 82 | SkSurfaceCharacterization::Textureable(isTextureable), |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 83 | SkSurfaceCharacterization::MipMapped(isMipMapped), |
| 84 | SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0), |
| 85 | SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false), |
| 86 | surfaceProps); |
| 87 | } |
| 88 | |
| 89 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 90 | sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() { |
| 91 | return fProxy->fpFactoryCache(); |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 92 | } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 93 | |
| 94 | sk_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 | |