blob: 8da3afe9e9332d44a8f4fd43104f5e1c48226f47 [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
41 if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
42 // The willUseGLFBO0 flags can only be used for a GL backend.
43 return SkSurfaceCharacterization(); // return an invalid characterization
44 }
45
Robert Phillipsbb606772019-02-04 17:50:57 -050046 if (!this->caps()->mipMapSupport()) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050047 isMipMapped = false;
48 }
49
Robert Phillipsf209e882019-06-25 15:59:50 -040050 if (!SkSurface_Gpu::Valid(this->caps(), backendFormat)) {
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050051 return SkSurfaceCharacterization(); // return an invalid characterization
52 }
53
Robert Phillipsd8f79a22019-06-24 13:25:42 -040054 sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, ii.colorType(), backendFormat);
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050055 if (!sampleCnt) {
56 return SkSurfaceCharacterization(); // return an invalid characterization
57 }
58
Robert Phillipsb45f47d2019-02-03 17:17:54 -050059 if (willUseGLFBO0 && isTextureable) {
60 return SkSurfaceCharacterization(); // return an invalid characterization
61 }
62
Robert Phillipsd8f79a22019-06-24 13:25:42 -040063 if (isTextureable && !this->caps()->isFormatTexturable(ii.colorType(), backendFormat)) {
Robert Phillipsb45f47d2019-02-03 17:17:54 -050064 // Skia doesn't agree that this is textureable.
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050065 return SkSurfaceCharacterization(); // return an invalid characterization
66 }
67
Robert Phillipsf209e882019-06-25 15:59:50 -040068 GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, ii.colorType());
69 if (kUnknown_GrPixelConfig == config) {
70 return SkSurfaceCharacterization(); // return an invalid characterization
71 }
72
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050073 return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
74 cacheMaxResourceBytes, ii,
Chris Dalton6ce447a2019-06-23 18:07:38 -060075 origin, config, sampleCnt,
Robert Phillipsb45f47d2019-02-03 17:17:54 -050076 SkSurfaceCharacterization::Textureable(isTextureable),
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050077 SkSurfaceCharacterization::MipMapped(isMipMapped),
78 SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
79 SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
80 surfaceProps);
81}
82
83////////////////////////////////////////////////////////////////////////////////
Robert Phillipsbb606772019-02-04 17:50:57 -050084sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
85 return fProxy->fpFactoryCache();
Robert Phillipsa0bc39d2019-01-29 13:14:47 -050086}
Robert Phillipsbb606772019-02-04 17:50:57 -050087
88sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
89 GrBackendApi backend,
90 const GrContextOptions& options,
91 uint32_t contextID,
92 sk_sp<const GrCaps> caps,
93 sk_sp<GrSkSLFPFactoryCache> cache) {
94 sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
95 contextID));
96
97 if (!proxy->init(std::move(caps), std::move(cache))) {
98 return nullptr;
99 }
100 return proxy;
101}
102