OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
9 #include "GrCaps.h" | 9 #include "GrCaps.h" |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 size_t fRowBytes; | 334 size_t fRowBytes; |
335 int fColorTableCnt; | 335 int fColorTableCnt; |
336 uint32_t* fColorTableData; | 336 uint32_t* fColorTableData; |
337 }; | 337 }; |
338 Data fData; | 338 Data fData; |
339 | 339 |
340 friend class SkImage; | 340 friend class SkImage; |
341 }; | 341 }; |
342 | 342 |
343 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y, | 343 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y, |
344 const DeferredTextureImageUsageParam s[], | 344 const DeferredTextureImageUsageParam s params[], |
345 int paramCnt, void* buffer) const { | 345 int paramCnt, void* buffer) const { |
346 // Extract relevant min/max values from the params array. | |
347 int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; | |
348 SkFilterQuality highestFilterQuality = params[0].fQuality; | |
349 for (int i = 1; i < paramCnt; ++i) { | |
350 if (lowestPreScaleMipLevel > params[i].fPreScaleMipLevel) | |
351 lowestPreScaleMipLevel = params[i].fPreScaleMipLevel; | |
352 if (highestFilterQuality < params[i].fQuality) | |
353 highestFilterQuality = params[i].fQuality; | |
354 } | |
355 | |
346 const bool fillMode = SkToBool(buffer); | 356 const bool fillMode = SkToBool(buffer); |
347 if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) { | 357 if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) { |
348 return 0; | 358 return 0; |
349 } | 359 } |
350 | 360 |
361 // Calculate scaling parameters. | |
362 const int scaleDivisor = powf(2.0f, lowestPreScaleMipLevel); | |
bsalomon
2016/05/26 13:12:54
1 << lowestPrecaleMipLevel?
Should we do some sor
ericrk
2016/06/09 19:46:05
Using the helper function that now exists in SkMip
| |
363 const bool isScaled = scaleDivisor != 1; | |
364 const int scaledWidth = this->width() / scaleDivisor; | |
bsalomon
2016/05/26 13:12:54
I think this should probably be consistent with th
ericrk
2016/06/09 19:46:05
Cblume added one, using it now.
| |
365 const int scaledHeight = this->height() / scaleDivisor; | |
366 // We never want to scale at higher than SW medium quality, as SW medium mat ches GPU high. | |
367 SkFilterQuality scaleFilterQuality = highestFilterQuality; | |
368 if (scaleFilterQuality > kMedium_SkFilterQuality) { | |
369 scaleFilterQuality = kMedium_SkFilterQuality; | |
370 } | |
371 | |
351 const int maxTextureSize = proxy.fCaps->maxTextureSize(); | 372 const int maxTextureSize = proxy.fCaps->maxTextureSize(); |
352 if (width() > maxTextureSize || height() > maxTextureSize) { | 373 if (scaledWidth > maxTextureSize || scaledHeight > maxTextureSize) { |
353 return 0; | 374 return 0; |
354 } | 375 } |
355 | 376 |
356 SkAutoPixmapStorage pixmap; | 377 SkAutoPixmapStorage pixmap; |
357 SkImageInfo info; | 378 SkImageInfo info; |
358 size_t pixelSize = 0; | 379 size_t pixelSize = 0; |
359 size_t ctSize = 0; | 380 size_t ctSize = 0; |
360 int ctCount = 0; | 381 int ctCount = 0; |
361 if (this->peekPixels(&pixmap)) { | 382 if (!isScaled && this->peekPixels(&pixmap)) { |
362 info = pixmap.info(); | 383 info = pixmap.info(); |
363 pixelSize = SkAlign8(pixmap.getSafeSize()); | 384 pixelSize = SkAlign8(pixmap.getSafeSize()); |
364 if (pixmap.ctable()) { | 385 if (pixmap.ctable()) { |
365 ctCount = pixmap.ctable()->count(); | 386 ctCount = pixmap.ctable()->count(); |
366 ctSize = SkAlign8(pixmap.ctable()->count() * 4); | 387 ctSize = SkAlign8(pixmap.ctable()->count() * 4); |
367 } | 388 } |
368 } else { | 389 } else { |
369 // Here we're just using presence of data to know whether there is a cod ec behind the image. | 390 // Here we're just using presence of data to know whether there is a cod ec behind the image. |
370 // In the future we will access the cacherator and get the exact data th at we want to (e.g. | 391 // In the future we will access the cacherator and get the exact data th at we want to (e.g. |
371 // yuv planes) upload. | 392 // yuv planes) upload. |
372 SkAutoTUnref<SkData> data(this->refEncoded()); | 393 SkAutoTUnref<SkData> data(this->refEncoded()); |
373 if (!data) { | 394 if (!data && !this->peekPixels(nullptr)) { |
374 return 0; | 395 return 0; |
375 } | 396 } |
376 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlph aType; | 397 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlph aType; |
377 info = SkImageInfo::MakeN32(this->width(), this->height(), at); | 398 info = SkImageInfo::MakeN32(scaledWidth, scaledHeight, at); |
378 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); | 399 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); |
379 if (fillMode) { | 400 if (fillMode) { |
380 pixmap.alloc(info); | 401 pixmap.alloc(info); |
381 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHint)) { | 402 if (isScaled) { |
382 return 0; | 403 if (!this->scalePixels(pixmap, scaleFilterQuality, |
404 SkImage::kDisallow_CachingHint)) { | |
405 return 0; | |
406 } | |
407 } else { | |
408 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHi nt)) { | |
409 return 0; | |
410 } | |
383 } | 411 } |
384 SkASSERT(!pixmap.ctable()); | 412 SkASSERT(!pixmap.ctable()); |
385 } | 413 } |
386 } | 414 } |
387 size_t size = 0; | 415 size_t size = 0; |
388 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); | 416 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); |
389 size += dtiSize; | 417 size += dtiSize; |
390 size_t pixelOffset = size; | 418 size_t pixelOffset = size; |
391 size += pixelSize; | 419 size += pixelSize; |
392 size_t ctOffset = size; | 420 size_t ctOffset = size; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 return nullptr; | 477 return nullptr; |
450 } | 478 } |
451 | 479 |
452 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 480 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
453 const SkIPoint dstP = SkIPoint::Make(0, 0); | 481 const SkIPoint dstP = SkIPoint::Make(0, 0); |
454 ctx->copySurface(dst, src, srcR, dstP); | 482 ctx->copySurface(dst, src, srcR, dstP); |
455 ctx->flushSurfaceWrites(dst); | 483 ctx->flushSurfaceWrites(dst); |
456 return dst; | 484 return dst; |
457 } | 485 } |
458 | 486 |
OLD | NEW |