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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp

Issue 2667363004: Fix the painting of document markers under zoom and variable DPI (Closed)
Patch Set: New baselines Created 3 years, 10 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 | « third_party/WebKit/Source/platform/graphics/GraphicsContext.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 (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 drawRect(r1, fillPaint); 502 drawRect(r1, fillPaint);
503 drawRect(r2, fillPaint); 503 drawRect(r2, fillPaint);
504 } 504 }
505 505
506 adjustLineToPixelBoundaries(p1, p2, width, penStyle); 506 adjustLineToPixelBoundaries(p1, p2, width, penStyle);
507 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), paint); 507 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), paint);
508 } 508 }
509 509
510 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, 510 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt,
511 float width, 511 float width,
512 DocumentMarkerLineStyle style) { 512 DocumentMarkerLineStyle style,
513 float zoom) {
513 if (contextDisabled()) 514 if (contextDisabled())
514 return; 515 return;
515 516
516 // Use 2x resources for a device scale factor of 1.5 or above. 517 // Use 2x resources for a device scale factor of 1.5 or above.
518 // This modifes the bitmaps used for the marker, not the overall
519 // scaling of the marker.
517 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1; 520 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1;
518 521
519 // Create the pattern we'll use to draw the underline. 522 // Create the pattern we'll use to draw the underline.
520 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0; 523 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0;
521 static SkBitmap* misspellBitmap1x[2] = {0, 0}; 524 static SkBitmap* misspellBitmap1x[2] = {0, 0};
522 static SkBitmap* misspellBitmap2x[2] = {0, 0}; 525 static SkBitmap* misspellBitmap2x[2] = {0, 0};
523 SkBitmap** misspellBitmap = 526 SkBitmap** misspellBitmap =
524 deviceScaleFactor == 2 ? misspellBitmap2x : misspellBitmap1x; 527 deviceScaleFactor == 2 ? misspellBitmap2x : misspellBitmap1x;
f(malita) 2017/02/03 15:53:55 Looks like we're not taking |zoom| into account wh
Stephen Chennney 2017/02/03 16:27:45 That's a good idea. I'll do that. I also thought
525 if (!misspellBitmap[index]) { 528 if (!misspellBitmap[index]) {
526 #if OS(MACOSX) 529 #if OS(MACOSX)
527 // Match the artwork used by the Mac. 530 // Match the artwork used by the Mac.
528 const int rowPixels = 4 * deviceScaleFactor; 531 const int rowPixels = 4 * deviceScaleFactor;
529 const int colPixels = 3 * deviceScaleFactor; 532 const int colPixels = 3 * deviceScaleFactor;
530 SkBitmap bitmap; 533 SkBitmap bitmap;
531 if (!bitmap.tryAllocN32Pixels(rowPixels, colPixels)) 534 if (!bitmap.tryAllocN32Pixels(rowPixels, colPixels))
532 return; 535 return;
533 536
534 bitmap.eraseARGB(0, 0, 0, 0); 537 bitmap.eraseARGB(0, 0, 0, 0);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 row[5] = colors[index][x * 3]; 580 row[5] = colors[index][x * 3];
578 row[6] = transparentColor; 581 row[6] = transparentColor;
579 row[7] = transparentColor; 582 row[7] = transparentColor;
580 } 583 }
581 } else 584 } else
582 ASSERT_NOT_REACHED(); 585 ASSERT_NOT_REACHED();
583 586
584 misspellBitmap[index] = new SkBitmap(bitmap); 587 misspellBitmap[index] = new SkBitmap(bitmap);
585 #else 588 #else
586 // We use a 2-pixel-high misspelling indicator because that seems to be 589 // We use a 2-pixel-high misspelling indicator because that seems to be
587 // what WebKit is designed for, and how much room there is in a typical 590 // what Blink is designed for, and how much room there is in a typical
588 // page for it. 591 // page for it.
589 const int rowPixels = 592 const int rowPixels =
590 32 * deviceScaleFactor; // Must be multiple of 4 for pattern below. 593 32 * deviceScaleFactor; // Must be multiple of 4 for pattern below.
591 const int colPixels = 2 * deviceScaleFactor; 594 const int colPixels = 2 * deviceScaleFactor;
592 SkBitmap bitmap; 595 SkBitmap bitmap;
593 if (!bitmap.tryAllocN32Pixels(rowPixels, colPixels)) 596 if (!bitmap.tryAllocN32Pixels(rowPixels, colPixels))
594 return; 597 return;
595 598
596 bitmap.eraseARGB(0, 0, 0, 0); 599 bitmap.eraseARGB(0, 0, 0, 0);
597 if (deviceScaleFactor == 1) 600 if (deviceScaleFactor == 1)
598 draw1xMarker(&bitmap, index); 601 draw1xMarker(&bitmap, index);
599 else if (deviceScaleFactor == 2) 602 else if (deviceScaleFactor == 2)
600 draw2xMarker(&bitmap, index); 603 draw2xMarker(&bitmap, index);
601 else 604 else
602 ASSERT_NOT_REACHED(); 605 ASSERT_NOT_REACHED();
603 606
604 misspellBitmap[index] = new SkBitmap(bitmap); 607 misspellBitmap[index] = new SkBitmap(bitmap);
605 #endif 608 #endif
606 } 609 }
607 610
608 #if OS(MACOSX) 611 #if OS(MACOSX)
609 SkScalar originX = WebCoreFloatToSkScalar(pt.x()) * deviceScaleFactor; 612 // Position already includes zoom and device scale factor.
610 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) * deviceScaleFactor; 613 SkScalar originX = WebCoreFloatToSkScalar(pt.x());
614 SkScalar originY = WebCoreFloatToSkScalar(pt.y());
611 615
612 // Make sure to draw only complete dots. 616 // Make sure to draw only complete dots, and finish inside the marked text.
613 int rowPixels = misspellBitmap[index]->width(); 617 float rowPixels = misspellBitmap[index]->width() * zoom / deviceScaleFactor;
614 float widthMod = fmodf(width * deviceScaleFactor, rowPixels); 618 float dotCount = floor(width / rowPixels);
615 if (rowPixels - widthMod > deviceScaleFactor) 619 width = dotCount * rowPixels;
616 width -= widthMod / deviceScaleFactor;
617 #else 620 #else
618 SkScalar originX = WebCoreFloatToSkScalar(pt.x()); 621 SkScalar originX = WebCoreFloatToSkScalar(pt.x());
619 622
620 // Offset it vertically by 1 so that there's some space under the text. 623 // Offset it vertically by 1 so that there's some space under the text.
621 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1; 624 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1;
622 originX *= deviceScaleFactor;
623 originY *= deviceScaleFactor;
624 #endif 625 #endif
625 626
626 SkMatrix localMatrix; 627 SkMatrix localMatrix;
627 localMatrix.setTranslate(originX, originY); 628 localMatrix.setScale(zoom / deviceScaleFactor, zoom / deviceScaleFactor);
629 localMatrix.postTranslate(originX, originY);
628 630
629 SkPaint paint; 631 SkPaint paint;
630 paint.setShader(SkShader::MakeBitmapShader( 632 paint.setShader(SkShader::MakeBitmapShader(
631 *misspellBitmap[index], SkShader::kRepeat_TileMode, 633 *misspellBitmap[index], SkShader::kRepeat_TileMode,
632 SkShader::kRepeat_TileMode, &localMatrix)); 634 SkShader::kRepeat_TileMode, &localMatrix));
633 635
634 SkRect rect; 636 SkRect rect;
635 rect.set(originX, originY, 637 rect.set(
636 originX + WebCoreFloatToSkScalar(width) * deviceScaleFactor, 638 originX, originY, originX + WebCoreFloatToSkScalar(width),
637 originY + SkIntToScalar(misspellBitmap[index]->height())); 639 originY +
640 SkIntToScalar(misspellBitmap[index]->height() / deviceScaleFactor) *
641 zoom);
638 642
639 if (deviceScaleFactor == 2) {
640 save();
641 scale(0.5, 0.5);
642 }
643 drawRect(rect, paint); 643 drawRect(rect, paint);
644 if (deviceScaleFactor == 2)
645 restore();
646 } 644 }
647 645
648 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { 646 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) {
649 if (contextDisabled()) 647 if (contextDisabled())
650 return; 648 return;
651 649
652 if (width <= 0) 650 if (width <= 0)
653 return; 651 return;
654 652
655 SkPaint paint; 653 SkPaint paint;
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 static const SkPMColor colors[] = { 1412 static const SkPMColor colors[] = {
1415 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1413 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1416 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1414 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1417 }; 1415 };
1418 1416
1419 return colors[index]; 1417 return colors[index];
1420 } 1418 }
1421 #endif 1419 #endif
1422 1420
1423 } // namespace blink 1421 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/GraphicsContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698