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

Side by Side Diff: tools/filtermain.cpp

Issue 12918029: New filter targeted at desk_googlespreadsheet overdraw issues (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Handle some corner cases Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « debugger/SkDrawCommand.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 2012 Google Inc. 2 * Copyright 2012 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 "SkDebugCanvas.h" 8 #include "SkDebugCanvas.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 return SK_Scalar1 == s->x() && SK_Scalar1 == s->y(); 313 return SK_Scalar1 == s->x() && SK_Scalar1 == s->y();
314 } 314 }
315 315
316 // Just remove the scale 316 // Just remove the scale
317 static void apply_6(SkTDArray<SkDrawCommand*>& commands, int curCommand) { 317 static void apply_6(SkTDArray<SkDrawCommand*>& commands, int curCommand) {
318 Scale* s = (Scale*) commands[curCommand]; 318 Scale* s = (Scale*) commands[curCommand];
319 319
320 s->setVisible(false); 320 s->setVisible(false);
321 } 321 }
322 322
323 // Check for:
324 // SAVE
325 // CLIP_RECT
326 // SAVE_LAYER
327 // SAVE
328 // CLIP_RECT
329 // SAVE_LAYER
330 // SAVE
331 // CLIP_RECT
332 // DRAWBITMAPRECTTORECT
333 // RESTORE
334 // RESTORE
335 // RESTORE
336 // RESTORE
337 // RESTORE
338 // where:
339 // all the clipRect's are BW, nested, intersections
340 // the drawBitmapRectToRect is a 1-1 copy from src to dest
341 // the last (smallest) clip rect is a subset of the drawBitmapRectToRect's dest rect
342 // all the saveLayer's paints can be rolled into the drawBitmapRectToRect's paint
343 // This pattern is used by Google spreadsheet when drawing the toolbar buttons
344 static bool check_7(const SkTDArray<SkDrawCommand*>& commands, int curCommand) {
345 if (SAVE != commands[curCommand]->getType() ||
346 commands.count() <= curCommand+13 ||
347 CLIP_RECT != commands[curCommand+1]->getType() ||
348 SAVE_LAYER != commands[curCommand+2]->getType() ||
349 SAVE != commands[curCommand+3]->getType() ||
350 CLIP_RECT != commands[curCommand+4]->getType() ||
351 SAVE_LAYER != commands[curCommand+5]->getType() ||
352 SAVE != commands[curCommand+6]->getType() ||
353 CLIP_RECT != commands[curCommand+7]->getType() ||
354 DRAW_BITMAP_RECT_TO_RECT != commands[curCommand+8]->getType() ||
355 RESTORE != commands[curCommand+9]->getType() ||
356 RESTORE != commands[curCommand+10]->getType() ||
357 RESTORE != commands[curCommand+11]->getType() ||
358 RESTORE != commands[curCommand+12]->getType() ||
359 RESTORE != commands[curCommand+13]->getType())
360 return false;
361
362 ClipRect* clip0 = (ClipRect*) commands[curCommand+1];
363 SaveLayer* saveLayer0 = (SaveLayer*) commands[curCommand+2];
364 ClipRect* clip1 = (ClipRect*) commands[curCommand+4];
365 SaveLayer* saveLayer1 = (SaveLayer*) commands[curCommand+5];
366 ClipRect* clip2 = (ClipRect*) commands[curCommand+7];
367 DrawBitmapRect* dbmr = (DrawBitmapRect*) commands[curCommand+8];
368
369 if (clip0->doAA() || clip1->doAA() || clip2->doAA()) {
370 return false;
371 }
372
373 if (SkRegion::kIntersect_Op != clip0->op() ||
374 SkRegion::kIntersect_Op != clip1->op() ||
375 SkRegion::kIntersect_Op != clip2->op()) {
376 return false;
377 }
378
379 if (!clip0->rect().contains(clip1->rect()) ||
380 !clip1->rect().contains(clip2->rect())) {
381 return false;
382 }
383
384 // The src->dest mapping needs to be 1-to-1
385 if (NULL == dbmr->srcRect()) {
386 if (dbmr->bitmap().width() != dbmr->dstRect().width() ||
387 dbmr->bitmap().height() != dbmr->dstRect().height()) {
388 return false;
389 }
390 } else {
391 if (dbmr->srcRect()->width() != dbmr->dstRect().width() ||
392 dbmr->srcRect()->height() != dbmr->dstRect().height()) {
393 return false;
394 }
395 }
396
397 if (!dbmr->dstRect().contains(clip2->rect())) {
398 return false;
399 }
400
401 const SkPaint* saveLayerPaint0 = saveLayer0->paint();
402 const SkPaint* saveLayerPaint1 = saveLayer1->paint();
403
404 if ((NULL != saveLayerPaint0 && !is_simple(*saveLayerPaint0)) ||
405 (NULL != saveLayerPaint1 && !is_simple(*saveLayerPaint1))) {
406 return false;
407 }
408
409 SkPaint* dbmrPaint = dbmr->paint();
410
411 if (NULL == dbmrPaint) {
412 return true;
413 }
414
415 if (NULL != saveLayerPaint0) {
416 SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force opaque
417 if (dbmrPaint->getColor() != layerColor0) {
418 return false;
419 }
420 }
421
422 if (NULL != saveLayerPaint1) {
423 SkColor layerColor1 = saveLayerPaint1->getColor() | 0xFF000000; // force opaque
424 if (dbmrPaint->getColor() != layerColor1) {
425 return false;
426 }
427 }
428
429 return true;
430 }
431
432 // Reduce to a single drawBitmapRectToRect call by folding the clipRect's into
433 // the src and dst Rects and the saveLayer paints into the drawBitmapRectToRect' s
434 // paint.
435 static void apply_7(SkTDArray<SkDrawCommand*>& commands, int curCommand) {
436 Save* save0 = (Save*) commands[curCommand];
437 ClipRect* clip0 = (ClipRect*) commands[curCommand+1];
438 SaveLayer* saveLayer0 = (SaveLayer*) commands[curCommand+2];
439 Save* save1 = (Save*) commands[curCommand+3];
440 ClipRect* clip1 = (ClipRect*) commands[curCommand+4];
441 SaveLayer* saveLayer1 = (SaveLayer*) commands[curCommand+5];
442 Save* save2 = (Save*) commands[curCommand+6];
443 ClipRect* clip2 = (ClipRect*) commands[curCommand+7];
444 DrawBitmapRect* dbmr = (DrawBitmapRect*) commands[curCommand+8];
445 Restore* restore0 = (Restore*) commands[curCommand+9];
446 Restore* restore1 = (Restore*) commands[curCommand+10];
447 Restore* restore2 = (Restore*) commands[curCommand+11];
448 Restore* restore3 = (Restore*) commands[curCommand+12];
449 Restore* restore4 = (Restore*) commands[curCommand+13];
450
451 SkScalar newSrcLeft = dbmr->srcRect()->fLeft + clip2->rect().fLeft - dbmr->d stRect().fLeft;
452 SkScalar newSrcTop = dbmr->srcRect()->fTop + clip2->rect().fTop - dbmr->dstR ect().fTop;
453
454 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop,
455 clip2->rect().width(), clip2->rect().height ());
456
457 dbmr->setSrcRect(newSrc);
458 dbmr->setDstRect(clip2->rect());
459
460 SkColor color = 0xFF000000;
461 int a0, a1;
462
463 const SkPaint* saveLayerPaint0 = saveLayer0->paint();
464 if (NULL != saveLayerPaint0) {
465 color = saveLayerPaint0->getColor();
466 a0 = SkColorGetA(color);
467 } else {
468 a0 = 0xFF;
469 }
470
471 const SkPaint* saveLayerPaint1 = saveLayer1->paint();
472 if (NULL != saveLayerPaint1) {
473 color = saveLayerPaint1->getColor();
474 a1 = SkColorGetA(color);
475 } else {
476 a1 = 0xFF;
477 }
478
479 int newA = (a0 * a1) / 255;
480 SkASSERT(newA <= 0xFF);
481
482 SkPaint* dbmrPaint = dbmr->paint();
483
484 if (NULL != dbmrPaint) {
485 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA);
486 dbmrPaint->setColor(newColor);
487 } else {
488 SkColor newColor = SkColorSetA(color, newA);
489
490 SkPaint newPaint;
491 newPaint.setColor(newColor);
492 dbmr->setPaint(newPaint);
493 }
494
495 // remove everything except the drawbitmaprect
496 save0->setVisible(false);
497 clip0->setVisible(false);
498 saveLayer0->setVisible(false);
499 save1->setVisible(false);
500 clip1->setVisible(false);
501 saveLayer1->setVisible(false);
502 save2->setVisible(false);
503 clip2->setVisible(false);
504 restore0->setVisible(false);
505 restore1->setVisible(false);
506 restore2->setVisible(false);
507 restore3->setVisible(false);
508 restore4->setVisible(false);
509 }
323 510
324 typedef bool (*PFCheck)(const SkTDArray<SkDrawCommand*>& commands, int curComman d); 511 typedef bool (*PFCheck)(const SkTDArray<SkDrawCommand*>& commands, int curComman d);
325 typedef void (*PFApply)(SkTDArray<SkDrawCommand*>& commands, int curCommand); 512 typedef void (*PFApply)(SkTDArray<SkDrawCommand*>& commands, int curCommand);
326 513
327 struct OptTableEntry { 514 struct OptTableEntry {
328 PFCheck fCheck; 515 PFCheck fCheck;
329 PFApply fApply; 516 PFApply fApply;
330 int fNumTimesApplied; 517 int fNumTimesApplied;
331 } gOptTable[] = { 518 } gOptTable[] = {
332 { check_0, apply_0, 0 }, 519 { check_0, apply_0, 0 },
333 { check_1, apply_1, 0 }, 520 { check_1, apply_1, 0 },
334 { check_2, apply_2, 0 }, 521 { check_2, apply_2, 0 },
335 { check_3, apply_3, 0 }, 522 { check_3, apply_3, 0 },
336 { check_4, apply_4, 0 }, 523 { check_4, apply_4, 0 },
337 { check_5, apply_5, 0 }, 524 { check_5, apply_5, 0 },
338 { check_6, apply_6, 0 }, 525 { check_6, apply_6, 0 },
526 { check_7, apply_7, 0 },
339 }; 527 };
340 528
341 static int filter_picture(const SkString& inFile, const SkString& outFile) { 529 static int filter_picture(const SkString& inFile, const SkString& outFile) {
342 SkPicture* inPicture = NULL; 530 SkPicture* inPicture = NULL;
343 531
344 SkFILEStream inStream(inFile.c_str()); 532 SkFILEStream inStream(inFile.c_str());
345 if (inStream.isValid()) { 533 if (inStream.isValid()) {
346 inPicture = SkNEW_ARGS(SkPicture, (&inStream, NULL, &SkImageDecoder::Dec odeMemory)); 534 inPicture = SkNEW_ARGS(SkPicture, (&inStream, NULL, &SkImageDecoder::Dec odeMemory));
347 } 535 }
348 536
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 684
497 SkGraphics::Term(); 685 SkGraphics::Term();
498 return 0; 686 return 0;
499 } 687 }
500 688
501 #if !defined SK_BUILD_FOR_IOS 689 #if !defined SK_BUILD_FOR_IOS
502 int main(int argc, char * const argv[]) { 690 int main(int argc, char * const argv[]) {
503 return tool_main(argc, (char**) argv); 691 return tool_main(argc, (char**) argv);
504 } 692 }
505 #endif 693 #endif
OLDNEW
« no previous file with comments | « debugger/SkDrawCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698