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 | 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 | |
Robert Phillips | c046ff0 | 2019-07-01 10:34:03 -0400 | [diff] [blame] | 41 | SkASSERT(isTextureable || !isMipMapped); |
| 42 | |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 43 | if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) { |
| 44 | // The willUseGLFBO0 flags can only be used for a GL backend. |
| 45 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 46 | } |
| 47 | |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 48 | if (!this->caps()->mipMapSupport()) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 49 | isMipMapped = false; |
| 50 | } |
| 51 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 52 | if (!SkSurface_Gpu::Valid(this->caps(), backendFormat)) { |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 53 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 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 | |
| 58 | if (!this->caps()->areColorTypeAndFormatCompatible(ii.colorType(), backendFormat)) { |
| 59 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 60 | } |
| 61 | |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 62 | sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, ii.colorType(), backendFormat); |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 63 | if (!sampleCnt) { |
| 64 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 65 | } |
| 66 | |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 67 | if (willUseGLFBO0 && isTextureable) { |
| 68 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 69 | } |
| 70 | |
Greg Daniel | 2f2caea | 2019-07-08 14:24:47 -0400 | [diff] [blame^] | 71 | if (isTextureable && !this->caps()->isFormatTexturable(grColorType, backendFormat)) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 72 | // Skia doesn't agree that this is textureable. |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 73 | return SkSurfaceCharacterization(); // return an invalid characterization |
| 74 | } |
| 75 | |
| 76 | return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this), |
Robert Phillips | b2adbef | 2019-07-02 16:33:05 -0400 | [diff] [blame] | 77 | cacheMaxResourceBytes, ii, backendFormat, |
| 78 | origin, sampleCnt, |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 79 | SkSurfaceCharacterization::Textureable(isTextureable), |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 80 | SkSurfaceCharacterization::MipMapped(isMipMapped), |
| 81 | SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0), |
| 82 | SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false), |
| 83 | surfaceProps); |
| 84 | } |
| 85 | |
| 86 | //////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 87 | sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() { |
| 88 | return fProxy->fpFactoryCache(); |
Robert Phillips | a0bc39d | 2019-01-29 13:14:47 -0500 | [diff] [blame] | 89 | } |
Robert Phillips | bb60677 | 2019-02-04 17:50:57 -0500 | [diff] [blame] | 90 | |
| 91 | sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make( |
| 92 | GrBackendApi backend, |
| 93 | const GrContextOptions& options, |
| 94 | uint32_t contextID, |
| 95 | sk_sp<const GrCaps> caps, |
| 96 | sk_sp<GrSkSLFPFactoryCache> cache) { |
| 97 | sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options, |
| 98 | contextID)); |
| 99 | |
| 100 | if (!proxy->init(std::move(caps), std::move(cache))) { |
| 101 | return nullptr; |
| 102 | } |
| 103 | return proxy; |
| 104 | } |
| 105 | |