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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (!texture) { | 350 if (!texture) { |
351 return nullptr; | 351 return nullptr; |
352 } | 352 } |
353 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, | 353 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, |
354 pixmap.alphaType(), texture, | 354 pixmap.alphaType(), texture, |
355 sk_ref_sp(pixmap.info().colorSpace()), budget
ed); | 355 sk_ref_sp(pixmap.info().colorSpace()), budget
ed); |
356 } | 356 } |
357 | 357 |
358 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 358 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
359 | 359 |
360 class DeferredTextureImage { | 360 namespace { |
361 public: | 361 struct MipMapLevelData { |
362 SkImage* newImage(GrContext* context, SkBudgeted) const; | 362 void* fPixelData; |
| 363 size_t fRowBytes; |
| 364 }; |
363 | 365 |
364 private: | 366 struct DeferredTextureImage { |
365 uint32_t fContextUniqueID; | 367 uint32_t fContextUniqueID; |
366 struct MipMapLevelData { | 368 // We don't store a SkImageInfo because it contains a ref-counted SkColorSpa
ce. |
367 void* fPixelData; | 369 int fWidth; |
368 size_t fRowBytes; | 370 int fHeight; |
369 }; | 371 SkColorType fColorType; |
370 struct Data { | 372 SkAlphaType fAlphaType; |
371 SkImageInfo fInfo; | 373 void* fColorSpace; |
372 int fColorTableCnt; | 374 size_t fColorSpaceSize; |
373 uint32_t* fColorTableData; | 375 int fColorTableCnt; |
374 int fMipMapLevelCount; | 376 uint32_t* fColorTableData; |
375 // The fMipMapLevelData array may contain more than 1 element. | 377 int fMipMapLevelCount; |
376 // It contains fMipMapLevelCount elements. | 378 // The fMipMapLevelData array may contain more than 1 element. |
377 // That means this struct's size is not known at compile-time. | 379 // It contains fMipMapLevelCount elements. |
378 MipMapLevelData fMipMapLevelData[1]; | 380 // That means this struct's size is not known at compile-time. |
379 }; | 381 MipMapLevelData fMipMapLevelData[1]; |
380 Data fData; | |
381 | |
382 friend class SkImage; | |
383 }; | 382 }; |
| 383 } // anonymous namespace |
384 | 384 |
385 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
y, | 385 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox
y, |
386 const DeferredTextureImageUsageParam
s params[], | 386 const DeferredTextureImageUsageParam
s params[], |
387 int paramCnt, void* buffer) const { | 387 int paramCnt, void* buffer) const { |
388 // Extract relevant min/max values from the params array. | 388 // Extract relevant min/max values from the params array. |
389 int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; | 389 int lowestPreScaleMipLevel = params[0].fPreScaleMipLevel; |
390 SkFilterQuality highestFilterQuality = params[0].fQuality; | 390 SkFilterQuality highestFilterQuality = params[0].fQuality; |
391 for (int i = 1; i < paramCnt; ++i) { | 391 for (int i = 1; i < paramCnt; ++i) { |
392 if (lowestPreScaleMipLevel > params[i].fPreScaleMipLevel) | 392 if (lowestPreScaleMipLevel > params[i].fPreScaleMipLevel) |
393 lowestPreScaleMipLevel = params[i].fPreScaleMipLevel; | 393 lowestPreScaleMipLevel = params[i].fPreScaleMipLevel; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 return 0; | 459 return 0; |
460 } | 460 } |
461 } | 461 } |
462 SkASSERT(!pixmap.ctable()); | 462 SkASSERT(!pixmap.ctable()); |
463 } | 463 } |
464 } | 464 } |
465 int mipMapLevelCount = 1; | 465 int mipMapLevelCount = 1; |
466 size_t size = 0; | 466 size_t size = 0; |
467 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); | 467 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); |
468 size += dtiSize; | 468 size += dtiSize; |
469 size += mipMapLevelCount * sizeof(DeferredTextureImage::MipMapLevelData); | 469 size += mipMapLevelCount * sizeof(MipMapLevelData); |
470 size_t pixelOffset = size; | 470 size_t pixelOffset = size; |
471 size += pixelSize; | 471 size += pixelSize; |
472 size_t ctOffset = size; | 472 size_t ctOffset = size; |
473 size += ctSize; | 473 size += ctSize; |
| 474 size_t colorSpaceOffset = 0; |
| 475 size_t colorSpaceSize = 0; |
| 476 if (info.colorSpace()) { |
| 477 colorSpaceOffset = size; |
| 478 colorSpaceSize = info.colorSpace()->writeToMemory(nullptr); |
| 479 size += colorSpaceSize; |
| 480 } |
474 if (!fillMode) { | 481 if (!fillMode) { |
475 return size; | 482 return size; |
476 } | 483 } |
477 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); | 484 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); |
478 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset); | 485 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset); |
479 SkPMColor* ct = nullptr; | 486 SkPMColor* ct = nullptr; |
480 if (ctSize) { | 487 if (ctSize) { |
481 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset); | 488 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset); |
482 } | 489 } |
483 | 490 |
484 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize()); | 491 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize()); |
485 if (ctSize) { | 492 if (ctSize) { |
486 memcpy(ct, pixmap.ctable()->readColors(), ctSize); | 493 memcpy(ct, pixmap.ctable()->readColors(), ctSize); |
487 } | 494 } |
488 | 495 |
489 SkASSERT(info == pixmap.info()); | 496 SkASSERT(info == pixmap.info()); |
490 size_t rowBytes = pixmap.rowBytes(); | 497 size_t rowBytes = pixmap.rowBytes(); |
491 DeferredTextureImage* dti = new (buffer) DeferredTextureImage(); | 498 DeferredTextureImage* dti = new (buffer) DeferredTextureImage(); |
492 dti->fContextUniqueID = proxy.fContextUniqueID; | 499 dti->fContextUniqueID = proxy.fContextUniqueID; |
493 dti->fData.fInfo = info; | 500 dti->fWidth = info.width(); |
494 dti->fData.fColorTableCnt = ctCount; | 501 dti->fHeight = info.height(); |
495 dti->fData.fColorTableData = ct; | 502 dti->fColorType = info.colorType(); |
496 dti->fData.fMipMapLevelCount = mipMapLevelCount; | 503 dti->fAlphaType = info.alphaType(); |
497 dti->fData.fMipMapLevelData[0].fPixelData = pixels; | 504 dti->fColorTableCnt = ctCount; |
498 dti->fData.fMipMapLevelData[0].fRowBytes = rowBytes; | 505 dti->fColorTableData = ct; |
| 506 dti->fMipMapLevelCount = mipMapLevelCount; |
| 507 dti->fMipMapLevelData[0].fPixelData = pixels; |
| 508 dti->fMipMapLevelData[0].fRowBytes = rowBytes; |
| 509 if (colorSpaceSize) { |
| 510 dti->fColorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffse
t); |
| 511 dti->fColorSpaceSize = colorSpaceSize; |
| 512 info.colorSpace()->writeToMemory(dti->fColorSpace); |
| 513 } else { |
| 514 dti->fColorSpace = nullptr; |
| 515 dti->fColorSpaceSize = 0; |
| 516 } |
499 return size; | 517 return size; |
500 } | 518 } |
501 | 519 |
502 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con
st void* data, | 520 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con
st void* data, |
503 SkBudgeted budgeted) { | 521 SkBudgeted budgeted) { |
504 if (!data) { | 522 if (!data) { |
505 return nullptr; | 523 return nullptr; |
506 } | 524 } |
507 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag
e*>(data); | 525 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag
e*>(data); |
508 | 526 |
509 if (!context || context->uniqueID() != dti->fContextUniqueID) { | 527 if (!context || context->uniqueID() != dti->fContextUniqueID) { |
510 return nullptr; | 528 return nullptr; |
511 } | 529 } |
512 SkAutoTUnref<SkColorTable> colorTable; | 530 SkAutoTUnref<SkColorTable> colorTable; |
513 if (dti->fData.fColorTableCnt) { | 531 if (dti->fColorTableCnt) { |
514 SkASSERT(dti->fData.fColorTableData); | 532 SkASSERT(dti->fColorTableData); |
515 colorTable.reset(new SkColorTable(dti->fData.fColorTableData, dti->fData
.fColorTableCnt)); | 533 colorTable.reset(new SkColorTable(dti->fColorTableData, dti->fColorTable
Cnt)); |
516 } | 534 } |
517 SkASSERT(dti->fData.fMipMapLevelCount == 1); | 535 SkASSERT(dti->fMipMapLevelCount == 1); |
| 536 sk_sp<SkColorSpace> colorSpace; |
| 537 if (dti->fColorSpaceSize) { |
| 538 colorSpace = SkColorSpace::Deserialize(dti->fColorSpace, dti->fColorSpac
eSize); |
| 539 } |
| 540 SkImageInfo info = SkImageInfo::Make(dti->fWidth, dti->fHeight, |
| 541 dti->fColorType, dti->fAlphaType, color
Space); |
518 SkPixmap pixmap; | 542 SkPixmap pixmap; |
519 pixmap.reset(dti->fData.fInfo, dti->fData.fMipMapLevelData[0].fPixelData, | 543 pixmap.reset(info, dti->fMipMapLevelData[0].fPixelData, |
520 dti->fData.fMipMapLevelData[0].fRowBytes, colorTable.get()); | 544 dti->fMipMapLevelData[0].fRowBytes, colorTable.get()); |
521 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted); | 545 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted); |
522 } | 546 } |
523 | 547 |
524 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 548 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
525 | 549 |
526 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { | 550 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { |
527 GrContext* ctx = src->getContext(); | 551 GrContext* ctx = src->getContext(); |
528 | 552 |
529 GrSurfaceDesc desc = src->desc(); | 553 GrSurfaceDesc desc = src->desc(); |
530 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); | 554 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp
tr, 0); |
(...skipping 15 matching lines...) Expand all Loading... |
546 return nullptr; | 570 return nullptr; |
547 } | 571 } |
548 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); | 572 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m
ipLevelCount)); |
549 if (!texture) { | 573 if (!texture) { |
550 return nullptr; | 574 return nullptr; |
551 } | 575 } |
552 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, | 576 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew
ImageUniqueID, |
553 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), | 577 info.alphaType(), texture, sk_ref_sp(info.col
orSpace()), |
554 budgeted); | 578 budgeted); |
555 } | 579 } |
OLD | NEW |