Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 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 "Viewer.h" | 8 #include "Viewer.h" |
| 9 | 9 |
| 10 #include "GMSlide.h" | 10 #include "GMSlide.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 void Viewer::updateTitle() { | 183 void Viewer::updateTitle() { |
| 184 SkString title("Viewer: "); | 184 SkString title("Viewer: "); |
| 185 title.append(fSlides[fCurrentSlide]->getName()); | 185 title.append(fSlides[fCurrentSlide]->getName()); |
| 186 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { | 186 if (kSRGB_SkColorProfileType == fWindow->getDisplayParams().fProfileType) { |
| 187 title.append(" sRGB"); | 187 title.append(" sRGB"); |
| 188 } | 188 } |
| 189 fWindow->setTitle(title.c_str()); | 189 fWindow->setTitle(title.c_str()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void Viewer::setupCurrentSlide(int previousSlide) { | 192 void Viewer::setupCurrentSlide(int previousSlide) { |
| 193 fGesture.reset(); | |
| 194 fOffsetMatrix.reset(); | |
| 195 fPreTouchMatrix.reset(); | |
| 193 this->updateTitle(); | 196 this->updateTitle(); |
| 194 fSlides[fCurrentSlide]->load(); | 197 fSlides[fCurrentSlide]->load(); |
| 195 if (previousSlide >= 0) { | 198 if (previousSlide >= 0) { |
| 196 fSlides[previousSlide]->unload(); | 199 fSlides[previousSlide]->unload(); |
| 197 } | 200 } |
| 198 fWindow->inval(); | 201 fWindow->inval(); |
| 199 } | 202 } |
| 200 | 203 |
| 201 #define MAX_ZOOM_LEVEL 8 | 204 #define MAX_ZOOM_LEVEL 8 |
| 202 #define MIN_ZOOM_LEVEL -8 | 205 #define MIN_ZOOM_LEVEL -8 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 223 //m = this->getLocalMatrix();//.invert(&m); | 226 //m = this->getLocalMatrix();//.invert(&m); |
| 224 m.mapXY(fZoomCenterX, fZoomCenterY, ¢er); | 227 m.mapXY(fZoomCenterX, fZoomCenterY, ¢er); |
| 225 SkScalar cx = center.fX; | 228 SkScalar cx = center.fX; |
| 226 SkScalar cy = center.fY; | 229 SkScalar cy = center.fY; |
| 227 | 230 |
| 228 m.setTranslate(-cx, -cy); | 231 m.setTranslate(-cx, -cy); |
| 229 m.postScale(fZoomScale, fZoomScale); | 232 m.postScale(fZoomScale, fZoomScale); |
| 230 m.postTranslate(cx, cy); | 233 m.postTranslate(cx, cy); |
| 231 } | 234 } |
| 232 | 235 |
| 233 m.preConcat(fGesture.localM()); | 236 SkMatrix touchMatrixWithOffset; |
|
djsollen
2016/05/19 17:04:23
I think you can do this computation by just applyi
liyuqian
2016/05/19 19:23:15
Done.
| |
| 234 m.preConcat(fGesture.globalM()); | 237 touchMatrixWithOffset.reset(); |
| 238 touchMatrixWithOffset.postConcat(fGesture.globalM()); | |
| 239 touchMatrixWithOffset.postConcat(fGesture.localM()); | |
| 240 if (touchMatrixWithOffset.isIdentity()) { | |
| 241 // The touch gesture has reset the matrix, so we reset the offset too. | |
| 242 fOffsetMatrix.reset(); | |
| 243 } | |
| 244 touchMatrixWithOffset.preConcat(fOffsetMatrix); | |
| 245 | |
| 246 // Begin checking if more offset is needed | |
| 247 | |
| 248 const SkScalar scaleX = touchMatrixWithOffset.getScaleX(); | |
| 249 const SkScalar scaleY = touchMatrixWithOffset.getScaleY(); | |
| 250 // Bring the X/Y translation to the slide's scale | |
| 251 const SkScalar tX = touchMatrixWithOffset.getTranslateX() / scaleX; | |
| 252 const SkScalar tY = touchMatrixWithOffset.getTranslateY() / scaleY; | |
| 253 | |
| 254 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); | |
| 255 const SkScalar SW = slideSize.width(), SH = slideSize.height(), ZERO = 0; | |
| 256 | |
| 257 // Bring contentRect's widht/height to the slide's scale | |
| 258 const SkRect contentRect = fWindow->getContentRect(); | |
|
djsollen
2016/05/19 17:04:23
on windows that don't return true for supportsCont
liyuqian
2016/05/19 19:23:15
Done.
| |
| 259 const SkScalar CW = contentRect.width() / fPreTouchMatrix.getScaleX() / scal eX; | |
| 260 const SkScalar CH = contentRect.height() / fPreTouchMatrix.getScaleY() / sca leY; | |
| 261 | |
| 262 // X Translation could be no less than -SW and no more than CW | |
| 263 const SkScalar overX = std::min(ZERO, tX + SW) + std::max(ZERO, tX - CW); | |
| 264 // Y Translation is similar to the X translation | |
| 265 const SkScalar overY = std::min(ZERO, tY + SH) + std::max(ZERO, tY - CH); | |
| 266 | |
| 267 // Apply additional offset | |
| 268 fOffsetMatrix.preTranslate(-overX * scaleX, -overY * scaleY); | |
| 269 touchMatrixWithOffset.preTranslate(-overX * scaleX, -overY * scaleY); | |
| 270 | |
| 271 // Finished checking offset | |
| 272 | |
| 273 m.preConcat(touchMatrixWithOffset); | |
| 235 | 274 |
| 236 return m; | 275 return m; |
| 237 } | 276 } |
| 238 | 277 |
| 239 void Viewer::onPaint(SkCanvas* canvas) { | 278 void Viewer::onPaint(SkCanvas* canvas) { |
| 240 | 279 |
| 241 int count = canvas->save(); | 280 int count = canvas->save(); |
| 242 | 281 |
| 243 if (fWindow->supportsContentRect()) { | 282 if (fWindow->supportsContentRect()) { |
| 244 SkRect contentRect = fWindow->getContentRect(); | 283 SkRect contentRect = fWindow->getContentRect(); |
| 245 canvas->clipRect(contentRect); | 284 canvas->clipRect(contentRect); |
| 246 canvas->translate(contentRect.fLeft, contentRect.fTop); | 285 canvas->translate(contentRect.fLeft, contentRect.fTop); |
| 247 } | 286 } |
| 248 | 287 |
| 249 canvas->clear(SK_ColorWHITE); | 288 canvas->clear(SK_ColorWHITE); |
| 250 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { | 289 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { |
| 251 const SkRect contentRect = fWindow->getContentRect(); | 290 const SkRect contentRect = fWindow->getContentRect(); |
| 252 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); | 291 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 253 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize. height()); | 292 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize. height()); |
| 254 SkMatrix matrix; | 293 SkMatrix matrix; |
| 255 matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleTo Fit); | 294 matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kStart_ScaleToF it); |
| 256 canvas->concat(matrix); | 295 canvas->concat(matrix); |
| 296 fPreTouchMatrix = matrix; | |
| 257 } | 297 } |
| 258 canvas->concat(computeMatrix()); | 298 canvas->concat(computeMatrix()); |
| 259 | 299 |
| 260 fSlides[fCurrentSlide]->draw(canvas); | 300 fSlides[fCurrentSlide]->draw(canvas); |
| 261 canvas->restoreToCount(count); | 301 canvas->restoreToCount(count); |
| 262 | 302 |
| 263 if (fDisplayStats) { | 303 if (fDisplayStats) { |
| 264 drawStats(canvas); | 304 drawStats(canvas); |
| 265 } | 305 } |
| 266 fCommands.drawHelp(canvas); | 306 fCommands.drawHelp(canvas); |
| 267 } | 307 } |
| 268 | 308 |
| 269 bool Viewer::onTouch(int owner, Window::InputState state, float x, float y) { | 309 bool Viewer::onTouch(int owner, Window::InputState state, float x, float y) { |
| 270 void* castedOwner = reinterpret_cast<void*>(owner); | 310 void* castedOwner = reinterpret_cast<void*>(owner); |
| 311 float castedX = (x - fPreTouchMatrix.getTranslateX()) / fPreTouchMatrix.getS caleX(); | |
| 312 float castedY = (y - fPreTouchMatrix.getTranslateY()) / fPreTouchMatrix.getS caleY(); | |
|
djsollen
2016/05/19 17:04:23
SkPoint touchPoint = SkPoint::Make(x, y);
SkMatrix
liyuqian
2016/05/19 19:23:15
Done.
| |
| 271 switch (state) { | 313 switch (state) { |
| 272 case Window::kUp_InputState: { | 314 case Window::kUp_InputState: { |
| 273 fGesture.touchEnd(castedOwner); | 315 fGesture.touchEnd(castedOwner); |
| 274 break; | 316 break; |
| 275 } | 317 } |
| 276 case Window::kDown_InputState: { | 318 case Window::kDown_InputState: { |
| 277 fGesture.touchBegin(castedOwner, x, y); | 319 fGesture.touchBegin(castedOwner, castedX, castedY); |
| 278 break; | 320 break; |
| 279 } | 321 } |
| 280 case Window::kMove_InputState: { | 322 case Window::kMove_InputState: { |
| 281 fGesture.touchMoved(castedOwner, x, y); | 323 fGesture.touchMoved(castedOwner, castedX, castedY); |
| 282 break; | 324 break; |
| 283 } | 325 } |
| 284 } | 326 } |
| 285 fWindow->inval(); | 327 fWindow->inval(); |
| 286 return true; | 328 return true; |
| 287 } | 329 } |
| 288 | 330 |
| 289 void Viewer::drawStats(SkCanvas* canvas) { | 331 void Viewer::drawStats(SkCanvas* canvas) { |
| 290 static const float kPixelPerMS = 2.0f; | 332 static const float kPixelPerMS = 2.0f; |
| 291 static const int kDisplayWidth = 130; | 333 static const int kDisplayWidth = 130; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 // Record measurements | 380 // Record measurements |
| 339 fMeasurements[fCurrentMeasurement++] = ms; | 381 fMeasurements[fCurrentMeasurement++] = ms; |
| 340 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod | 382 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
| 341 SkASSERT(fCurrentMeasurement < kMeasurementCount); | 383 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
| 342 | 384 |
| 343 fAnimTimer.updateTime(); | 385 fAnimTimer.updateTime(); |
| 344 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { | 386 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { |
| 345 fWindow->inval(); | 387 fWindow->inval(); |
| 346 } | 388 } |
| 347 } | 389 } |
| OLD | NEW |