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

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

Issue 320873003: change pixelref to not inherit from SkFlattenable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 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 | « include/gpu/SkGrPixelRef.h ('k') | src/core/SkMallocPixelRef.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 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 bitmap->setPixelRef(pr, 0, 0); 1285 bitmap->setPixelRef(pr, 0, 0);
1286 return true; 1286 return true;
1287 } 1287 }
1288 1288
1289 enum { 1289 enum {
1290 SERIALIZE_PIXELTYPE_NONE, 1290 SERIALIZE_PIXELTYPE_NONE,
1291 SERIALIZE_PIXELTYPE_REF_DATA 1291 SERIALIZE_PIXELTYPE_REF_DATA
1292 }; 1292 };
1293 1293
1294 void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) { 1294 void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) {
1295 #ifdef SK_SUPPORT_LEGACY_PIXELREF_UNFLATTENABLE
1295 this->reset(); 1296 this->reset();
1296 1297
1297 SkImageInfo info; 1298 SkImageInfo info;
1298 info.unflatten(buffer); 1299 info.unflatten(buffer);
1299 size_t rowBytes = buffer.readInt(); 1300 size_t rowBytes = buffer.readInt();
1300 if (!buffer.validate((info.width() >= 0) && (info.height() >= 0) && 1301 if (!buffer.validate((info.width() >= 0) && (info.height() >= 0) &&
1301 SkColorTypeIsValid(info.fColorType) && 1302 SkColorTypeIsValid(info.fColorType) &&
1302 SkAlphaTypeIsValid(info.fAlphaType) && 1303 SkAlphaTypeIsValid(info.fAlphaType) &&
1303 SkColorTypeValidateAlphaType(info.fColorType, info.fAlp haType) && 1304 SkColorTypeValidateAlphaType(info.fColorType, info.fAlp haType) &&
1304 info.validRowBytes(rowBytes))) { 1305 info.validRowBytes(rowBytes))) {
1305 return; 1306 return;
1306 } 1307 }
1307 1308
1308 bool configIsValid = this->setInfo(info, rowBytes); 1309 bool configIsValid = this->setInfo(info, rowBytes);
1309 buffer.validate(configIsValid); 1310 buffer.validate(configIsValid);
1310 1311
1311 int reftype = buffer.readInt(); 1312 int reftype = buffer.readInt();
1312 if (buffer.validate((SERIALIZE_PIXELTYPE_REF_DATA == reftype) || 1313 if (buffer.validate((SERIALIZE_PIXELTYPE_REF_DATA == reftype) ||
1313 (SERIALIZE_PIXELTYPE_NONE == reftype))) { 1314 (SERIALIZE_PIXELTYPE_NONE == reftype))) {
1314 switch (reftype) { 1315 switch (reftype) {
1315 case SERIALIZE_PIXELTYPE_REF_DATA: { 1316 case SERIALIZE_PIXELTYPE_REF_DATA: {
1316 SkIPoint origin; 1317 SkIPoint origin;
1317 origin.fX = buffer.readInt(); 1318 origin.fX = buffer.readInt();
1318 origin.fY = buffer.readInt(); 1319 origin.fY = buffer.readInt();
1319 size_t offset = origin.fY * rowBytes + origin.fX * info.bytesPer Pixel(); 1320 size_t offset = origin.fY * rowBytes + origin.fX * info.bytesPer Pixel();
1320 SkPixelRef* pr = buffer.readPixelRef(); 1321 SkPixelRef* pr = buffer.readFlattenable<SkPixelRef>();
1321 if (!buffer.validate((NULL == pr) || 1322 if (!buffer.validate((NULL == pr) ||
1322 (pr->getAllocatedSizeInBytes() >= (offset + this->getSafe Size())))) { 1323 (pr->getAllocatedSizeInBytes() >= (offset + this->getSafe Size())))) {
1323 origin.setZero(); 1324 origin.setZero();
1324 } 1325 }
1325 SkSafeUnref(this->setPixelRef(pr, origin)); 1326 SkSafeUnref(this->setPixelRef(pr, origin));
1326 break; 1327 break;
1327 } 1328 }
1328 case SERIALIZE_PIXELTYPE_NONE: 1329 case SERIALIZE_PIXELTYPE_NONE:
1329 break; 1330 break;
1330 default: 1331 default:
1331 SkDEBUGFAIL("unrecognized pixeltype in serialized data"); 1332 SkDEBUGFAIL("unrecognized pixeltype in serialized data");
1332 sk_throw(); 1333 sk_throw();
1333 } 1334 }
1334 } 1335 }
1336 #else
1337 sk_throw();
1338 #endif
1335 } 1339 }
1336 1340
1337 /////////////////////////////////////////////////////////////////////////////// 1341 ///////////////////////////////////////////////////////////////////////////////
1338 1342
1339 SkBitmap::RLEPixels::RLEPixels(int width, int height) { 1343 SkBitmap::RLEPixels::RLEPixels(int width, int height) {
1340 fHeight = height; 1344 fHeight = height;
1341 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*)); 1345 fYPtrs = (uint8_t**)sk_calloc_throw(height * sizeof(uint8_t*));
1342 } 1346 }
1343 1347
1344 SkBitmap::RLEPixels::~RLEPixels() { 1348 SkBitmap::RLEPixels::~RLEPixels() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 /////////////////////////////////////////////////////////////////////////////// 1428 ///////////////////////////////////////////////////////////////////////////////
1425 1429
1426 #ifdef SK_DEBUG 1430 #ifdef SK_DEBUG
1427 void SkImageInfo::validate() const { 1431 void SkImageInfo::validate() const {
1428 SkASSERT(fWidth >= 0); 1432 SkASSERT(fWidth >= 0);
1429 SkASSERT(fHeight >= 0); 1433 SkASSERT(fHeight >= 0);
1430 SkASSERT(SkColorTypeIsValid(fColorType)); 1434 SkASSERT(SkColorTypeIsValid(fColorType));
1431 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1435 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1432 } 1436 }
1433 #endif 1437 #endif
OLDNEW
« no previous file with comments | « include/gpu/SkGrPixelRef.h ('k') | src/core/SkMallocPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698