blob: 7fd443bde6c7b58bb76cca93f7c2464df2237815 [file] [log] [blame]
Robert Phillipsdbaf3172019-02-06 15:12:53 -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 "src/gpu/GrContextPriv.h"
Robert Phillipsdbaf3172019-02-06 15:12:53 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/gpu/GrContextThreadSafeProxy.h"
11#include "include/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040012#include "src/gpu/GrAuditTrail.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrContextThreadSafeProxyPriv.h"
14#include "src/gpu/GrDrawingManager.h"
15#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrMemoryPool.h"
17#include "src/gpu/GrRenderTargetContext.h"
Greg Daniel46e366a2019-12-16 14:38:36 -050018#include "src/gpu/GrSurfaceContext.h"
Greg Daniel46cfbc62019-06-07 11:43:30 -040019#include "src/gpu/GrSurfaceContextPriv.h"
Mike Klein4b432fa2019-06-06 11:44:05 -050020#include "src/gpu/GrSurfacePriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050021#include "src/gpu/SkGr.h"
Robert Phillips7f11fb52019-12-03 13:35:19 -050022#include "src/gpu/effects/GrSkSLFP.h"
Greg Daniel6eb8c242019-06-05 10:22:24 -040023#include "src/gpu/effects/generated/GrConfigConversionEffect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/text/GrTextBlobCache.h"
25#include "src/image/SkImage_Base.h"
26#include "src/image/SkImage_Gpu.h"
Robert Phillipsdbaf3172019-02-06 15:12:53 -050027
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040028#define ASSERT_OWNED_PROXY(P) \
Robert Phillipsdbaf3172019-02-06 15:12:53 -050029 SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == fContext)
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040030#define ASSERT_SINGLE_OWNER \
Robert Phillipsa41c6852019-02-07 10:44:10 -050031 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->singleOwner());)
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040032#define RETURN_VALUE_IF_ABANDONED(value) if (fContext->abandoned()) { return (value); }
33#define RETURN_IF_ABANDONED RETURN_VALUE_IF_ABANDONED(void)
Robert Phillipsdbaf3172019-02-06 15:12:53 -050034
Robert Phillipsa41c6852019-02-07 10:44:10 -050035sk_sp<const GrCaps> GrContextPriv::refCaps() const {
36 return fContext->refCaps();
37}
38
Robert Phillipsc5058a62019-02-15 12:52:59 -050039void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
40 fContext->addOnFlushCallbackObject(onFlushCBObject);
41}
42
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040043GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
44 const GrFlushInfo& info) {
45 ASSERT_SINGLE_OWNER
46 RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo)
47 GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "flushSurfaces", fContext);
48 SkASSERT(numProxies >= 0);
49 SkASSERT(!numProxies || proxies);
50 for (int i = 0; i < numProxies; ++i) {
51 SkASSERT(proxies[i]);
52 ASSERT_OWNED_PROXY(proxies[i]);
53 }
54 return fContext->drawingManager()->flushSurfaces(
55 proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info);
Robert Phillipsdbaf3172019-02-06 15:12:53 -050056}
57
Brian Salomon693bc2b2019-05-09 13:48:00 +000058void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -040059 this->flushSurfaces(proxy ? &proxy : nullptr, proxy ? 1 : 0, {});
Brian Salomon693bc2b2019-05-09 13:48:00 +000060}
Robert Phillipsdbaf3172019-02-06 15:12:53 -050061
Chris Dalton6b498102019-08-01 14:14:52 -060062void GrContextPriv::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
63 fContext->drawingManager()->moveRenderTasksToDDL(ddl);
Robert Phillipsdbaf3172019-02-06 15:12:53 -050064}
65
Chris Dalton6b498102019-08-01 14:14:52 -060066void GrContextPriv::copyRenderTasksFromDDL(const SkDeferredDisplayList* ddl,
67 GrRenderTargetProxy* newDest) {
68 fContext->drawingManager()->copyRenderTasksFromDDL(ddl, newDest);
Robert Phillipsdbaf3172019-02-06 15:12:53 -050069}
70
Robert Phillipsdbaf3172019-02-06 15:12:53 -050071//////////////////////////////////////////////////////////////////////////////
Robert Phillipsdbaf3172019-02-06 15:12:53 -050072
73#if GR_TEST_UTILS
74void GrContextPriv::resetGpuStats() const {
75#if GR_GPU_STATS
76 fContext->fGpu->stats()->reset();
77#endif
78}
79
80void GrContextPriv::dumpCacheStats(SkString* out) const {
81#if GR_CACHE_STATS
82 fContext->fResourceCache->dumpStats(out);
83#endif
84}
85
86void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
87 SkTArray<double>* values) const {
88#if GR_CACHE_STATS
89 fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values);
90#endif
91}
92
93void GrContextPriv::printCacheStats() const {
94 SkString out;
95 this->dumpCacheStats(&out);
96 SkDebugf("%s", out.c_str());
97}
98
99void GrContextPriv::dumpGpuStats(SkString* out) const {
100#if GR_GPU_STATS
101 return fContext->fGpu->stats()->dump(out);
102#endif
103}
104
105void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
106 SkTArray<double>* values) const {
107#if GR_GPU_STATS
108 return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values);
109#endif
110}
111
112void GrContextPriv::printGpuStats() const {
113 SkString out;
114 this->dumpGpuStats(&out);
115 SkDebugf("%s", out.c_str());
116}
117
118void GrContextPriv::testingOnly_setTextBlobCacheLimit(size_t bytes) {
Robert Phillips2184fb72019-02-21 16:11:41 -0500119 fContext->priv().getTextBlobCache()->setBudget(bytes);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500120}
121
122sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index) {
123 auto atlasManager = this->getAtlasManager();
124 if (!atlasManager) {
125 return nullptr;
126 }
127
128 unsigned int numActiveProxies;
Greg Daniel9715b6c2019-12-10 15:03:10 -0500129 const GrSurfaceProxyView* views = atlasManager->getViews(format, &numActiveProxies);
130 if (index >= numActiveProxies || !views || !views[index].proxy()) {
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500131 return nullptr;
132 }
133
Greg Daniel9715b6c2019-12-10 15:03:10 -0500134 SkASSERT(views[index].proxy()->priv().isExact());
Brian Salomon729fc0c2019-09-30 16:33:11 +0000135 sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
Ben Wagner aka dogben9ed88b32020-01-21 22:24:00 +0000136 kPremul_SkAlphaType, views[index], nullptr));
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500137 return image;
138}
139
140void GrContextPriv::testingOnly_purgeAllUnlockedResources() {
141 fContext->fResourceCache->purgeAllUnlocked();
142}
143
144void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
145 fContext->flush();
Robert Phillips292a6b22019-02-14 14:49:02 -0500146 fContext->drawingManager()->testingOnly_removeOnFlushCallbackObject(cb);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500147}
148#endif
Greg Daniel6eb8c242019-06-05 10:22:24 -0400149
150bool GrContextPriv::validPMUPMConversionExists() {
151 ASSERT_SINGLE_OWNER
152 if (!fContext->fDidTestPMConversions) {
153 fContext->fPMUPMConversionsRoundTrip =
154 GrConfigConversionEffect::TestForPreservingPMConversions(fContext);
155 fContext->fDidTestPMConversions = true;
156 }
157
158 // The PM<->UPM tests fail or succeed together so we only need to check one.
159 return fContext->fPMUPMConversionsRoundTrip;
160}
161
162std::unique_ptr<GrFragmentProcessor> GrContextPriv::createPMToUPMEffect(
163 std::unique_ptr<GrFragmentProcessor> fp) {
164 ASSERT_SINGLE_OWNER
165 // We should have already called this->priv().validPMUPMConversionExists() in this case
166 SkASSERT(fContext->fDidTestPMConversions);
167 // ...and it should have succeeded
168 SkASSERT(this->validPMUPMConversionExists());
169
170 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
171}
172
173std::unique_ptr<GrFragmentProcessor> GrContextPriv::createUPMToPMEffect(
174 std::unique_ptr<GrFragmentProcessor> fp) {
175 ASSERT_SINGLE_OWNER
176 // We should have already called this->priv().validPMUPMConversionExists() in this case
177 SkASSERT(fContext->fDidTestPMConversions);
178 // ...and it should have succeeded
179 SkASSERT(this->validPMUPMConversionExists());
180
181 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
182}