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

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

Issue 2173513002: Cleanup of code that converts from GPU-backed resources to SkImageInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@fix-sync
Patch Set: 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_Gpu.h ('k') | 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 25 matching lines...) Expand all
36 SkNotifyBitmapGenIDIsStale(this->uniqueID()); 36 SkNotifyBitmapGenIDIsStale(this->uniqueID());
37 } 37 }
38 } 38 }
39 39
40 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) { 40 extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
41 if (image->isTextureBacked()) { 41 if (image->isTextureBacked()) {
42 ((SkImage_Gpu*)image)->applyBudgetDecision(); 42 ((SkImage_Gpu*)image)->applyBudgetDecision();
43 } 43 }
44 } 44 }
45 45
46 SkImageInfo SkImage_Gpu::onImageInfo() const {
47 SkColorType ct;
48 if (!GrPixelConfigToColorType(fTexture->config(), &ct)) {
49 ct = kUnknown_SkColorType;
50 }
51 return SkImageInfo::Make(fTexture->width(), fTexture->height(), ct, fAlphaTy pe, fColorSpace);
Brian Osman 2016/07/21 20:57:07 This is now slightly different semantically - it u
52 }
53
46 static SkImageInfo make_info(int w, int h, bool isOpaque, sk_sp<SkColorSpace> co lorSpace) { 54 static SkImageInfo make_info(int w, int h, bool isOpaque, sk_sp<SkColorSpace> co lorSpace) {
47 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S kAlphaType, 55 return SkImageInfo::MakeN32(w, h, isOpaque ? kOpaque_SkAlphaType : kPremul_S kAlphaType,
48 std::move(colorSpace)); 56 std::move(colorSpace));
49 } 57 }
50 58
51 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const { 59 bool SkImage_Gpu::getROPixels(SkBitmap* dst, CachingHint chint) const {
52 if (SkBitmapCache::Find(this->uniqueID(), dst)) { 60 if (SkBitmapCache::Find(this->uniqueID(), dst)) {
53 SkASSERT(dst->getGenerationID() == this->uniqueID()); 61 SkASSERT(dst->getGenerationID() == this->uniqueID());
54 SkASSERT(dst->isImmutable()); 62 SkASSERT(dst->isImmutable());
55 SkASSERT(dst->getPixels()); 63 SkASSERT(dst->getPixels());
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 317 }
310 SkBitmap bmp; 318 SkBitmap bmp;
311 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) { 319 if (!this->asLegacyBitmap(&bmp, kRO_LegacyBitmapMode)) {
312 return nullptr; 320 return nullptr;
313 } 321 }
314 GrBitmapTextureMaker maker(context, bmp); 322 GrBitmapTextureMaker maker(context, bmp);
315 return create_image_from_maker(&maker, at, this->uniqueID()); 323 return create_image_from_maker(&maker, at, this->uniqueID());
316 } 324 }
317 325
318 sk_sp<SkImage> SkImage::makeNonTextureImage() const { 326 sk_sp<SkImage> SkImage::makeNonTextureImage() const {
319 GrTexture* texture = as_IB(this)->peekTexture(); 327 if (!this->isTextureBacked()) {
320 if (!texture) {
321 return sk_ref_sp(const_cast<SkImage*>(this)); 328 return sk_ref_sp(const_cast<SkImage*>(this));
322 } 329 }
323 SkColorType ct; 330 SkImageInfo info = as_IB(this)->onImageInfo();
Brian Osman 2016/07/21 20:57:07 Similar to above. We already have the *correct* al
324 sk_sp<SkColorSpace> cs;
325 if (!GrPixelConfigToColorAndColorSpace(texture->config(), &ct, &cs)) {
326 return nullptr;
327 }
328 SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaTyp e;
329 auto info = SkImageInfo::Make(this->width(), this->height(), ct, at, cs);
330 size_t rowBytes = info.minRowBytes(); 331 size_t rowBytes = info.minRowBytes();
331 size_t size = info.getSafeSize(rowBytes); 332 size_t size = info.getSafeSize(rowBytes);
332 auto data = SkData::MakeUninitialized(size); 333 auto data = SkData::MakeUninitialized(size);
333 if (!data) { 334 if (!data) {
334 return nullptr; 335 return nullptr;
335 } 336 }
336 SkPixmap pm(info, data->writable_data(), rowBytes); 337 SkPixmap pm(info, data->writable_data(), rowBytes);
337 if (!this->readPixels(pm, 0, 0, kDisallow_CachingHint)) { 338 if (!this->readPixels(pm, 0, 0, kDisallow_CachingHint)) {
338 return nullptr; 339 return nullptr;
339 } 340 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 return nullptr; 546 return nullptr;
546 } 547 }
547 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); 548 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount));
548 if (!texture) { 549 if (!texture) {
549 return nullptr; 550 return nullptr;
550 } 551 }
551 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 552 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
552 info.alphaType(), texture, sk_ref_sp(info.col orSpace()), 553 info.alphaType(), texture, sk_ref_sp(info.col orSpace()),
553 budgeted); 554 budgeted);
554 } 555 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698