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

Side by Side Diff: src/core/SkBitmap.cpp

Issue 560653004: SkData can allocate room for its contents in the same block (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox, change fPtr to non const Created 6 years, 3 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 | « include/core/SkData.h ('k') | src/core/SkData.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 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 } 1204 }
1205 1205
1206 const size_t ramRB = info.minRowBytes(); 1206 const size_t ramRB = info.minRowBytes();
1207 const int height = info.height(); 1207 const int height = info.height();
1208 const size_t snugSize = snugRB * height; 1208 const size_t snugSize = snugRB * height;
1209 const size_t ramSize = ramRB * height; 1209 const size_t ramSize = ramRB * height;
1210 if (!buffer->validate(snugSize <= ramSize)) { 1210 if (!buffer->validate(snugSize <= ramSize)) {
1211 return false; 1211 return false;
1212 } 1212 }
1213 1213
1214 char* dst = (char*)sk_malloc_throw(ramSize); 1214 SkAutoDataUnref data(SkData::NewUninitialized(ramSize));
1215 char* dst = (char*)data->writable_data();
1215 buffer->readByteArray(dst, snugSize); 1216 buffer->readByteArray(dst, snugSize);
1216 SkAutoDataUnref data(SkData::NewFromMalloc(dst, ramSize));
1217 1217
1218 if (snugSize != ramSize) { 1218 if (snugSize != ramSize) {
1219 const char* srcRow = dst + snugRB * (height - 1); 1219 const char* srcRow = dst + snugRB * (height - 1);
1220 char* dstRow = dst + ramRB * (height - 1); 1220 char* dstRow = dst + ramRB * (height - 1);
1221 for (int y = height - 1; y >= 1; --y) { 1221 for (int y = height - 1; y >= 1; --y) {
1222 memmove(dstRow, srcRow, snugRB); 1222 memmove(dstRow, srcRow, snugRB);
1223 srcRow -= snugRB; 1223 srcRow -= snugRB;
1224 dstRow -= ramRB; 1224 dstRow -= ramRB;
1225 } 1225 }
1226 SkASSERT(srcRow == dstRow); // first row does not need to be moved 1226 SkASSERT(srcRow == dstRow); // first row does not need to be moved
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 /////////////////////////////////////////////////////////////////////////////// 1380 ///////////////////////////////////////////////////////////////////////////////
1381 1381
1382 #ifdef SK_DEBUG 1382 #ifdef SK_DEBUG
1383 void SkImageInfo::validate() const { 1383 void SkImageInfo::validate() const {
1384 SkASSERT(fWidth >= 0); 1384 SkASSERT(fWidth >= 0);
1385 SkASSERT(fHeight >= 0); 1385 SkASSERT(fHeight >= 0);
1386 SkASSERT(SkColorTypeIsValid(fColorType)); 1386 SkASSERT(SkColorTypeIsValid(fColorType));
1387 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1387 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1388 } 1388 }
1389 #endif 1389 #endif
OLDNEW
« no previous file with comments | « include/core/SkData.h ('k') | src/core/SkData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698