blob: 920d6fbbbb1ecb6ee87658947c15a6b1ee47e875 [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
Greg Daniel2f2caea2019-07-08 14:24:47 -040056 GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
Robert Phillipsb2adbef2019-07-02 16:33:05 -040057
58 if (!this->caps()->areColorTypeAndFormatCompatible(ii.colorType(), backendFormat)) {
59 return SkSurfaceCharacterization(); // return an invalid characterization
60 }
61
Robert Phillipsd8f79a22019-06-24 13:25:42 -040062 sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, ii.colorType(), backendFormat);
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050063 if (!sampleCnt) {
64 return SkSurfaceCharacterization(); // return an invalid characterization
65 }
66
Robert Phillipsb45f47d2019-02-03 17:17:54 -050067 if (willUseGLFBO0 && isTextureable) {
68 return SkSurfaceCharacterization(); // return an invalid characterization
69 }
70
Greg Daniel2f2caea2019-07-08 14:24:47 -040071 if (isTextureable && !this->caps()->isFormatTexturable(grColorType, backendFormat)) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -050072 // Skia doesn't agree that this is textureable.
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050073 return SkSurfaceCharacterization(); // return an invalid characterization
74 }
75
76 return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
Robert Phillipsb2adbef2019-07-02 16:33:05 -040077 cacheMaxResourceBytes, ii, backendFormat,
78 origin, sampleCnt,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050079 SkSurfaceCharacterization::Textureable(isTextureable),
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050080 SkSurfaceCharacterization::MipMapped(isMipMapped),
81 SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
82 SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
83 surfaceProps);
84}
85
86////////////////////////////////////////////////////////////////////////////////
Robert Phillipsbb606772019-02-04 17:50:57 -050087sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
88 return fProxy->fpFactoryCache();
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050089}
Robert Phillipsbb606772019-02-04 17:50:57 -050090
91sk_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