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

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

Issue 2020683002: Rewrite assignment operator on SkBitmap, fix asan (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remember all the fields Created 4 years, 6 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 | « no previous file | 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 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
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 "SkAtomics.h" 8 #include "SkAtomics.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 SkBitmap::SkBitmap(SkBitmap&& other) : SkBitmap() { this->swap(other); } 42 SkBitmap::SkBitmap(SkBitmap&& other) : SkBitmap() { this->swap(other); }
43 43
44 SkBitmap::~SkBitmap() { 44 SkBitmap::~SkBitmap() {
45 SkDEBUGCODE(this->validate();) 45 SkDEBUGCODE(this->validate();)
46 this->freePixels(); 46 this->freePixels();
47 } 47 }
48 48
49 SkBitmap& SkBitmap::operator=(const SkBitmap& src) { 49 SkBitmap& SkBitmap::operator=(const SkBitmap& src) {
50 if (this != &src) { 50 if (this != &src) {
51 this->freePixels(); 51 this->freePixels();
52 memcpy(this, &src, sizeof(src)); 52 this->fPixelRef = SkSafeRef(src.fPixelRef);
53 if (this->fPixelRef) {
54 // ignore the values if we have a pixelRef
55 this->fPixels = nullptr;
56 this->fColorTable = nullptr;
57 } else {
58 this->fPixels = src.fPixels;
59 this->fColorTable = src.fColorTable;
60 }
61 // we reset our locks if we get blown away
62 this->fPixelLockCount = 0;
53 63
54 // inc src reference counts 64 this->fPixelRefOrigin = src.fPixelRefOrigin;
55 SkSafeRef(src.fPixelRef); 65 this->fInfo = src.fInfo;
56 SkSafeRef(src.fInfo.colorSpace()); 66 this->fRowBytes = src.fRowBytes;
57 67 this->fFlags = src.fFlags;
58 // we reset our locks if we get blown away
59 fPixelLockCount = 0;
60
61 if (fPixelRef) {
62 // ignore the values from the memcpy
63 fPixels = nullptr;
64 fColorTable = nullptr;
65 // Note that what to for genID is somewhat arbitrary. We have no
66 // way to track changes to raw pixels across multiple SkBitmaps.
67 // Would benefit from an SkRawPixelRef type created by
68 // setPixels.
69 // Just leave the memcpy'ed one but they'll get out of sync
70 // as soon either is modified.
71 }
72 } 68 }
73 69
74 SkDEBUGCODE(this->validate();) 70 SkDEBUGCODE(this->validate();)
75 return *this; 71 return *this;
76 } 72 }
77 73
78 SkBitmap& SkBitmap::operator=(SkBitmap&& other) { 74 SkBitmap& SkBitmap::operator=(SkBitmap&& other) {
79 if (this != &other) { 75 if (this != &other) {
80 this->swap(other); 76 this->swap(other);
81 other.reset(); 77 other.reset();
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 /////////////////////////////////////////////////////////////////////////////// 1347 ///////////////////////////////////////////////////////////////////////////////
1352 1348
1353 #ifdef SK_DEBUG 1349 #ifdef SK_DEBUG
1354 void SkImageInfo::validate() const { 1350 void SkImageInfo::validate() const {
1355 SkASSERT(fWidth >= 0); 1351 SkASSERT(fWidth >= 0);
1356 SkASSERT(fHeight >= 0); 1352 SkASSERT(fHeight >= 0);
1357 SkASSERT(SkColorTypeIsValid(fColorType)); 1353 SkASSERT(SkColorTypeIsValid(fColorType));
1358 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1354 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1359 } 1355 }
1360 #endif 1356 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698