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