blob: 8bf5afbc884e30c892c9cc3ceac635c222a8c3d1 [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 Phillipsbb606772019-02-04 17:50:57 -050018GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend,
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050019 const GrContextOptions& options,
Robert Phillipsbb606772019-02-04 17:50:57 -050020 uint32_t contextID)
21 : INHERITED(backend, options, contextID) {
22}
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050023
24GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
25
Robert Phillipsbb606772019-02-04 17:50:57 -050026bool 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 Phillipsa0bc39d2019-01-29 13:14:47 -050031SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
32 size_t cacheMaxResourceBytes,
33 const SkImageInfo& ii, const GrBackendFormat& backendFormat,
34 int sampleCnt, GrSurfaceOrigin origin,
35 const SkSurfaceProps& surfaceProps,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050036 bool isMipMapped, bool willUseGLFBO0, bool isTextureable) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050037 if (!backendFormat.isValid()) {
38 return SkSurfaceCharacterization(); // return an invalid characterization
39 }
40
Robert Phillipsc046ff02019-07-01 10:34:03 -040041 SkASSERT(isTextureable || !isMipMapped);
42
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050043 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 Phillipsbb606772019-02-04 17:50:57 -050048 if (!this->caps()->mipMapSupport()) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050049 isMipMapped = false;
50 }
51
Robert Phillipsf209e882019-06-25 15:59:50 -040052 if (!SkSurface_Gpu::Valid(this->caps(), backendFormat)) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050053 return SkSurfaceCharacterization(); // return an invalid characterization
54 }
55
Robert Phillipsd8f79a22019-06-24 13:25:42 -040056 sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, ii.colorType(), backendFormat);
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050057 if (!sampleCnt) {
58 return SkSurfaceCharacterization(); // return an invalid characterization
59 }
60
Robert Phillipsb45f47d2019-02-03 17:17:54 -050061 if (willUseGLFBO0 && isTextureable) {
62 return SkSurfaceCharacterization(); // return an invalid characterization
63 }
64
Robert Phillipsd8f79a22019-06-24 13:25:42 -040065 if (isTextureable && !this->caps()->isFormatTexturable(ii.colorType(), backendFormat)) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -050066 // Skia doesn't agree that this is textureable.
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050067 return SkSurfaceCharacterization(); // return an invalid characterization
68 }
69
Robert Phillipsf209e882019-06-25 15:59:50 -040070 GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, ii.colorType());
71 if (kUnknown_GrPixelConfig == config) {
72 return SkSurfaceCharacterization(); // return an invalid characterization
73 }
74
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050075 return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
76 cacheMaxResourceBytes, ii,
Chris Dalton6ce447a2019-06-23 18:07:38 -060077 origin, config, sampleCnt,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050078 SkSurfaceCharacterization::Textureable(isTextureable),
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050079 SkSurfaceCharacterization::MipMapped(isMipMapped),
80 SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
81 SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
82 surfaceProps);
83}
84
85////////////////////////////////////////////////////////////////////////////////
Robert Phillipsbb606772019-02-04 17:50:57 -050086sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
87 return fProxy->fpFactoryCache();
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050088}
Robert Phillipsbb606772019-02-04 17:50:57 -050089
90sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
91 GrBackendApi backend,
92 const GrContextOptions& options,
93 uint32_t contextID,
94 sk_sp<const GrCaps> caps,
95 sk_sp<GrSkSLFPFactoryCache> cache) {
96 sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
97 contextID));
98
99 if (!proxy->init(std::move(caps), std::move(cache))) {
100 return nullptr;
101 }
102 return proxy;
103}
104