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

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

Issue 139463007: no need to refcnt colortables, since pixelrefs own them (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkBitmap.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 /* 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 this->freePixels(); 94 this->freePixels();
95 memcpy(this, &src, sizeof(src)); 95 memcpy(this, &src, sizeof(src));
96 96
97 // inc src reference counts 97 // inc src reference counts
98 SkSafeRef(src.fPixelRef); 98 SkSafeRef(src.fPixelRef);
99 SkSafeRef(src.fMipMap); 99 SkSafeRef(src.fMipMap);
100 100
101 // we reset our locks if we get blown away 101 // we reset our locks if we get blown away
102 fPixelLockCount = 0; 102 fPixelLockCount = 0;
103 103
104 /* The src could be in 3 states 104 if (fPixelRef) {
105 1. no pixelref, in which case we just copy/ref the pixels/ctable
106 2. unlocked pixelref, pixels/ctable should be null
107 3. locked pixelref, we should lock the ref again ourselves
108 */
109 if (NULL == fPixelRef) {
110 // leave fPixels as it is
111 SkSafeRef(fColorTable); // ref the user's ctable if present
112 } else { // we have a pixelref, so pixels/ctable reflect it
113 // ignore the values from the memcpy 105 // ignore the values from the memcpy
114 fPixels = NULL; 106 fPixels = NULL;
115 fColorTable = NULL; 107 fColorTable = NULL;
116 // Note that what to for genID is somewhat arbitrary. We have no 108 // Note that what to for genID is somewhat arbitrary. We have no
117 // way to track changes to raw pixels across multiple SkBitmaps. 109 // way to track changes to raw pixels across multiple SkBitmaps.
118 // Would benefit from an SkRawPixelRef type created by 110 // Would benefit from an SkRawPixelRef type created by
119 // setPixels. 111 // setPixels.
120 // Just leave the memcpy'ed one but they'll get out of sync 112 // Just leave the memcpy'ed one but they'll get out of sync
121 // as soon either is modified. 113 // as soon either is modified.
122 } 114 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 if (fPixelLockCount > 0) { 330 if (fPixelLockCount > 0) {
339 SkASSERT(fPixelRef->isLocked()); 331 SkASSERT(fPixelRef->isLocked());
340 332
341 void* p = fPixelRef->pixels(); 333 void* p = fPixelRef->pixels();
342 if (NULL != p) { 334 if (NULL != p) {
343 p = (char*)p 335 p = (char*)p
344 + fPixelRefOrigin.fY * fRowBytes 336 + fPixelRefOrigin.fY * fRowBytes
345 + fPixelRefOrigin.fX * fBytesPerPixel; 337 + fPixelRefOrigin.fX * fBytesPerPixel;
346 } 338 }
347 fPixels = p; 339 fPixels = p;
348 SkRefCnt_SafeAssign(fColorTable, fPixelRef->colorTable()); 340 fColorTable = fPixelRef->colorTable();
349 } else { 341 } else {
350 SkASSERT(0 == fPixelLockCount); 342 SkASSERT(0 == fPixelLockCount);
351 fPixels = NULL; 343 fPixels = NULL;
352 if (fColorTable) { 344 fColorTable = NULL;
353 fColorTable->unref();
354 fColorTable = NULL;
355 }
356 } 345 }
357 } 346 }
358 } 347 }
359 348
360 static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) { 349 static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) {
361 SkColorType ct; 350 SkColorType ct;
362 switch (config) { 351 switch (config) {
363 case SkBitmap::kA8_Config: 352 case SkBitmap::kA8_Config:
364 ct = kAlpha_8_SkColorType; 353 ct = kAlpha_8_SkColorType;
365 break; 354 break;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 if (NULL == allocator) { 492 if (NULL == allocator) {
504 allocator = &stdalloc; 493 allocator = &stdalloc;
505 } 494 }
506 return allocator->allocPixelRef(this, ctable); 495 return allocator->allocPixelRef(this, ctable);
507 } 496 }
508 497
509 void SkBitmap::freePixels() { 498 void SkBitmap::freePixels() {
510 // if we're gonna free the pixels, we certainly need to free the mipmap 499 // if we're gonna free the pixels, we certainly need to free the mipmap
511 this->freeMipMap(); 500 this->freeMipMap();
512 501
513 if (fColorTable) {
514 fColorTable->unref();
515 fColorTable = NULL;
516 }
517
518 if (NULL != fPixelRef) { 502 if (NULL != fPixelRef) {
519 if (fPixelLockCount > 0) { 503 if (fPixelLockCount > 0) {
520 fPixelRef->unlockPixels(); 504 fPixelRef->unlockPixels();
521 } 505 }
522 fPixelRef->unref(); 506 fPixelRef->unref();
523 fPixelRef = NULL; 507 fPixelRef = NULL;
524 fPixelRefOrigin.setZero(); 508 fPixelRefOrigin.setZero();
525 } 509 }
526 fPixelLockCount = 0; 510 fPixelLockCount = 0;
527 fPixels = NULL; 511 fPixels = NULL;
512 fColorTable = NULL;
528 } 513 }
529 514
530 void SkBitmap::freeMipMap() { 515 void SkBitmap::freeMipMap() {
531 if (fMipMap) { 516 if (fMipMap) {
532 fMipMap->unref(); 517 fMipMap->unref();
533 fMipMap = NULL; 518 fMipMap = NULL;
534 } 519 }
535 } 520 }
536 521
537 uint32_t SkBitmap::getGenerationID() const { 522 uint32_t SkBitmap::getGenerationID() const {
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 #ifdef SK_DEBUG 1588 #ifdef SK_DEBUG
1604 void SkBitmap::validate() const { 1589 void SkBitmap::validate() const {
1605 SkASSERT(fConfig < kConfigCount); 1590 SkASSERT(fConfig < kConfigCount);
1606 SkASSERT(fRowBytes >= (unsigned)ComputeRowBytes((Config)fConfig, fWidth)); 1591 SkASSERT(fRowBytes >= (unsigned)ComputeRowBytes((Config)fConfig, fWidth));
1607 uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImm utable_Flag; 1592 uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImm utable_Flag;
1608 #ifdef SK_BUILD_FOR_ANDROID 1593 #ifdef SK_BUILD_FOR_ANDROID
1609 allFlags |= kHasHardwareMipMap_Flag; 1594 allFlags |= kHasHardwareMipMap_Flag;
1610 #endif 1595 #endif
1611 SkASSERT(fFlags <= allFlags); 1596 SkASSERT(fFlags <= allFlags);
1612 SkASSERT(fPixelLockCount >= 0); 1597 SkASSERT(fPixelLockCount >= 0);
1613 SkASSERT(NULL == fColorTable || (unsigned)fColorTable->getRefCnt() < 10000);
1614 SkASSERT((uint8_t)ComputeBytesPerPixel((Config)fConfig) == fBytesPerPixel); 1598 SkASSERT((uint8_t)ComputeBytesPerPixel((Config)fConfig) == fBytesPerPixel);
1615 1599
1616 if (fPixels) { 1600 if (fPixels) {
1617 SkASSERT(fPixelRef); 1601 SkASSERT(fPixelRef);
1618 SkASSERT(fPixelLockCount > 0); 1602 SkASSERT(fPixelLockCount > 0);
1619 SkASSERT(fPixelRef->isLocked()); 1603 SkASSERT(fPixelRef->isLocked());
1620 SkASSERT(fPixelRef->rowBytes() == fRowBytes); 1604 SkASSERT(fPixelRef->rowBytes() == fRowBytes);
1621 SkASSERT(fPixelRefOrigin.fX >= 0); 1605 SkASSERT(fPixelRefOrigin.fX >= 0);
1622 SkASSERT(fPixelRefOrigin.fY >= 0); 1606 SkASSERT(fPixelRefOrigin.fY >= 0);
1623 SkASSERT(fPixelRef->info().fWidth >= (int)fWidth + fPixelRefOrigin.fX); 1607 SkASSERT(fPixelRef->info().fWidth >= (int)fWidth + fPixelRefOrigin.fX);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 if (NULL != uri) { 1645 if (NULL != uri) {
1662 str->appendf(" uri:\"%s\"", uri); 1646 str->appendf(" uri:\"%s\"", uri);
1663 } else { 1647 } else {
1664 str->appendf(" pixelref:%p", pr); 1648 str->appendf(" pixelref:%p", pr);
1665 } 1649 }
1666 } 1650 }
1667 1651
1668 str->append(")"); 1652 str->append(")");
1669 } 1653 }
1670 #endif 1654 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698