blob: 554fbdaa2c8d7c361c4cdf34c1f8effec2392f72 [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 Danielf91aeb22019-06-18 09:58:02 -040018#include "src/gpu/GrSkSLFPFactoryCache.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/GrTextureContext.h"
22#include "src/gpu/SkGr.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 Phillipsdbaf3172019-02-06 15:12:53 -050039sk_sp<GrSkSLFPFactoryCache> GrContextPriv::fpFactoryCache() {
40 return fContext->fpFactoryCache();
41}
42
43sk_sp<GrOpMemoryPool> GrContextPriv::refOpMemoryPool() {
Robert Phillipsd6841482019-02-08 10:29:20 -050044 return fContext->refOpMemoryPool();
Robert Phillipsdbaf3172019-02-06 15:12:53 -050045}
46
Robert Phillipsc5058a62019-02-15 12:52:59 -050047void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
48 fContext->addOnFlushCallbackObject(onFlushCBObject);
49}
50
Brian Salomone7499c72019-06-24 12:12:36 -040051sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy,
Brian Salomond6287472019-06-24 15:50:07 -040052 GrColorType colorType,
Brian Salomone7499c72019-06-24 12:12:36 -040053 SkAlphaType alphaType,
54 sk_sp<SkColorSpace> colorSpace,
55 const SkSurfaceProps* props) {
Brian Salomond6287472019-06-24 15:50:07 -040056 return fContext->makeWrappedSurfaceContext(std::move(proxy), colorType, alphaType,
57 std::move(colorSpace), props);
Robert Phillips292a6b22019-02-14 14:49:02 -050058}
59
Brian Salomon947efe22019-07-16 15:36:11 -040060sk_sp<GrTextureContext> GrContextPriv::makeDeferredTextureContext(SkBackingFit fit,
61 int width,
62 int height,
Brian Salomond6287472019-06-24 15:50:07 -040063 GrColorType colorType,
Brian Salomone7499c72019-06-24 12:12:36 -040064 SkAlphaType alphaType,
65 sk_sp<SkColorSpace> colorSpace,
Brian Salomon947efe22019-07-16 15:36:11 -040066 GrMipMapped mipMapped,
67 GrSurfaceOrigin origin,
68 SkBudgeted budgeted,
69 GrProtected isProtected) {
70 return fContext->makeDeferredTextureContext(fit, width, height, colorType, alphaType,
71 std::move(colorSpace), mipMapped, origin, budgeted,
72 isProtected);
Robert Phillips292a6b22019-02-14 14:49:02 -050073}
74
Robert Phillipsb97da532019-02-12 15:24:12 -050075sk_sp<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -040076 SkBackingFit fit,
77 int width,
78 int height,
Brian Salomond6287472019-06-24 15:50:07 -040079 GrColorType colorType,
80 sk_sp<SkColorSpace> colorSpace,
81 int sampleCnt,
82 GrMipMapped mipMapped,
83 GrSurfaceOrigin origin,
84 const SkSurfaceProps* surfaceProps,
85 SkBudgeted budgeted,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040086 GrProtected isProtected) {
Brian Salomon27ae52c2019-07-03 11:27:44 -040087 return fContext->makeDeferredRenderTargetContext(fit, width, height, colorType,
Robert Phillipsb97da532019-02-12 15:24:12 -050088 std::move(colorSpace), sampleCnt, mipMapped,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040089 origin, surfaceProps, budgeted, isProtected);
Robert Phillipsb97da532019-02-12 15:24:12 -050090}
91
Robert Phillips6f0e02f2019-02-13 11:02:28 -050092sk_sp<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContextWithFallback(
Brian Salomon27ae52c2019-07-03 11:27:44 -040093 SkBackingFit fit, int width, int height, GrColorType colorType,
94 sk_sp<SkColorSpace> colorSpace, int sampleCnt, GrMipMapped mipMapped,
95 GrSurfaceOrigin origin, const SkSurfaceProps* surfaceProps, SkBudgeted budgeted) {
Brian Salomond6287472019-06-24 15:50:07 -040096 return fContext->makeDeferredRenderTargetContextWithFallback(
Brian Salomon27ae52c2019-07-03 11:27:44 -040097 fit, width, height, colorType, std::move(colorSpace), sampleCnt, mipMapped, origin,
98 surfaceProps, budgeted);
Robert Phillips6f0e02f2019-02-13 11:02:28 -050099}
100
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500101sk_sp<GrTextureContext> GrContextPriv::makeBackendTextureContext(const GrBackendTexture& tex,
102 GrSurfaceOrigin origin,
Brian Salomond6287472019-06-24 15:50:07 -0400103 GrColorType colorType,
Brian Salomone7499c72019-06-24 12:12:36 -0400104 SkAlphaType alphaType,
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500105 sk_sp<SkColorSpace> colorSpace) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400106 ASSERT_SINGLE_OWNER
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500107
108 sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendTexture(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400109 tex, colorType, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500110 if (!proxy) {
111 return nullptr;
112 }
113
Brian Salomond6287472019-06-24 15:50:07 -0400114 return this->drawingManager()->makeTextureContext(std::move(proxy), colorType, alphaType,
Brian Salomone7499c72019-06-24 12:12:36 -0400115 std::move(colorSpace));
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500116}
117
118sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -0400119 const GrBackendTexture& tex,
120 GrSurfaceOrigin origin,
121 int sampleCnt,
122 GrColorType colorType,
123 sk_sp<SkColorSpace> colorSpace,
124 const SkSurfaceProps* props,
125 ReleaseProc releaseProc,
126 ReleaseContext releaseCtx) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400127 ASSERT_SINGLE_OWNER
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500128 SkASSERT(sampleCnt > 0);
129
130 sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture(
Robert Phillips0902c982019-07-16 07:47:56 -0400131 tex, origin, sampleCnt, colorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
132 releaseProc, releaseCtx));
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500133 if (!proxy) {
134 return nullptr;
135 }
136
Brian Salomond6287472019-06-24 15:50:07 -0400137 return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType,
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500138 std::move(colorSpace), props);
139}
140
141sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -0400142 const GrBackendRenderTarget& backendRT,
143 GrSurfaceOrigin origin,
144 GrColorType colorType,
145 sk_sp<SkColorSpace> colorSpace,
146 const SkSurfaceProps* surfaceProps,
147 ReleaseProc releaseProc,
148 ReleaseContext releaseCtx) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400149 ASSERT_SINGLE_OWNER
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500150
151 sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400152 backendRT, colorType, origin, releaseProc, releaseCtx);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500153 if (!proxy) {
154 return nullptr;
155 }
156
Brian Salomond6287472019-06-24 15:50:07 -0400157 return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType,
158 std::move(colorSpace), surfaceProps);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500159}
160
161sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext(
Brian Salomond6287472019-06-24 15:50:07 -0400162 const GrBackendTexture& tex,
163 GrSurfaceOrigin origin,
164 int sampleCnt,
165 GrColorType colorType,
166 sk_sp<SkColorSpace> colorSpace,
167 const SkSurfaceProps* props) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400168 ASSERT_SINGLE_OWNER
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500169 SkASSERT(sampleCnt > 0);
170 sk_sp<GrSurfaceProxy> proxy(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400171 this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, colorType,
172 origin, sampleCnt));
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500173 if (!proxy) {
174 return nullptr;
175 }
176
Brian Salomond6287472019-06-24 15:50:07 -0400177 return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType,
178 std::move(colorSpace), props);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500179}
180
181sk_sp<GrRenderTargetContext> GrContextPriv::makeVulkanSecondaryCBRenderTargetContext(
182 const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo, const SkSurfaceProps* props) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400183 ASSERT_SINGLE_OWNER
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500184 sk_sp<GrSurfaceProxy> proxy(
185 this->proxyProvider()->wrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo));
186 if (!proxy) {
187 return nullptr;
188 }
189
Brian Salomond6287472019-06-24 15:50:07 -0400190 return this->drawingManager()->makeRenderTargetContext(
191 std::move(proxy),
192 SkColorTypeToGrColorType(imageInfo.colorType()),
193 imageInfo.refColorSpace(),
194 props);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500195}
196
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400197GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies,
198 const GrFlushInfo& info) {
199 ASSERT_SINGLE_OWNER
200 RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo)
201 GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "flushSurfaces", fContext);
202 SkASSERT(numProxies >= 0);
203 SkASSERT(!numProxies || proxies);
204 for (int i = 0; i < numProxies; ++i) {
205 SkASSERT(proxies[i]);
206 ASSERT_OWNED_PROXY(proxies[i]);
207 }
208 return fContext->drawingManager()->flushSurfaces(
209 proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500210}
211
Brian Salomon693bc2b2019-05-09 13:48:00 +0000212void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400213 this->flushSurfaces(proxy ? &proxy : nullptr, proxy ? 1 : 0, {});
Brian Salomon693bc2b2019-05-09 13:48:00 +0000214}
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500215
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500216void GrContextPriv::moveOpListsToDDL(SkDeferredDisplayList* ddl) {
Robert Phillips292a6b22019-02-14 14:49:02 -0500217 fContext->drawingManager()->moveOpListsToDDL(ddl);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500218}
219
220void GrContextPriv::copyOpListsFromDDL(const SkDeferredDisplayList* ddl,
221 GrRenderTargetProxy* newDest) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500222 fContext->drawingManager()->copyOpListsFromDDL(ddl, newDest);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500223}
224
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500225//////////////////////////////////////////////////////////////////////////////
226#ifdef SK_ENABLE_DUMP_GPU
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500227#include "src/utils/SkJSONWriter.h"
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500228SkString GrContextPriv::dump() const {
229 SkDynamicMemoryWStream stream;
230 SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
231 writer.beginObject();
232
233 static const char* kBackendStr[] = {
234 "Metal",
Stephen White985741a2019-07-18 11:43:45 -0400235 "Dawn",
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500236 "OpenGL",
237 "Vulkan",
238 "Mock",
239 };
240 GR_STATIC_ASSERT(0 == (unsigned)GrBackendApi::kMetal);
Stephen White985741a2019-07-18 11:43:45 -0400241 GR_STATIC_ASSERT(1 == (unsigned)GrBackendApi::kDawn);
242 GR_STATIC_ASSERT(2 == (unsigned)GrBackendApi::kOpenGL);
243 GR_STATIC_ASSERT(3 == (unsigned)GrBackendApi::kVulkan);
244 GR_STATIC_ASSERT(4 == (unsigned)GrBackendApi::kMock);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500245 writer.appendString("backend", kBackendStr[(unsigned)fContext->backend()]);
246
247 writer.appendName("caps");
248 fContext->caps()->dumpJSON(&writer);
249
250 writer.appendName("gpu");
251 fContext->fGpu->dumpJSON(&writer);
252
253 // Flush JSON to the memory stream
254 writer.endObject();
255 writer.flush();
256
257 // Null terminate the JSON data in the memory stream
258 stream.write8(0);
259
260 // Allocate a string big enough to hold all the data, then copy out of the stream
261 SkString result(stream.bytesWritten());
262 stream.copyToAndReset(result.writable_str());
263 return result;
264}
265#endif
266
267#if GR_TEST_UTILS
268void GrContextPriv::resetGpuStats() const {
269#if GR_GPU_STATS
270 fContext->fGpu->stats()->reset();
271#endif
272}
273
274void GrContextPriv::dumpCacheStats(SkString* out) const {
275#if GR_CACHE_STATS
276 fContext->fResourceCache->dumpStats(out);
277#endif
278}
279
280void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys,
281 SkTArray<double>* values) const {
282#if GR_CACHE_STATS
283 fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values);
284#endif
285}
286
287void GrContextPriv::printCacheStats() const {
288 SkString out;
289 this->dumpCacheStats(&out);
290 SkDebugf("%s", out.c_str());
291}
292
293void GrContextPriv::dumpGpuStats(SkString* out) const {
294#if GR_GPU_STATS
295 return fContext->fGpu->stats()->dump(out);
296#endif
297}
298
299void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys,
300 SkTArray<double>* values) const {
301#if GR_GPU_STATS
302 return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values);
303#endif
304}
305
306void GrContextPriv::printGpuStats() const {
307 SkString out;
308 this->dumpGpuStats(&out);
309 SkDebugf("%s", out.c_str());
310}
311
312void GrContextPriv::testingOnly_setTextBlobCacheLimit(size_t bytes) {
Robert Phillips2184fb72019-02-21 16:11:41 -0500313 fContext->priv().getTextBlobCache()->setBudget(bytes);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500314}
315
316sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index) {
317 auto atlasManager = this->getAtlasManager();
318 if (!atlasManager) {
319 return nullptr;
320 }
321
322 unsigned int numActiveProxies;
323 const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies);
324 if (index >= numActiveProxies || !proxies || !proxies[index]) {
325 return nullptr;
326 }
327
328 SkASSERT(proxies[index]->priv().isExact());
329 sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID,
330 kPremul_SkAlphaType, proxies[index], nullptr));
331 return image;
332}
333
334void GrContextPriv::testingOnly_purgeAllUnlockedResources() {
335 fContext->fResourceCache->purgeAllUnlocked();
336}
337
338void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
339 fContext->flush();
Robert Phillips292a6b22019-02-14 14:49:02 -0500340 fContext->drawingManager()->testingOnly_removeOnFlushCallbackObject(cb);
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500341}
342#endif
Greg Daniel6eb8c242019-06-05 10:22:24 -0400343
344bool GrContextPriv::validPMUPMConversionExists() {
345 ASSERT_SINGLE_OWNER
346 if (!fContext->fDidTestPMConversions) {
347 fContext->fPMUPMConversionsRoundTrip =
348 GrConfigConversionEffect::TestForPreservingPMConversions(fContext);
349 fContext->fDidTestPMConversions = true;
350 }
351
352 // The PM<->UPM tests fail or succeed together so we only need to check one.
353 return fContext->fPMUPMConversionsRoundTrip;
354}
355
356std::unique_ptr<GrFragmentProcessor> GrContextPriv::createPMToUPMEffect(
357 std::unique_ptr<GrFragmentProcessor> fp) {
358 ASSERT_SINGLE_OWNER
359 // We should have already called this->priv().validPMUPMConversionExists() in this case
360 SkASSERT(fContext->fDidTestPMConversions);
361 // ...and it should have succeeded
362 SkASSERT(this->validPMUPMConversionExists());
363
364 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
365}
366
367std::unique_ptr<GrFragmentProcessor> GrContextPriv::createUPMToPMEffect(
368 std::unique_ptr<GrFragmentProcessor> fp) {
369 ASSERT_SINGLE_OWNER
370 // We should have already called this->priv().validPMUPMConversionExists() in this case
371 SkASSERT(fContext->fDidTestPMConversions);
372 // ...and it should have succeeded
373 SkASSERT(this->validPMUPMConversionExists());
374
375 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
376}
Robert Phillipscb1adb42019-06-10 15:09:34 -0400377
378//////////////////////////////////////////////////////////////////////////////
379
380#include "src/core/SkMipMap.h"
381
382GrBackendTexture GrContextPriv::createBackendTexture(const SkPixmap srcData[], int numLevels,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400383 GrRenderable renderable,
384 GrProtected isProtected) {
Robert Phillipscb1adb42019-06-10 15:09:34 -0400385 if (!fContext->asDirectContext()) {
386 return {};
387 }
388
389 if (this->abandoned()) {
390 return {};
391 }
392
393 if (!srcData || !numLevels) {
394 return {};
395 }
396
397 int baseWidth = srcData[0].width();
398 int baseHeight = srcData[0].height();
399 SkColorType colorType = srcData[0].colorType();
400
401 if (numLevels > 1) {
402 if (numLevels != SkMipMap::ComputeLevelCount(baseWidth, baseHeight) + 1) {
403 return {};
404 }
405
406 int currentWidth = baseWidth;
407 int currentHeight = baseHeight;
408 for (int i = 1; i < numLevels; ++i) {
409 currentWidth = SkTMax(1, currentWidth / 2);
410 currentHeight = SkTMax(1, currentHeight / 2);
411
412 if (srcData[i].colorType() != colorType) {
413 return {};
414 }
415
416 if (srcData[i].width() != currentWidth || srcData[i].height() != currentHeight) {
417 return {};
418 }
419 }
420 }
421
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400422 GrBackendFormat backendFormat = fContext->defaultBackendFormat(colorType, renderable);
Robert Phillipscb1adb42019-06-10 15:09:34 -0400423 if (!backendFormat.isValid()) {
424 return {};
425 }
426
427 GrGpu* gpu = fContext->fGpu.get();
428
429 // TODO: propagate the array of pixmaps interface to GrGpu
430 return gpu->createBackendTexture(baseWidth, baseHeight, backendFormat,
431 GrMipMapped::kNo, // TODO: use real mipmap setting here
432 renderable, srcData[0].addr(), srcData[0].rowBytes(),
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400433 nullptr, isProtected);
Robert Phillipscb1adb42019-06-10 15:09:34 -0400434}