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

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

Issue 1514503004: SkBitmap move (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-14 (Monday) 12:58:31 EST Created 5 years 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/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 * 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 21 matching lines...) Expand all
32 sk_bzero(this, sizeof(*this)); 32 sk_bzero(this, sizeof(*this));
33 } 33 }
34 34
35 SkBitmap::SkBitmap(const SkBitmap& src) { 35 SkBitmap::SkBitmap(const SkBitmap& src) {
36 SkDEBUGCODE(src.validate();) 36 SkDEBUGCODE(src.validate();)
37 sk_bzero(this, sizeof(*this)); 37 sk_bzero(this, sizeof(*this));
38 *this = src; 38 *this = src;
39 SkDEBUGCODE(this->validate();) 39 SkDEBUGCODE(this->validate();)
40 } 40 }
41 41
42 SkBitmap::SkBitmap(SkBitmap&& other) : SkBitmap() { this->swap(other); }
43
42 SkBitmap::~SkBitmap() { 44 SkBitmap::~SkBitmap() {
43 SkDEBUGCODE(this->validate();) 45 SkDEBUGCODE(this->validate();)
44 this->freePixels(); 46 this->freePixels();
45 } 47 }
46 48
47 SkBitmap& SkBitmap::operator=(const SkBitmap& src) { 49 SkBitmap& SkBitmap::operator=(const SkBitmap& src) {
48 if (this != &src) { 50 if (this != &src) {
49 this->freePixels(); 51 this->freePixels();
50 memcpy(this, &src, sizeof(src)); 52 memcpy(this, &src, sizeof(src));
51 53
(...skipping 13 matching lines...) Expand all
65 // setPixels. 67 // setPixels.
66 // Just leave the memcpy'ed one but they'll get out of sync 68 // Just leave the memcpy'ed one but they'll get out of sync
67 // as soon either is modified. 69 // as soon either is modified.
68 } 70 }
69 } 71 }
70 72
71 SkDEBUGCODE(this->validate();) 73 SkDEBUGCODE(this->validate();)
72 return *this; 74 return *this;
73 } 75 }
74 76
77 SkBitmap& SkBitmap::operator=(SkBitmap&& other) {
78 if (this != &other) {
79 this->swap(other);
80 other.reset();
81 }
82 return *this;
83 }
84
75 void SkBitmap::swap(SkBitmap& other) { 85 void SkBitmap::swap(SkBitmap& other) {
76 SkTSwap(fColorTable, other.fColorTable); 86 SkTSwap(fColorTable, other.fColorTable);
77 SkTSwap(fPixelRef, other.fPixelRef); 87 SkTSwap(fPixelRef, other.fPixelRef);
78 SkTSwap(fPixelRefOrigin, other.fPixelRefOrigin); 88 SkTSwap(fPixelRefOrigin, other.fPixelRefOrigin);
79 SkTSwap(fPixelLockCount, other.fPixelLockCount); 89 SkTSwap(fPixelLockCount, other.fPixelLockCount);
80 SkTSwap(fPixels, other.fPixels); 90 SkTSwap(fPixels, other.fPixels);
81 SkTSwap(fInfo, other.fInfo); 91 SkTSwap(fInfo, other.fInfo);
82 SkTSwap(fRowBytes, other.fRowBytes); 92 SkTSwap(fRowBytes, other.fRowBytes);
83 SkTSwap(fFlags, other.fFlags); 93 SkTSwap(fFlags, other.fFlags);
84 94
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 /////////////////////////////////////////////////////////////////////////////// 1338 ///////////////////////////////////////////////////////////////////////////////
1329 1339
1330 #ifdef SK_DEBUG 1340 #ifdef SK_DEBUG
1331 void SkImageInfo::validate() const { 1341 void SkImageInfo::validate() const {
1332 SkASSERT(fWidth >= 0); 1342 SkASSERT(fWidth >= 0);
1333 SkASSERT(fHeight >= 0); 1343 SkASSERT(fHeight >= 0);
1334 SkASSERT(SkColorTypeIsValid(fColorType)); 1344 SkASSERT(SkColorTypeIsValid(fColorType));
1335 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1345 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1336 } 1346 }
1337 #endif 1347 #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