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

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

Issue 2147493004: Add a function to convert a texture backed SkImage to raster. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 4 years, 5 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 "SkAutoPixmapStorage.h" 8 #include "SkAutoPixmapStorage.h"
9 #include "GrCaps.h" 9 #include "GrCaps.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return create_image_from_maker(&maker, at, this->uniqueID()); 325 return create_image_from_maker(&maker, at, this->uniqueID());
326 } 326 }
327 SkBitmap bmp; 327 SkBitmap bmp;
328 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) { 328 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) {
329 return nullptr; 329 return nullptr;
330 } 330 }
331 GrBitmapTextureMaker maker(context, bmp); 331 GrBitmapTextureMaker maker(context, bmp);
332 return create_image_from_maker(&maker, at, this->uniqueID()); 332 return create_image_from_maker(&maker, at, this->uniqueID());
333 } 333 }
334 334
335 sk_sp<SkImage> SkImage::makeNonTextureImage() const {
336 GrTexture* texture = as_IB(this)->peekTexture();
337 if (!texture) {
338 return sk_ref_sp(const_cast<SkImage*>(this));
339 }
340 SkColorType ct;
341 sk_sp<SkColorSpace> cs;
342 if (!GrPixelConfigToColorAndColorSpace(texture->config(), &ct, &cs)) {
343 return nullptr;
344 }
345 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
346 auto info = SkImageInfo::Make(this->width(), this->height(), ct, at, cs);
347 size_t rowBytes = info.minRowBytes();
348 size_t size = info.getSafeSize(rowBytes);
349 auto data = SkData::MakeUninitialized(size);
350 if (!data) {
351 return nullptr;
352 }
353 SkPixmap pm(info, data->writable_data(), rowBytes);
354 if (!this->readPixels(pm, 0, 0, kDisallow_CachingHint)) {
355 return nullptr;
356 }
357 return MakeRasterData(info, data, rowBytes);
358 }
359
335 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap, 360 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi xmap,
336 SkBudgeted budgeted) { 361 SkBudgeted budgeted) {
337 if (!ctx) { 362 if (!ctx) {
338 return nullptr; 363 return nullptr;
339 } 364 }
340 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgete d)); 365 SkAutoTUnref<GrTexture> texture(GrUploadPixmapToTexture(ctx, pixmap, budgete d));
341 if (!texture) { 366 if (!texture) {
342 return nullptr; 367 return nullptr;
343 } 368 }
344 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 369 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (!ctx) { 560 if (!ctx) {
536 return nullptr; 561 return nullptr;
537 } 562 }
538 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); 563 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount));
539 if (!texture) { 564 if (!texture) {
540 return nullptr; 565 return nullptr;
541 } 566 }
542 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 567 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
543 info.alphaType(), texture, budgeted); 568 info.alphaType(), texture, budgeted);
544 } 569 }
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