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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrContextThreadSafeProxy.h" |
| 9 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkSurfaceCharacterization.h" |
| 12 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrBaseContextPriv.h" |
| 14 | #include "src/gpu/GrCaps.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrSkSLFPFactoryCache.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/image/SkSurface_Gpu.h" |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 17 | |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 18 | #ifdef SK_VULKAN |
| 19 | #include "src/gpu/vk/GrVkCaps.h" |
| 20 | #endif |
| 21 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 22 | GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend, |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 23 | const GrContextOptions& options, |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 24 | uint32_t contextID) |
| 25 | : INHERITED(backend, options, contextID) { |
| 26 | } |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 27 | |
| 28 | GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default; |
| 29 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 30 | bool 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 Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 35 | SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization( |
| 36 | size_t cacheMaxResourceBytes, |
| 37 | const SkImageInfo& ii, const GrBackendFormat& backendFormat, |
| 38 | int sampleCnt, GrSurfaceOrigin origin, |
| 39 | const SkSurfaceProps& surfaceProps, |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 40 | bool isMipMapped, bool willUseGLFBO0, bool isTextureable, |
| 41 | GrProtected isProtected) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 42 | if (!backendFormat.isValid()) { |
| 43 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 44 | } |
| 45 | |
Robert Phillips | c046ff0 | 2019-07-01 10:34:03 -0400 | [diff] [blame] | 46 | SkASSERT(isTextureable || !isMipMapped); |
| 47 | |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 48 | 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 Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 53 | if (!this->caps()->mipMapSupport()) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 54 | isMipMapped = false; |
| 55 | } |
| 56 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 57 | if (!SkSurface_Gpu::Valid(this->caps(), backendFormat)) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 58 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 59 | } |
| 60 | |
Greg Daniel | 2f2caea | 2019-07-08 14:24:47 -0400 | [diff] [blame] | 61 | GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType()); |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 62 | |
Greg Daniel | 627d053 | 2019-07-08 16:48:14 -0400 | [diff] [blame] | 63 | if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, backendFormat)) { |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 64 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 65 | } |
| 66 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 67 | if (!this->caps()->isFormatAsColorTypeRenderable(grColorType, backendFormat, sampleCnt)) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 68 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 69 | } |
| 70 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 71 | sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendFormat); |
| 72 | SkASSERT(sampleCnt); |
| 73 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 74 | if (willUseGLFBO0 && isTextureable) { |
| 75 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 76 | } |
| 77 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 78 | if (isTextureable && !this->caps()->isFormatTexturable(backendFormat)) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 79 | // Skia doesn't agree that this is textureable. |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 80 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 81 | } |
| 82 | |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 83 | if (GrBackendApi::kVulkan == backendFormat.backend()) { |
| 84 | if (GrBackendApi::kVulkan != this->backend()) { |
| 85 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 86 | } |
| 87 | |
| 88 | #ifdef SK_VULKAN |
| 89 | const GrVkCaps* vkCaps = (const GrVkCaps*) this->caps(); |
| 90 | |
| 91 | // The protection status of the characterization and the context need to match |
| 92 | if (isProtected != GrProtected(vkCaps->supportsProtectedMemory())) { |
| 93 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 94 | } |
| 95 | #endif |
| 96 | } |
| 97 | |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 98 | return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this), |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 99 | cacheMaxResourceBytes, ii, backendFormat, |
| 100 | origin, sampleCnt, |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 101 | SkSurfaceCharacterization::Textureable(isTextureable), |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 102 | SkSurfaceCharacterization::MipMapped(isMipMapped), |
| 103 | SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0), |
| 104 | SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false), |
Robert Phillips | 3cd5432 | 2019-07-10 09:28:59 -0400 | [diff] [blame] | 105 | isProtected, |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 106 | surfaceProps); |
| 107 | } |
| 108 | |
| 109 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 110 | sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() { |
| 111 | return fProxy->fpFactoryCache(); |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 112 | } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 113 | |
| 114 | sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make( |
| 115 | GrBackendApi backend, |
| 116 | const GrContextOptions& options, |
| 117 | uint32_t contextID, |
| 118 | sk_sp<const GrCaps> caps, |
| 119 | sk_sp<GrSkSLFPFactoryCache> cache) { |
| 120 | sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options, |
| 121 | contextID)); |
| 122 | |
| 123 | if (!proxy->init(std::move(caps), std::move(cache))) { |
| 124 | return nullptr; |
| 125 | } |
| 126 | return proxy; |
| 127 | } |
| 128 | |