OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
9 | 9 |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 254 } |
255 | 255 |
256 void SkDebugCanvas::toggleFilter(bool toggle) { | 256 void SkDebugCanvas::toggleFilter(bool toggle) { |
257 fFilter = toggle; | 257 fFilter = toggle; |
258 } | 258 } |
259 | 259 |
260 void SkDebugCanvas::clear(SkColor color) { | 260 void SkDebugCanvas::clear(SkColor color) { |
261 addDrawCommand(new Clear(color)); | 261 addDrawCommand(new Clear(color)); |
262 } | 262 } |
263 | 263 |
264 static SkBitmap createBitmap(const SkPath& path) { | |
265 SkBitmap bitmap; | |
266 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
267 SkDebugCanvas::kVizImageWidth, | |
268 SkDebugCanvas::kVizImageHeight); | |
269 bitmap.allocPixels(); | |
270 bitmap.eraseColor(SK_ColorWHITE); | |
271 SkDevice* device = new SkDevice(bitmap); | |
272 | |
273 SkCanvas canvas(device); | |
274 device->unref(); | |
275 | |
276 const SkRect& bounds = path.getBounds(); | |
277 | |
278 if (bounds.width() > bounds.height()) { | |
279 canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds
.width()), | |
280 SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bound
s.width())); | |
281 } else { | |
282 canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds
.height()), | |
283 SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bound
s.height())); | |
284 } | |
285 canvas.translate(-bounds.fLeft+2, -bounds.fTop+2); | |
286 | |
287 SkPaint p; | |
288 p.setColor(SK_ColorBLACK); | |
289 p.setStyle(SkPaint::kStroke_Style); | |
290 | |
291 canvas.drawPath(path, p); | |
292 | |
293 return bitmap; | |
294 } | |
295 | |
296 static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) { | |
297 SkBitmap bitmap; | |
298 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
299 SkDebugCanvas::kVizImageWidth, | |
300 SkDebugCanvas::kVizImageHeight); | |
301 bitmap.allocPixels(); | |
302 bitmap.eraseColor(SK_ColorLTGRAY); | |
303 SkDevice* device = new SkDevice(bitmap); | |
304 | |
305 SkCanvas canvas(device); | |
306 device->unref(); | |
307 | |
308 SkScalar xScale = SkIntToScalar(SkDebugCanvas::kVizImageWidth-2) / input.wid
th(); | |
309 SkScalar yScale = SkIntToScalar(SkDebugCanvas::kVizImageHeight-2) / input.he
ight(); | |
310 | |
311 if (input.width() > input.height()) { | |
312 yScale *= input.height() / (float) input.width(); | |
313 } else { | |
314 xScale *= input.width() / (float) input.height(); | |
315 } | |
316 | |
317 SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1, | |
318 xScale * input.width(), | |
319 yScale * input.height()); | |
320 | |
321 canvas.drawBitmapRect(input, NULL, dst); | |
322 | |
323 if (NULL != srcRect) { | |
324 SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1, | |
325 srcRect->fTop * yScale + SK_Scalar1, | |
326 srcRect->fRight * xScale + SK_Scalar1, | |
327 srcRect->fBottom * yScale + SK_Scalar1); | |
328 SkPaint p; | |
329 p.setColor(SK_ColorRED); | |
330 p.setStyle(SkPaint::kStroke_Style); | |
331 | |
332 canvas.drawRect(r, p); | |
333 } | |
334 | |
335 return bitmap; | |
336 } | |
337 | |
338 bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { | 264 bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
339 SkBitmap bitmap = createBitmap(path); | 265 addDrawCommand(new ClipPath(path, op, doAA)); |
340 addDrawCommand(new ClipPath(path, op, doAA, bitmap)); | |
341 return true; | 266 return true; |
342 } | 267 } |
343 | 268 |
344 bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { | 269 bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
345 addDrawCommand(new ClipRect(rect, op, doAA)); | 270 addDrawCommand(new ClipRect(rect, op, doAA)); |
346 return true; | 271 return true; |
347 } | 272 } |
348 | 273 |
349 bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA)
{ | 274 bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA)
{ |
350 addDrawCommand(new ClipRRect(rrect, op, doAA)); | 275 addDrawCommand(new ClipRRect(rrect, op, doAA)); |
351 return true; | 276 return true; |
352 } | 277 } |
353 | 278 |
354 bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) { | 279 bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) { |
355 addDrawCommand(new ClipRegion(region, op)); | 280 addDrawCommand(new ClipRegion(region, op)); |
356 return true; | 281 return true; |
357 } | 282 } |
358 | 283 |
359 bool SkDebugCanvas::concat(const SkMatrix& matrix) { | 284 bool SkDebugCanvas::concat(const SkMatrix& matrix) { |
360 addDrawCommand(new Concat(matrix)); | 285 addDrawCommand(new Concat(matrix)); |
361 return true; | 286 return true; |
362 } | 287 } |
363 | 288 |
364 void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, | 289 void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, |
365 SkScalar top, const SkPaint* paint = NULL) { | 290 SkScalar top, const SkPaint* paint = NULL) { |
366 SkBitmap resizedBitmap = createBitmap(bitmap, NULL); | 291 addDrawCommand(new DrawBitmap(bitmap, left, top, paint)); |
367 addDrawCommand(new DrawBitmap(bitmap, left, top, paint, resizedBitmap)); | |
368 } | 292 } |
369 | 293 |
370 void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, | 294 void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, |
371 const SkRect* src, const SkRect& dst, const SkPaint* paint) { | 295 const SkRect* src, const SkRect& dst, const SkPaint* paint) { |
372 SkBitmap resizedBitmap = createBitmap(bitmap, src); | 296 addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint)); |
373 addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint, resizedBitmap)); | |
374 } | 297 } |
375 | 298 |
376 void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap, | 299 void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap, |
377 const SkMatrix& matrix, const SkPaint* paint) { | 300 const SkMatrix& matrix, const SkPaint* paint) { |
378 SkBitmap resizedBitmap = createBitmap(bitmap, NULL); | 301 addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint)); |
379 addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint, resizedBitmap)); | |
380 } | 302 } |
381 | 303 |
382 void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap, | 304 void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap, |
383 const SkIRect& center, const SkRect& dst, const SkPaint* paint) { | 305 const SkIRect& center, const SkRect& dst, const SkPaint* paint) { |
384 SkBitmap resizedBitmap = createBitmap(bitmap, NULL); | 306 addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint)); |
385 addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint, resizedBitmap)
); | |
386 } | 307 } |
387 | 308 |
388 void SkDebugCanvas::drawData(const void* data, size_t length) { | 309 void SkDebugCanvas::drawData(const void* data, size_t length) { |
389 addDrawCommand(new DrawData(data, length)); | 310 addDrawCommand(new DrawData(data, length)); |
390 } | 311 } |
391 | 312 |
392 void SkDebugCanvas::beginCommentGroup(const char* description) { | 313 void SkDebugCanvas::beginCommentGroup(const char* description) { |
393 addDrawCommand(new BeginCommentGroup(description)); | 314 addDrawCommand(new BeginCommentGroup(description)); |
394 } | 315 } |
395 | 316 |
396 void SkDebugCanvas::addComment(const char* kywd, const char* value) { | 317 void SkDebugCanvas::addComment(const char* kywd, const char* value) { |
397 addDrawCommand(new Comment(kywd, value)); | 318 addDrawCommand(new Comment(kywd, value)); |
398 } | 319 } |
399 | 320 |
400 void SkDebugCanvas::endCommentGroup() { | 321 void SkDebugCanvas::endCommentGroup() { |
401 addDrawCommand(new EndCommentGroup()); | 322 addDrawCommand(new EndCommentGroup()); |
402 } | 323 } |
403 | 324 |
404 void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { | 325 void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
405 addDrawCommand(new DrawOval(oval, paint)); | 326 addDrawCommand(new DrawOval(oval, paint)); |
406 } | 327 } |
407 | 328 |
408 void SkDebugCanvas::drawPaint(const SkPaint& paint) { | 329 void SkDebugCanvas::drawPaint(const SkPaint& paint) { |
409 addDrawCommand(new DrawPaint(paint)); | 330 addDrawCommand(new DrawPaint(paint)); |
410 } | 331 } |
411 | 332 |
412 void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 333 void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
413 SkBitmap bitmap = createBitmap(path); | 334 addDrawCommand(new DrawPath(path, paint)); |
414 addDrawCommand(new DrawPath(path, paint, bitmap)); | |
415 } | 335 } |
416 | 336 |
417 void SkDebugCanvas::drawPicture(SkPicture& picture) { | 337 void SkDebugCanvas::drawPicture(SkPicture& picture) { |
418 addDrawCommand(new DrawPicture(picture)); | 338 addDrawCommand(new DrawPicture(picture)); |
419 } | 339 } |
420 | 340 |
421 void SkDebugCanvas::drawPoints(PointMode mode, size_t count, | 341 void SkDebugCanvas::drawPoints(PointMode mode, size_t count, |
422 const SkPoint pts[], const SkPaint& paint) { | 342 const SkPoint pts[], const SkPaint& paint) { |
423 addDrawCommand(new DrawPoints(mode, count, pts, paint)); | 343 addDrawCommand(new DrawPoints(mode, count, pts, paint)); |
424 } | 344 } |
(...skipping 11 matching lines...) Expand all Loading... |
436 void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { | 356 void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
437 // NOTE(chudy): Messing up when renamed to DrawRect... Why? | 357 // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
438 addDrawCommand(new DrawRectC(rect, paint)); | 358 addDrawCommand(new DrawRectC(rect, paint)); |
439 } | 359 } |
440 | 360 |
441 void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 361 void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
442 addDrawCommand(new DrawRRect(rrect, paint)); | 362 addDrawCommand(new DrawRRect(rrect, paint)); |
443 } | 363 } |
444 | 364 |
445 void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, | 365 void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, |
446 const SkPaint* paint = NULL) { | 366 const SkPaint* paint = NULL) { |
447 SkBitmap resizedBitmap = createBitmap(bitmap, NULL); | 367 addDrawCommand(new DrawSprite(bitmap, left, top, paint)); |
448 addDrawCommand(new DrawSprite(bitmap, left, top, paint, resizedBitmap)); | |
449 } | 368 } |
450 | 369 |
451 void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x, | 370 void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
452 SkScalar y, const SkPaint& paint) { | 371 SkScalar y, const SkPaint& paint) { |
453 addDrawCommand(new DrawTextC(text, byteLength, x, y, paint)); | 372 addDrawCommand(new DrawTextC(text, byteLength, x, y, paint)); |
454 } | 373 } |
455 | 374 |
456 void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength, | 375 void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength, |
457 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { | 376 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { |
458 addDrawCommand(new DrawTextOnPath(text, byteLength, path, matrix, paint)); | 377 addDrawCommand(new DrawTextOnPath(text, byteLength, path, matrix, paint)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 421 |
503 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { | 422 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
504 addDrawCommand(new Translate(dx, dy)); | 423 addDrawCommand(new Translate(dx, dy)); |
505 return true; | 424 return true; |
506 } | 425 } |
507 | 426 |
508 void SkDebugCanvas::toggleCommand(int index, bool toggle) { | 427 void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
509 SkASSERT(index < fCommandVector.count()); | 428 SkASSERT(index < fCommandVector.count()); |
510 fCommandVector[index]->setVisible(toggle); | 429 fCommandVector[index]->setVisible(toggle); |
511 } | 430 } |
OLD | NEW |