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

Side by Side Diff: src/views/animated/SkImageView.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 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 | « src/views/animated/SkBorderView.cpp ('k') | src/views/animated/SkProgressBarView.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 2011 Google Inc. 3 * Copyright 2011 Google Inc.
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 #include "SkImageView.h" 8 #include "SkImageView.h"
9 #include "SkAnimator.h" 9 #include "SkAnimator.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
13 #include "SkMatrix.h" 13 #include "SkMatrix.h"
14 #include "SkSystemEventTypes.h" 14 #include "SkSystemEventTypes.h"
15 #include "SkTime.h" 15 #include "SkTime.h"
16 16
17 SkImageView::SkImageView() 17 SkImageView::SkImageView()
18 { 18 {
19 fMatrix = NULL; 19 fMatrix = nullptr;
20 fScaleType = kMatrix_ScaleType; 20 fScaleType = kMatrix_ScaleType;
21 21
22 fData.fAnim = NULL; // handles initializing the other union values 22 fData.fAnim = nullptr; // handles initializing the other union val ues
23 fDataIsAnim = true; 23 fDataIsAnim = true;
24 24
25 fUriIsValid = false; // an empty string is not valid 25 fUriIsValid = false; // an empty string is not valid
26 } 26 }
27 27
28 SkImageView::~SkImageView() 28 SkImageView::~SkImageView()
29 { 29 {
30 if (fMatrix) 30 if (fMatrix)
31 sk_free(fMatrix); 31 sk_free(fMatrix);
32 32
(...skipping 25 matching lines...) Expand all
58 } 58 }
59 59
60 void SkImageView::setScaleType(ScaleType st) 60 void SkImageView::setScaleType(ScaleType st)
61 { 61 {
62 SkASSERT((unsigned)st <= kFitEnd_ScaleType); 62 SkASSERT((unsigned)st <= kFitEnd_ScaleType);
63 63
64 if ((ScaleType)fScaleType != st) 64 if ((ScaleType)fScaleType != st)
65 { 65 {
66 fScaleType = SkToU8(st); 66 fScaleType = SkToU8(st);
67 if (fUriIsValid) 67 if (fUriIsValid)
68 this->inval(NULL); 68 this->inval(nullptr);
69 } 69 }
70 } 70 }
71 71
72 bool SkImageView::getImageMatrix(SkMatrix* matrix) const 72 bool SkImageView::getImageMatrix(SkMatrix* matrix) const
73 { 73 {
74 if (fMatrix) 74 if (fMatrix)
75 { 75 {
76 SkASSERT(!fMatrix->isIdentity()); 76 SkASSERT(!fMatrix->isIdentity());
77 if (matrix) 77 if (matrix)
78 *matrix = *fMatrix; 78 *matrix = *fMatrix;
79 return true; 79 return true;
80 } 80 }
81 else 81 else
82 { 82 {
83 if (matrix) 83 if (matrix)
84 matrix->reset(); 84 matrix->reset();
85 return false; 85 return false;
86 } 86 }
87 } 87 }
88 88
89 void SkImageView::setImageMatrix(const SkMatrix* matrix) 89 void SkImageView::setImageMatrix(const SkMatrix* matrix)
90 { 90 {
91 bool changed = false; 91 bool changed = false;
92 92
93 if (matrix && !matrix->isIdentity()) 93 if (matrix && !matrix->isIdentity())
94 { 94 {
95 if (fMatrix == NULL) 95 if (fMatrix == nullptr)
96 fMatrix = (SkMatrix*)sk_malloc_throw(sizeof(SkMatrix)); 96 fMatrix = (SkMatrix*)sk_malloc_throw(sizeof(SkMatrix));
97 *fMatrix = *matrix; 97 *fMatrix = *matrix;
98 changed = true; 98 changed = true;
99 } 99 }
100 else // set us to identity 100 else // set us to identity
101 { 101 {
102 if (fMatrix) 102 if (fMatrix)
103 { 103 {
104 SkASSERT(!fMatrix->isIdentity()); 104 SkASSERT(!fMatrix->isIdentity());
105 sk_free(fMatrix); 105 sk_free(fMatrix);
106 fMatrix = NULL; 106 fMatrix = nullptr;
107 changed = true; 107 changed = true;
108 } 108 }
109 } 109 }
110 110
111 // only redraw if we changed our matrix and we're not in scaleToFit mode 111 // only redraw if we changed our matrix and we're not in scaleToFit mode
112 if (changed && this->getScaleType() == kMatrix_ScaleType && fUriIsValid) 112 if (changed && this->getScaleType() == kMatrix_ScaleType && fUriIsValid)
113 this->inval(NULL); 113 this->inval(nullptr);
114 } 114 }
115 115
116 //////////////////////////////////////////////////////////////////////////////// /////////////// 116 //////////////////////////////////////////////////////////////////////////////// ///////////////
117 117
118 bool SkImageView::onEvent(const SkEvent& evt) 118 bool SkImageView::onEvent(const SkEvent& evt)
119 { 119 {
120 if (evt.isType(SK_EventType_Inval)) 120 if (evt.isType(SK_EventType_Inval))
121 { 121 {
122 if (fUriIsValid) 122 if (fUriIsValid)
123 this->inval(NULL); 123 this->inval(nullptr);
124 return true; 124 return true;
125 } 125 }
126 return this->INHERITED::onEvent(evt); 126 return this->INHERITED::onEvent(evt);
127 } 127 }
128 128
129 static inline SkMatrix::ScaleToFit scaleTypeToScaleToFit(SkImageView::ScaleType st) 129 static inline SkMatrix::ScaleToFit scaleTypeToScaleToFit(SkImageView::ScaleType st)
130 { 130 {
131 SkASSERT(st != SkImageView::kMatrix_ScaleType); 131 SkASSERT(st != SkImageView::kMatrix_ScaleType);
132 SkASSERT((unsigned)st <= SkImageView::kFitEnd_ScaleType); 132 SkASSERT((unsigned)st <= SkImageView::kFitEnd_ScaleType);
133 133
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 if (fDataIsAnim) 168 if (fDataIsAnim)
169 { 169 {
170 SkMSec now = SkTime::GetMSecs(); 170 SkMSec now = SkTime::GetMSecs();
171 171
172 SkAnimator::DifferenceType diff = fData.fAnim->draw(canvas, &paint, now) ; 172 SkAnimator::DifferenceType diff = fData.fAnim->draw(canvas, &paint, now) ;
173 173
174 SkDEBUGF(("SkImageView : now = %X[%12.3f], diff = %d\n", now, now/1000., diff)); 174 SkDEBUGF(("SkImageView : now = %X[%12.3f], diff = %d\n", now, now/1000., diff));
175 175
176 if (diff == SkAnimator::kDifferent) 176 if (diff == SkAnimator::kDifferent)
177 this->inval(NULL); 177 this->inval(nullptr);
178 else if (diff == SkAnimator::kPartiallyDifferent) 178 else if (diff == SkAnimator::kPartiallyDifferent)
179 { 179 {
180 SkRect bounds; 180 SkRect bounds;
181 fData.fAnim->getInvalBounds(&bounds); 181 fData.fAnim->getInvalBounds(&bounds);
182 matrix.mapRect(&bounds); // get the bounds into view coordinates 182 matrix.mapRect(&bounds); // get the bounds into view coordinates
183 this->inval(&bounds); 183 this->inval(&bounds);
184 } 184 }
185 } 185 }
186 else 186 else
187 canvas->drawBitmap(*fData.fBitmap, 0, 0, &paint); 187 canvas->drawBitmap(*fData.fBitmap, 0, 0, &paint);
(...skipping 12 matching lines...) Expand all
200 this->setScaleType((ScaleType)index); 200 this->setScaleType((ScaleType)index);
201 201
202 // need inflate syntax/reader for matrix 202 // need inflate syntax/reader for matrix
203 } 203 }
204 204
205 //////////////////////////////////////////////////////////////////////////////// ///// 205 //////////////////////////////////////////////////////////////////////////////// /////
206 206
207 void SkImageView::onUriChange() 207 void SkImageView::onUriChange()
208 { 208 {
209 if (this->freeData()) 209 if (this->freeData())
210 this->inval(NULL); 210 this->inval(nullptr);
211 fUriIsValid = true; // give ensureUriIsLoaded() a shot at the new uri 211 fUriIsValid = true; // give ensureUriIsLoaded() a shot at the new uri
212 } 212 }
213 213
214 bool SkImageView::freeData() 214 bool SkImageView::freeData()
215 { 215 {
216 if (fData.fAnim) // test is valid for all union values 216 if (fData.fAnim) // test is valid for all union values
217 { 217 {
218 if (fDataIsAnim) 218 if (fDataIsAnim)
219 delete fData.fAnim; 219 delete fData.fAnim;
220 else 220 else
221 delete fData.fBitmap; 221 delete fData.fBitmap;
222 222
223 fData.fAnim = NULL; // valid for all union values 223 fData.fAnim = nullptr; // valid for all union values
224 return true; 224 return true;
225 } 225 }
226 return false; 226 return false;
227 } 227 }
228 228
229 bool SkImageView::getDataBounds(SkRect* bounds) 229 bool SkImageView::getDataBounds(SkRect* bounds)
230 { 230 {
231 SkASSERT(bounds); 231 SkASSERT(bounds);
232 232
233 if (this->ensureUriIsLoaded()) 233 if (this->ensureUriIsLoaded())
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return false; 293 return false;
294 } 294 }
295 fData.fBitmap = bitmap; 295 fData.fBitmap = bitmap;
296 fDataIsAnim = false; 296 fDataIsAnim = false;
297 #else 297 #else
298 return false; 298 return false;
299 #endif 299 #endif
300 } 300 }
301 return true; 301 return true;
302 } 302 }
OLDNEW
« no previous file with comments | « src/views/animated/SkBorderView.cpp ('k') | src/views/animated/SkProgressBarView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698