| OLD | NEW |
| 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 14 matching lines...) Expand all Loading... |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "platform/graphics/GraphicsContext.h" | 28 #include "platform/graphics/GraphicsContext.h" |
| 29 | 29 |
| 30 #include "platform/TraceEvent.h" | 30 #include "platform/TraceEvent.h" |
| 31 #include "platform/geometry/IntRect.h" | 31 #include "platform/geometry/IntRect.h" |
| 32 #include "platform/graphics/ColorSpace.h" | 32 #include "platform/graphics/ColorSpace.h" |
| 33 #include "platform/graphics/Gradient.h" | 33 #include "platform/graphics/Gradient.h" |
| 34 #include "platform/graphics/ImageBuffer.h" | 34 #include "platform/graphics/ImageBuffer.h" |
| 35 #include "platform/graphics/paint/DisplayItemList.h" | 35 #include "platform/graphics/paint/PaintController.h" |
| 36 #include "platform/weborigin/KURL.h" | 36 #include "platform/weborigin/KURL.h" |
| 37 #include "skia/ext/platform_device.h" | 37 #include "skia/ext/platform_device.h" |
| 38 #include "third_party/skia/include/core/SkAnnotation.h" | 38 #include "third_party/skia/include/core/SkAnnotation.h" |
| 39 #include "third_party/skia/include/core/SkColorFilter.h" | 39 #include "third_party/skia/include/core/SkColorFilter.h" |
| 40 #include "third_party/skia/include/core/SkData.h" | 40 #include "third_party/skia/include/core/SkData.h" |
| 41 #include "third_party/skia/include/core/SkPicture.h" | 41 #include "third_party/skia/include/core/SkPicture.h" |
| 42 #include "third_party/skia/include/core/SkPictureRecorder.h" | 42 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 43 #include "third_party/skia/include/core/SkRRect.h" | 43 #include "third_party/skia/include/core/SkRRect.h" |
| 44 #include "third_party/skia/include/core/SkRefCnt.h" | 44 #include "third_party/skia/include/core/SkRefCnt.h" |
| 45 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 45 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| 46 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 46 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
| 47 #include "third_party/skia/include/utils/SkNullCanvas.h" | 47 #include "third_party/skia/include/utils/SkNullCanvas.h" |
| 48 #include "wtf/Assertions.h" | 48 #include "wtf/Assertions.h" |
| 49 #include "wtf/MathExtras.h" | 49 #include "wtf/MathExtras.h" |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 GraphicsContext::GraphicsContext(DisplayItemList* displayItemList, DisabledMode
disableContextOrPainting, SkMetaData* metaData) | 53 GraphicsContext::GraphicsContext(PaintController* paintController, DisabledMode
disableContextOrPainting, SkMetaData* metaData) |
| 54 : m_canvas(nullptr) | 54 : m_canvas(nullptr) |
| 55 , m_originalCanvas(nullptr) | 55 , m_originalCanvas(nullptr) |
| 56 , m_displayItemList(displayItemList) | 56 , m_paintController(paintController) |
| 57 , m_paintStateStack() | 57 , m_paintStateStack() |
| 58 , m_paintStateIndex(0) | 58 , m_paintStateIndex(0) |
| 59 #if ENABLE(ASSERT) | 59 #if ENABLE(ASSERT) |
| 60 , m_layerCount(0) | 60 , m_layerCount(0) |
| 61 , m_disableDestructionChecks(false) | 61 , m_disableDestructionChecks(false) |
| 62 , m_inDrawingRecorder(false) | 62 , m_inDrawingRecorder(false) |
| 63 #endif | 63 #endif |
| 64 , m_disabledState(disableContextOrPainting) | 64 , m_disabledState(disableContextOrPainting) |
| 65 , m_deviceScaleFactor(1.0f) | 65 , m_deviceScaleFactor(1.0f) |
| 66 , m_printing(false) | 66 , m_printing(false) |
| 67 , m_hasMetaData(!!metaData) | 67 , m_hasMetaData(!!metaData) |
| 68 { | 68 { |
| 69 // TODO(chrishtr): switch the type of the parameter to DisplayItemList&. | 69 // TODO(chrishtr): switch the type of the parameter to PaintController&. |
| 70 ASSERT(displayItemList); | 70 ASSERT(paintController); |
| 71 | 71 |
| 72 if (metaData) | 72 if (metaData) |
| 73 m_metaData = *metaData; | 73 m_metaData = *metaData; |
| 74 | 74 |
| 75 // FIXME: Do some tests to determine how many states are typically used, and
allocate | 75 // FIXME: Do some tests to determine how many states are typically used, and
allocate |
| 76 // several here. | 76 // several here. |
| 77 m_paintStateStack.append(GraphicsContextState::create()); | 77 m_paintStateStack.append(GraphicsContextState::create()); |
| 78 m_paintState = m_paintStateStack.last().get(); | 78 m_paintState = m_paintStateStack.last().get(); |
| 79 | 79 |
| 80 if (contextDisabled()) { | 80 if (contextDisabled()) { |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 drawRect(skRect, paint); | 727 drawRect(skRect, paint); |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 | 730 |
| 731 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point, const SkPaint& paint) | 731 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point, const SkPaint& paint) |
| 732 { | 732 { |
| 733 if (contextDisabled()) | 733 if (contextDisabled()) |
| 734 return; | 734 return; |
| 735 | 735 |
| 736 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint)) | 736 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint)) |
| 737 m_displayItemList->setTextPainted(); | 737 m_paintController->setTextPainted(); |
| 738 } | 738 } |
| 739 | 739 |
| 740 template<typename DrawTextFunc> | 740 template<typename DrawTextFunc> |
| 741 void GraphicsContext::drawTextPasses(const DrawTextFunc& drawText) | 741 void GraphicsContext::drawTextPasses(const DrawTextFunc& drawText) |
| 742 { | 742 { |
| 743 TextDrawingModeFlags modeFlags = textDrawingMode(); | 743 TextDrawingModeFlags modeFlags = textDrawingMode(); |
| 744 | 744 |
| 745 if (modeFlags & TextModeFill) { | 745 if (modeFlags & TextModeFill) { |
| 746 drawText(immutableState()->fillPaint()); | 746 drawText(immutableState()->fillPaint()); |
| 747 } | 747 } |
| 748 | 748 |
| 749 if ((modeFlags & TextModeStroke) && strokeStyle() != NoStroke && strokeThick
ness() > 0) { | 749 if ((modeFlags & TextModeStroke) && strokeStyle() != NoStroke && strokeThick
ness() > 0) { |
| 750 SkPaint paintForStroking(immutableState()->strokePaint()); | 750 SkPaint paintForStroking(immutableState()->strokePaint()); |
| 751 if (modeFlags & TextModeFill) { | 751 if (modeFlags & TextModeFill) { |
| 752 paintForStroking.setLooper(0); // shadow was already applied during
fill pass | 752 paintForStroking.setLooper(0); // shadow was already applied during
fill pass |
| 753 } | 753 } |
| 754 drawText(paintForStroking); | 754 drawText(paintForStroking); |
| 755 } | 755 } |
| 756 } | 756 } |
| 757 | 757 |
| 758 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point) | 758 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point) |
| 759 { | 759 { |
| 760 if (contextDisabled()) | 760 if (contextDisabled()) |
| 761 return; | 761 return; |
| 762 | 762 |
| 763 drawTextPasses([&font, &runInfo, &point, this](const SkPaint& paint) { | 763 drawTextPasses([&font, &runInfo, &point, this](const SkPaint& paint) { |
| 764 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint)) | 764 if (font.drawText(m_canvas, runInfo, point, m_deviceScaleFactor, paint)) |
| 765 m_displayItemList->setTextPainted(); | 765 m_paintController->setTextPainted(); |
| 766 }); | 766 }); |
| 767 } | 767 } |
| 768 | 768 |
| 769 void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRunPaintInfo
& runInfo, const AtomicString& mark, const FloatPoint& point) | 769 void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRunPaintInfo
& runInfo, const AtomicString& mark, const FloatPoint& point) |
| 770 { | 770 { |
| 771 if (contextDisabled()) | 771 if (contextDisabled()) |
| 772 return; | 772 return; |
| 773 | 773 |
| 774 drawTextPasses([&font, &runInfo, &mark, &point, this](const SkPaint& paint)
{ | 774 drawTextPasses([&font, &runInfo, &mark, &point, this](const SkPaint& paint)
{ |
| 775 font.drawEmphasisMarks(m_canvas, runInfo, mark, point, m_deviceScaleFact
or, paint); | 775 font.drawEmphasisMarks(m_canvas, runInfo, mark, point, m_deviceScaleFact
or, paint); |
| 776 }); | 776 }); |
| 777 } | 777 } |
| 778 | 778 |
| 779 void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& run
Info, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReady
Action) | 779 void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& run
Info, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReady
Action) |
| 780 { | 780 { |
| 781 if (contextDisabled()) | 781 if (contextDisabled()) |
| 782 return; | 782 return; |
| 783 | 783 |
| 784 drawTextPasses([&font, &runInfo, &point, customFontNotReadyAction, this](con
st SkPaint& paint) { | 784 drawTextPasses([&font, &runInfo, &point, customFontNotReadyAction, this](con
st SkPaint& paint) { |
| 785 if (font.drawBidiText(m_canvas, runInfo, point, customFontNotReadyAction
, m_deviceScaleFactor, paint)) | 785 if (font.drawBidiText(m_canvas, runInfo, point, customFontNotReadyAction
, m_deviceScaleFactor, paint)) |
| 786 m_displayItemList->setTextPainted(); | 786 m_paintController->setTextPainted(); |
| 787 }); | 787 }); |
| 788 } | 788 } |
| 789 | 789 |
| 790 void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run,
const FloatPoint& point, int h, const Color& backgroundColor, int from, int to) | 790 void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run,
const FloatPoint& point, int h, const Color& backgroundColor, int from, int to) |
| 791 { | 791 { |
| 792 if (contextDisabled()) | 792 if (contextDisabled()) |
| 793 return; | 793 return; |
| 794 | 794 |
| 795 fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor
); | 795 fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor
); |
| 796 } | 796 } |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 static const SkPMColor colors[] = { | 1365 static const SkPMColor colors[] = { |
| 1366 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1366 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
| 1367 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1367 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
| 1368 }; | 1368 }; |
| 1369 | 1369 |
| 1370 return colors[index]; | 1370 return colors[index]; |
| 1371 } | 1371 } |
| 1372 #endif | 1372 #endif |
| 1373 | 1373 |
| 1374 } // namespace blink | 1374 } // namespace blink |
| OLD | NEW |