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 "GrCaps.h" | 8 #include "GrCaps.h" |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap)); | 318 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap)); |
319 if (!texture) { | 319 if (!texture) { |
320 return nullptr; | 320 return nullptr; |
321 } | 321 } |
322 return new SkImage_Gpu(texture->width(), texture->height(), kNeedNewImageUni queID, | 322 return new SkImage_Gpu(texture->width(), texture->height(), kNeedNewImageUni queID, |
323 pixmap.alphaType(), texture, budgeted); | 323 pixmap.alphaType(), texture, budgeted); |
324 } | 324 } |
325 | 325 |
326 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 326 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
327 | 327 |
328 class DeferredTextureImage { | |
329 public: | |
330 SkImage* newImage(GrContext* context, SkBudgeted) const; | |
331 | |
332 private: | |
333 uint32_t fContextUniqueID; | |
robertphillips
2016/03/09 18:54:16
What do we do with fImageUniqueID ?
bsalomon
2016/03/10 15:30:07
Currently, nothing. I wasn't sure whether the new
| |
334 uint32_t fImageUniqueID; | |
335 struct Data { | |
336 SkImageInfo fInfo; | |
337 void* fPixelData; | |
338 size_t fRowBytes; | |
339 int fColorTableCnt; | |
340 uint32_t* fColorTableData; | |
341 }; | |
342 Data fData; | |
343 | |
344 friend class SkImage; | |
345 }; | |
346 | |
347 size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox y, | |
348 const DeferredTextureImageUsageParam s[], | |
349 int paramCnt, void* buffer) const { | |
350 const bool fillMode = SkToBool(buffer); | |
351 if (fillMode && !SkIsAlign8(reinterpret_cast<intptr_t>(buffer))) { | |
352 return 0; | |
353 } | |
354 | |
355 SkAutoPixmapStorage pixmap; | |
356 SkImageInfo info; | |
357 size_t pixelSize = 0; | |
358 size_t ctSize = 0; | |
359 int ctCount = 0; | |
360 if (this->peekPixels(&pixmap)) { | |
361 info = pixmap.info(); | |
362 pixelSize = SkAlign8(pixmap.getSafeSize()); | |
363 if (pixmap.ctable()) { | |
364 ctCount = pixmap.ctable()->count(); | |
365 ctSize = SkAlign8(pixmap.ctable()->count() * 4); | |
366 } | |
367 } else { | |
368 // Here we're just using presence of data to know whether there is a cod ec behind the image. | |
369 // In the future we will access the cacherator and get the exact data th at we want to (e.g. | |
370 // yuv planes) upload. | |
371 SkAutoTUnref<SkData> data(this->refEncoded()); | |
372 if (!data) { | |
373 return 0; | |
374 } | |
375 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlph aType; | |
376 info = SkImageInfo::MakeN32(this->width(), this->height(), at); | |
377 pixelSize = SkAlign8(SkAutoPixmapStorage::AllocSize(info, nullptr)); | |
378 if (fillMode) { | |
379 pixmap.alloc(info); | |
380 if (!this->readPixels(pixmap, 0, 0, SkImage::kDisallow_CachingHint)) { | |
381 return 0; | |
382 } | |
383 SkASSERT(!pixmap.ctable()); | |
384 } | |
385 } | |
386 size_t size = 0; | |
387 size_t dtiSize = SkAlign8(sizeof(DeferredTextureImage)); | |
388 size += dtiSize; | |
389 size_t pixelOffset = size; | |
390 size += pixelSize; | |
391 size_t ctOffset = size; | |
392 size += ctSize; | |
393 if (!fillMode) { | |
394 return size; | |
395 } | |
396 intptr_t bufferAsInt = reinterpret_cast<intptr_t>(buffer); | |
397 void* pixels = reinterpret_cast<void*>(bufferAsInt + pixelOffset); | |
398 SkPMColor* ct = nullptr; | |
399 if (ctSize) { | |
400 ct = reinterpret_cast<SkPMColor*>(bufferAsInt + ctOffset); | |
401 } | |
402 | |
403 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize()); | |
404 if (ctSize) { | |
405 memcpy(ct, pixmap.ctable()->readColors(), ctSize); | |
406 } | |
407 | |
408 SkASSERT(info == pixmap.info()); | |
409 size_t rowBytes = pixmap.rowBytes(); | |
410 DeferredTextureImage* dti = new (buffer) DeferredTextureImage(); | |
411 dti->fContextUniqueID = proxy.fContextUniqueID; | |
412 dti->fImageUniqueID = this->uniqueID(); | |
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 SkImage* SkImage::NewFromDeferredTextureImageData(GrContext* context, const 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::NewTextureFromPixmap(context, pixmap, budgeted); | |
439 } | |
440 | |
441 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
442 | |
328 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { | 443 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) { |
329 GrContext* ctx = src->getContext(); | 444 GrContext* ctx = src->getContext(); |
330 | 445 |
331 GrSurfaceDesc desc = src->desc(); | 446 GrSurfaceDesc desc = src->desc(); |
332 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); | 447 GrTexture* dst = ctx->textureProvider()->createTexture(desc, budgeted, nullp tr, 0); |
333 if (!dst) { | 448 if (!dst) { |
334 return nullptr; | 449 return nullptr; |
335 } | 450 } |
336 | 451 |
337 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 452 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
338 const SkIPoint dstP = SkIPoint::Make(0, 0); | 453 const SkIPoint dstP = SkIPoint::Make(0, 0); |
339 ctx->copySurface(dst, src, srcR, dstP); | 454 ctx->copySurface(dst, src, srcR, dstP); |
340 ctx->flushSurfaceWrites(dst); | 455 ctx->flushSurfaceWrites(dst); |
341 return dst; | 456 return dst; |
342 } | 457 } |
343 | 458 |
OLD | NEW |