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

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

Issue 1776693002: Add deferred texture upload API. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase on sk_skp Created 4 years, 9 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 | « src/image/SkImage.cpp ('k') | tests/ImageTest.cpp » ('j') | 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 "GrCaps.h" 8 #include "GrCaps.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap)); 320 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap));
321 if (!texture) { 321 if (!texture) {
322 return nullptr; 322 return nullptr;
323 } 323 }
324 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 324 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
325 pixmap.alphaType(), texture, budgeted); 325 pixmap.alphaType(), texture, budgeted);
326 } 326 }
327 327
328 //////////////////////////////////////////////////////////////////////////////// /////////////////// 328 //////////////////////////////////////////////////////////////////////////////// ///////////////////
329 329
330 class DeferredTextureImage {
331 public:
332 SkImage* newImage(GrContext* context, SkBudgeted) const;
333
334 private:
335 uint32_t fContextUniqueID;
336 struct Data {
337 SkImageInfo fInfo;
338 void* fPixelData;
339 size_t fRowBytes;
340 int fColorTableCnt;
341 uint32_t* fColorTableData;
342 };
343 Data fData;
344
345 friend class SkImage;
346 };
347
348 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y,
349 const DeferredTextureImageUsageParam s[],
350 int paramCnt, void* buffer) const {
351 const bool fillMode = SkToBool(buffer);
352 if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) {
353 return 0;
354 }
355
356 SkAutoPixmapStorage pixmap;
357 SkImageInfo info;
358 size_t pixelSize = 0;
359 size_t ctSize = 0;
360 int ctCount = 0;
361 if (this->peekPixels(&pixmap)) {
362 info = pixmap.info();
363 pixelSize = SkAlign8(pixmap.getSafeSize());
364 if (pixmap.ctable()) {
365 ctCount = pixmap.ctable()->count();
366 ctSize = SkAlign8(pixmap.ctable()->count() * 4);
367 }
368 } else {
369 // 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.
371 // yuv planes) upload.
372 SkAutoTUnref<SkData> data(this->refEncoded());
373 if (!data) {
374 return 0;
375 }
376 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlph aType;
377 info = SkImageInfo::MakeN32(this->width(), this->height(), at);
378 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr));
379 if (fillMode) {
380 pixmap.alloc(info);
381 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHint)) {
382 return 0;
383 }
384 SkASSERT(!pixmap.ctable());
385 }
386 }
387 size_t size = 0;
388 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage));
389 size += dtiSize;
390 size_t pixelOffset = size;
391 size += pixelSize;
392 size_t ctOffset = size;
393 size += ctSize;
394 if (!fillMode) {
395 return size;
396 }
397 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer);
398 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset);
399 SkPMColor* ct = nullptr;
400 if (ctSize) {
401 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset);
402 }
403
404 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize());
405 if (ctSize) {
406 memcpy(ct, pixmap.ctable()->readColors(), ctSize);
407 }
408
409 SkASSERT(info == pixmap.info());
410 size_t rowBytes = pixmap.rowBytes();
411 DeferredTextureImage* dti = new (buffer) DeferredTextureImage();
412 dti->fContextUniqueID = proxy.fContextUniqueID;
413 dti->fData.fInfo = info;
414 dti->fData.fPixelData = pixels;
415 dti->fData.fRowBytes = rowBytes;
416 dti->fData.fColorTableCnt = ctCount;
417 dti->fData.fColorTableData = ct;
418 return size;
419 }
420
421 sk_sp<SkImage> SkImage::MakeFromDeferredTextureImageData(GrContext* context, con st void* data,
422 SkBudgeted budgeted) {
423 if (!data) {
424 return nullptr;
425 }
426 const DeferredTextureImage* dti = reinterpret_cast<const DeferredTextureImag e*>(data);
427
428 if (!context || context->uniqueID() != dti->fContextUniqueID) {
429 return nullptr;
430 }
431 SkAutoTUnref<SkColorTable> colorTable;
432 if (dti->fData.fColorTableCnt) {
433 SkASSERT(dti->fData.fColorTableData);
434 colorTable.reset(new SkColorTable(dti->fData.fColorTableData, dti->fData .fColorTableCnt));
435 }
436 SkPixmap pixmap;
437 pixmap.reset(dti->fData.fInfo, dti->fData.fPixelData, dti->fData.fRowBytes, colorTable.get());
438 return SkImage::MakeTextureFromPixmap(context, pixmap, budgeted);
439 }
440
441 //////////////////////////////////////////////////////////////////////////////// ///////////////////
442
330 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { 443 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) {
331 GrContext* ctx = src->getContext(); 444 GrContext* ctx = src->getContext();
332 445
333 GrSurfaceDesc desc = src->desc(); 446 GrSurfaceDesc desc = src->desc();
334 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); 447 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0);
335 if (!dst) { 448 if (!dst) {
336 return nullptr; 449 return nullptr;
337 } 450 }
338 451
339 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); 452 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight);
340 const SkIPoint dstP = SkIPoint::Make(0, 0); 453 const SkIPoint dstP = SkIPoint::Make(0, 0);
341 ctx->copySurface(dst, src, srcR, dstP); 454 ctx->copySurface(dst, src, srcR, dstP);
342 ctx->flushSurfaceWrites(dst); 455 ctx->flushSurfaceWrites(dst);
343 return dst; 456 return dst;
344 } 457 }
345 458
OLDNEW
« no previous file with comments | « src/image/SkImage.cpp ('k') | tests/ImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698