Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 2023573002: Add mip support to *DeferredTextureImageData functions. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixing MSVC build. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 322
323 //////////////////////////////////////////////////////////////////////////////// /////////////////// 323 //////////////////////////////////////////////////////////////////////////////// ///////////////////
324 324
325 class DeferredTextureImage { 325 class DeferredTextureImage {
326 public: 326 public:
327 SkImage* newImage(GrContext* context, SkBudgeted) const; 327 SkImage* newImage(GrContext* context, SkBudgeted) const;
328 328
329 private: 329 private:
330 uint32_t fContextUniqueID; 330 uint32_t fContextUniqueID;
331 struct MipMapLevelData {
332 void* fPixelData;
333 size_t fRowBytes;
334 };
331 struct Data { 335 struct Data {
332 SkImageInfo fInfo; 336 SkImageInfo fInfo;
333 void* fPixelData;
334 size_t fRowBytes;
335 int fColorTableCnt; 337 int fColorTableCnt;
336 uint32_t* fColorTableData; 338 uint32_t* fColorTableData;
339 int fMipMapLevelCount;
340 // The fMipMapLevelData array may contain more than 1 element.
341 // It contains fMipMapLevelCount elements.
342 // That means this struct's size is not known at compile-time.
343 MipMapLevelData fMipMapLevelData[1];
337 }; 344 };
338 Data fData; 345 Data fData;
339 346
340 friend class SkImage; 347 friend class SkImage;
341 }; 348 };
342 349
343 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y, 350 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y,
344 const DeferredTextureImageUsageParam s[], 351 const DeferredTextureImageUsageParam s[],
345 int paramCnt, void* buffer) const { 352 int paramCnt, void* buffer) const {
346 const bool fillMode = SkToBool(buffer); 353 const bool fillMode = SkToBool(buffer);
(...skipping 30 matching lines...) Expand all
377 info = SkImageInfo::MakeN32(this->width(), this->height(), at); 384 info = SkImageInfo::MakeN32(this->width(), this->height(), at);
378 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); 385 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr));
379 if (fillMode) { 386 if (fillMode) {
380 pixmap.alloc(info); 387 pixmap.alloc(info);
381 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHint)) { 388 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHint)) {
382 return 0; 389 return 0;
383 } 390 }
384 SkASSERT(!pixmap.ctable()); 391 SkASSERT(!pixmap.ctable());
385 } 392 }
386 } 393 }
394 int mipMapLevelCount = 1;
387 size_t size = 0; 395 size_t size = 0;
388 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); 396 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage));
389 size += dtiSize; 397 size += dtiSize;
398 size += mipMapLevelCount * sizeof(DeferredTextureImage::MipMapLevelData);
390 size_t pixelOffset = size; 399 size_t pixelOffset = size;
391 size += pixelSize; 400 size += pixelSize;
392 size_t ctOffset = size; 401 size_t ctOffset = size;
393 size += ctSize; 402 size += ctSize;
394 if (!fillMode) { 403 if (!fillMode) {
395 return size; 404 return size;
396 } 405 }
397 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); 406 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer);
398 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset); 407 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset);
399 SkPMColor* ct = nullptr; 408 SkPMColor* ct = nullptr;
400 if (ctSize) { 409 if (ctSize) {
401 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset); 410 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset);
402 } 411 }
403 412
404 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize()); 413 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize());
405 if (ctSize) { 414 if (ctSize) {
406 memcpy(ct, pixmap.ctable()->readColors(), ctSize); 415 memcpy(ct, pixmap.ctable()->readColors(), ctSize);
407 } 416 }
408 417
409 SkASSERT(info == pixmap.info()); 418 SkASSERT(info == pixmap.info());
410 size_t rowBytes = pixmap.rowBytes(); 419 size_t rowBytes = pixmap.rowBytes();
411 DeferredTextureImage* dti = new (buffer) DeferredTextureImage(); 420 DeferredTextureImage* dti = new (buffer) DeferredTextureImage();
412 dti->fContextUniqueID = proxy.fContextUniqueID; 421 dti->fContextUniqueID = proxy.fContextUniqueID;
413 dti->fData.fInfo = info; 422 dti->fData.fInfo = info;
414 dti->fData.fPixelData = pixels;
415 dti->fData.fRowBytes = rowBytes;
416 dti->fData.fColorTableCnt = ctCount; 423 dti->fData.fColorTableCnt = ctCount;
417 dti->fData.fColorTableData = ct; 424 dti->fData.fColorTableData = ct;
425 dti->fData.fMipMapLevelCount = mipMapLevelCount;
426 dti->fData.fMipMapLevelData[0].fPixelData = pixels;
427 dti->fData.fMipMapLevelData[0].fRowBytes = rowBytes;
418 return size; 428 return size;
419 } 429 }
420 430
421 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con st void* data, 431 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con st void* data,
422 SkBudgeted budgeted) { 432 SkBudgeted budgeted) {
423 if (!data) { 433 if (!data) {
424 return nullptr; 434 return nullptr;
425 } 435 }
426 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag e*>(data); 436 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag e*>(data);
427 437
428 if (!context || context->uniqueID() != dti->fContextUniqueID) { 438 if (!context || context->uniqueID() != dti->fContextUniqueID) {
429 return nullptr; 439 return nullptr;
430 } 440 }
431 SkAutoTUnref<SkColorTable> colorTable; 441 SkAutoTUnref<SkColorTable> colorTable;
432 if (dti->fData.fColorTableCnt) { 442 if (dti->fData.fColorTableCnt) {
433 SkASSERT(dti->fData.fColorTableData); 443 SkASSERT(dti->fData.fColorTableData);
434 colorTable.reset(new SkColorTable(dti->fData.fColorTableData, dti->fData .fColorTableCnt)); 444 colorTable.reset(new SkColorTable(dti->fData.fColorTableData, dti->fData .fColorTableCnt));
435 } 445 }
446 SkASSERT(dti->fData.fMipMapLevelCount == 1);
436 SkPixmap pixmap; 447 SkPixmap pixmap;
437 pixmap.reset(dti->fData.fInfo, dti->fData.fPixelData, dti->fData.fRowBytes, colorTable.get()); 448 pixmap.reset(dti->fData.fInfo, dti->fData.fMipMapLevelData[0].fPixelData,
449 dti->fData.fMipMapLevelData[0].fRowBytes, colorTable.get());
438 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted); 450 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted);
439 } 451 }
440 452
441 //////////////////////////////////////////////////////////////////////////////// /////////////////// 453 //////////////////////////////////////////////////////////////////////////////// ///////////////////
442 454
443 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { 455 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) {
444 GrContext* ctx = src->getContext(); 456 GrContext* ctx = src->getContext();
445 457
446 GrSurfaceDesc desc = src->desc(); 458 GrSurfaceDesc desc = src->desc();
447 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); 459 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0);
448 if (!dst) { 460 if (!dst) {
449 return nullptr; 461 return nullptr;
450 } 462 }
451 463
452 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 464 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
453 const SkIPoint dstP = SkIPoint::Make(0, 0); 465 const SkIPoint dstP = SkIPoint::Make(0, 0);
454 ctx->copySurface(dst, src, srcR, dstP); 466 ctx->copySurface(dst, src, srcR, dstP);
455 ctx->flushSurfaceWrites(dst); 467 ctx->flushSurfaceWrites(dst);
456 return dst; 468 return dst;
457 } 469 }
458 470
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698