| 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/geometry/IntRect.h" | 30 #include "platform/geometry/IntRect.h" |
| 31 #include "platform/geometry/RoundedRect.h" | 31 #include "platform/geometry/RoundedRect.h" |
| 32 #include "platform/graphics/BitmapImage.h" | 32 #include "platform/graphics/BitmapImage.h" |
| 33 #include "platform/graphics/DisplayList.h" | 33 #include "platform/graphics/DisplayList.h" |
| 34 #include "platform/graphics/Gradient.h" | 34 #include "platform/graphics/Gradient.h" |
| 35 #include "platform/graphics/ImageBuffer.h" |
| 35 #include "platform/text/BidiResolver.h" | 36 #include "platform/text/BidiResolver.h" |
| 36 #include "platform/text/TextRunIterator.h" | 37 #include "platform/text/TextRunIterator.h" |
| 37 #include "platform/weborigin/KURL.h" | 38 #include "platform/weborigin/KURL.h" |
| 38 #include "third_party/skia/include/core/SkAnnotation.h" | 39 #include "third_party/skia/include/core/SkAnnotation.h" |
| 39 #include "third_party/skia/include/core/SkColorFilter.h" | 40 #include "third_party/skia/include/core/SkColorFilter.h" |
| 40 #include "third_party/skia/include/core/SkData.h" | 41 #include "third_party/skia/include/core/SkData.h" |
| 41 #include "third_party/skia/include/core/SkPicture.h" | 42 #include "third_party/skia/include/core/SkPicture.h" |
| 42 #include "third_party/skia/include/core/SkRRect.h" | 43 #include "third_party/skia/include/core/SkRRect.h" |
| 43 #include "third_party/skia/include/core/SkRefCnt.h" | 44 #include "third_party/skia/include/core/SkRefCnt.h" |
| 44 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 45 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| 45 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 46 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| 46 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 47 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| 48 #include "third_party/skia/include/gpu/GrRenderTarget.h" |
| 49 #include "third_party/skia/include/gpu/GrTexture.h" |
| 47 #include "wtf/Assertions.h" | 50 #include "wtf/Assertions.h" |
| 48 #include "wtf/MathExtras.h" | 51 #include "wtf/MathExtras.h" |
| 49 | 52 |
| 50 #if OS(MACOSX) | 53 #if OS(MACOSX) |
| 51 #include <ApplicationServices/ApplicationServices.h> | 54 #include <ApplicationServices/ApplicationServices.h> |
| 52 #endif | 55 #endif |
| 53 | 56 |
| 54 using namespace std; | 57 using namespace std; |
| 55 using blink::WebBlendMode; | 58 using blink::WebBlendMode; |
| 56 | 59 |
| 57 namespace WebCore { | 60 namespace WebCore { |
| 58 | 61 |
| 62 namespace { |
| 63 |
| 64 class CompatibleImageBufferSurface : public ImageBufferSurface { |
| 65 WTF_MAKE_NONCOPYABLE(CompatibleImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; |
| 66 public: |
| 67 CompatibleImageBufferSurface(PassRefPtr<SkBaseDevice> device, const IntSize&
size, OpacityMode opacityMode) |
| 68 : ImageBufferSurface(size, opacityMode) |
| 69 { |
| 70 m_canvas = adoptPtr(new SkCanvas(device.get())); // Takes a ref on devic
e |
| 71 } |
| 72 virtual ~CompatibleImageBufferSurface() { } |
| 73 |
| 74 virtual SkCanvas* canvas() const OVERRIDE { return m_canvas.get(); } |
| 75 virtual bool isValid() const OVERRIDE { return m_canvas; } |
| 76 virtual bool isAccelerated() const OVERRIDE { return isValid() && m_canvas->
getTopDevice()->accessRenderTarget(); } |
| 77 virtual Platform3DObject getBackingTexture() const OVERRIDE |
| 78 { |
| 79 ASSERT(isAccelerated()); |
| 80 GrRenderTarget* renderTarget = m_canvas->getTopDevice()->accessRenderTar
get(); |
| 81 if (renderTarget) { |
| 82 return renderTarget->asTexture()->getTextureHandle(); |
| 83 } |
| 84 return 0; |
| 85 }; |
| 86 |
| 87 private: |
| 88 OwnPtr<SkCanvas> m_canvas; |
| 89 }; |
| 90 |
| 91 } // unnamed namespace |
| 92 |
| 59 struct GraphicsContext::DeferredSaveState { | 93 struct GraphicsContext::DeferredSaveState { |
| 60 DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount(
count) { } | 94 DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount(
count) { } |
| 61 | 95 |
| 62 unsigned m_flags; | 96 unsigned m_flags; |
| 63 int m_restoreCount; | 97 int m_restoreCount; |
| 64 }; | 98 }; |
| 65 | 99 |
| 66 struct GraphicsContext::RecordingState { | 100 struct GraphicsContext::RecordingState { |
| 67 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR
efPtr<DisplayList> displayList) | 101 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR
efPtr<DisplayList> displayList) |
| 68 : m_savedCanvas(currentCanvas) | 102 : m_savedCanvas(currentCanvas) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 { | 142 { |
| 109 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); | 143 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); |
| 110 return &m_canvas->getDevice()->accessBitmap(false); | 144 return &m_canvas->getDevice()->accessBitmap(false); |
| 111 } | 145 } |
| 112 | 146 |
| 113 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const | 147 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const |
| 114 { | 148 { |
| 115 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); | 149 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); |
| 116 } | 150 } |
| 117 | 151 |
| 118 SkBaseDevice* GraphicsContext::createCompatibleDevice(const IntSize& size, bool
hasAlpha) const | |
| 119 { | |
| 120 if (paintingDisabled()) | |
| 121 return 0; | |
| 122 | |
| 123 return m_canvas->createCompatibleDevice(SkBitmap::kARGB_8888_Config, size.wi
dth(), size.height(), !hasAlpha); | |
| 124 } | |
| 125 | |
| 126 void GraphicsContext::save() | 152 void GraphicsContext::save() |
| 127 { | 153 { |
| 128 if (paintingDisabled()) | 154 if (paintingDisabled()) |
| 129 return; | 155 return; |
| 130 | 156 |
| 131 m_stateStack.append(m_state->clone()); | 157 m_stateStack.append(m_state->clone()); |
| 132 m_state = m_stateStack.last().get(); | 158 m_state = m_stateStack.last().get(); |
| 133 | 159 |
| 134 m_saveStateStack.append(DeferredSaveState(m_deferredSaveFlags, m_canvas->get
SaveCount())); | 160 m_saveStateStack.append(DeferredSaveState(m_deferredSaveFlags, m_canvas->get
SaveCount())); |
| 135 m_deferredSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; | 161 m_deferredSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 setImageInterpolationQuality(previousInterpolationQuality); | 1144 setImageInterpolationQuality(previousInterpolationQuality); |
| 1119 } else { | 1145 } else { |
| 1120 image->drawTiled(this, dest, srcRect, tileScaleFactor, hRule, vRule, op)
; | 1146 image->drawTiled(this, dest, srcRect, tileScaleFactor, hRule, vRule, op)
; |
| 1121 } | 1147 } |
| 1122 } | 1148 } |
| 1123 | 1149 |
| 1124 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& p, Com
positeOperator op, WebBlendMode blendMode) | 1150 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& p, Com
positeOperator op, WebBlendMode blendMode) |
| 1125 { | 1151 { |
| 1126 if (!image) | 1152 if (!image) |
| 1127 return; | 1153 return; |
| 1128 drawImageBuffer(image, FloatRect(IntRect(p, image->logicalSize())), FloatRec
t(FloatPoint(), FloatSize(image->logicalSize())), op, blendMode); | 1154 drawImageBuffer(image, FloatRect(IntRect(p, image->size())), FloatRect(Float
Point(), FloatSize(image->size())), op, blendMode); |
| 1129 } | 1155 } |
| 1130 | 1156 |
| 1131 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& r, Comp
ositeOperator op, WebBlendMode blendMode, bool useLowQualityScale) | 1157 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& r, Comp
ositeOperator op, WebBlendMode blendMode, bool useLowQualityScale) |
| 1132 { | 1158 { |
| 1133 if (!image) | 1159 if (!image) |
| 1134 return; | 1160 return; |
| 1135 drawImageBuffer(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image
->logicalSize())), op, blendMode, useLowQualityScale); | 1161 drawImageBuffer(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image
->size())), op, blendMode, useLowQualityScale); |
| 1136 } | 1162 } |
| 1137 | 1163 |
| 1138 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& dest,
const IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode) | 1164 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& dest,
const IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode) |
| 1139 { | 1165 { |
| 1140 drawImageBuffer(image, FloatRect(IntRect(dest, srcRect.size())), FloatRect(s
rcRect), op, blendMode); | 1166 drawImageBuffer(image, FloatRect(IntRect(dest, srcRect.size())), FloatRect(s
rcRect), op, blendMode); |
| 1141 } | 1167 } |
| 1142 | 1168 |
| 1143 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& dest, c
onst IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode, bool useLow
QualityScale) | 1169 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& dest, c
onst IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode, bool useLow
QualityScale) |
| 1144 { | 1170 { |
| 1145 drawImageBuffer(image, FloatRect(dest), FloatRect(srcRect), op, blendMode, u
seLowQualityScale); | 1171 drawImageBuffer(image, FloatRect(dest), FloatRect(srcRect), op, blendMode, u
seLowQualityScale); |
| 1146 } | 1172 } |
| 1147 | 1173 |
| 1148 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest) | 1174 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest) |
| 1149 { | 1175 { |
| 1150 if (!image) | 1176 if (!image) |
| 1151 return; | 1177 return; |
| 1152 drawImageBuffer(image, dest, FloatRect(IntRect(IntPoint(), image->logicalSiz
e()))); | 1178 drawImageBuffer(image, dest, FloatRect(IntRect(IntPoint(), image->size()))); |
| 1153 } | 1179 } |
| 1154 | 1180 |
| 1155 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest,
const FloatRect& src, CompositeOperator op, WebBlendMode blendMode, bool useLow
QualityScale) | 1181 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest,
const FloatRect& src, CompositeOperator op, WebBlendMode blendMode, bool useLow
QualityScale) |
| 1156 { | 1182 { |
| 1157 if (paintingDisabled() || !image) | 1183 if (paintingDisabled() || !image) |
| 1158 return; | 1184 return; |
| 1159 | 1185 |
| 1160 if (useLowQualityScale) { | 1186 if (useLowQualityScale) { |
| 1161 InterpolationQuality previousInterpolationQuality = imageInterpolationQu
ality(); | 1187 InterpolationQuality previousInterpolationQuality = imageInterpolationQu
ality(); |
| 1162 setImageInterpolationQuality(InterpolationLow); | 1188 setImageInterpolationQuality(InterpolationLow); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 p1.setX(p1.x() + 0.5f); | 1719 p1.setX(p1.x() + 0.5f); |
| 1694 p2.setX(p2.x() + 0.5f); | 1720 p2.setX(p2.x() + 0.5f); |
| 1695 } else { | 1721 } else { |
| 1696 // We're a horizontal line. Adjust our y. | 1722 // We're a horizontal line. Adjust our y. |
| 1697 p1.setY(p1.y() + 0.5f); | 1723 p1.setY(p1.y() + 0.5f); |
| 1698 p2.setY(p2.y() + 0.5f); | 1724 p2.setY(p2.y() + 0.5f); |
| 1699 } | 1725 } |
| 1700 } | 1726 } |
| 1701 } | 1727 } |
| 1702 | 1728 |
| 1703 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s
ize, bool hasAlpha) const | 1729 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s
ize, OpacityMode opacityMode) const |
| 1704 { | 1730 { |
| 1705 // Make the buffer larger if the context's transform is scaling it so we nee
d a higher | 1731 // Make the buffer larger if the context's transform is scaling it so we nee
d a higher |
| 1706 // resolution than one pixel per unit. Also set up a corresponding scale fac
tor on the | 1732 // resolution than one pixel per unit. Also set up a corresponding scale fac
tor on the |
| 1707 // graphics context. | 1733 // graphics context. |
| 1708 | 1734 |
| 1709 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); | 1735 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); |
| 1710 IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale()))
, static_cast<int>(ceil(size.height() * transform.yScale()))); | 1736 IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale()))
, static_cast<int>(ceil(size.height() * transform.yScale()))); |
| 1711 | 1737 |
| 1712 OwnPtr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(scaledSize,
1, this, hasAlpha); | 1738 RefPtr<SkBaseDevice> device = adoptRef(m_canvas->getTopDevice()->createCompa
tibleDevice(SkBitmap::kARGB_8888_Config, size.width(), size.height(), opacityMod
e == Opaque)); |
| 1713 if (!buffer) | 1739 if (!device) |
| 1714 return nullptr; | 1740 return nullptr; |
| 1741 OwnPtr<ImageBufferSurface> surface = adoptPtr(new CompatibleImageBufferSurfa
ce(device.release(), scaledSize, opacityMode)); |
| 1742 ASSERT(surface->isValid()); |
| 1743 OwnPtr<ImageBuffer> buffer = adoptPtr(new ImageBuffer(surface.release())); |
| 1715 | 1744 |
| 1716 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) /
size.width(), | 1745 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) /
size.width(), |
| 1717 static_cast<float>(scaledSize.height()) / size.height())); | 1746 static_cast<float>(scaledSize.height()) / size.height())); |
| 1718 | 1747 |
| 1719 return buffer.release(); | 1748 return buffer.release(); |
| 1720 } | 1749 } |
| 1721 | 1750 |
| 1722 void GraphicsContext::addCornerArc(SkPath* path, const SkRect& rect, const IntSi
ze& size, int startAngle) | 1751 void GraphicsContext::addCornerArc(SkPath* path, const SkRect& rect, const IntSi
ze& size, int startAngle) |
| 1723 { | 1752 { |
| 1724 SkIRect ir; | 1753 SkIRect ir; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 | 1993 |
| 1965 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 1994 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
| 1966 { | 1995 { |
| 1967 if (m_trackTextRegion) { | 1996 if (m_trackTextRegion) { |
| 1968 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1997 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
| 1969 m_textRegion.join(textRect); | 1998 m_textRegion.join(textRect); |
| 1970 } | 1999 } |
| 1971 } | 2000 } |
| 1972 | 2001 |
| 1973 } | 2002 } |
| OLD | NEW |