| 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 17 matching lines...) Expand all Loading... |
| 28 #include "platform/graphics/GraphicsContext.h" | 28 #include "platform/graphics/GraphicsContext.h" |
| 29 | 29 |
| 30 #include "platform/RuntimeEnabledFeatures.h" | 30 #include "platform/RuntimeEnabledFeatures.h" |
| 31 #include "platform/TraceEvent.h" | 31 #include "platform/TraceEvent.h" |
| 32 #include "platform/geometry/IntRect.h" | 32 #include "platform/geometry/IntRect.h" |
| 33 #include "platform/graphics/BitmapImage.h" | 33 #include "platform/graphics/BitmapImage.h" |
| 34 #include "platform/graphics/Gradient.h" | 34 #include "platform/graphics/Gradient.h" |
| 35 #include "platform/graphics/GraphicsContextClient.h" | 35 #include "platform/graphics/GraphicsContextClient.h" |
| 36 #include "platform/graphics/ImageBuffer.h" | 36 #include "platform/graphics/ImageBuffer.h" |
| 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 38 #include "platform/graphics/skia/SkiaUtils.h" | |
| 39 #include "platform/text/BidiResolver.h" | 38 #include "platform/text/BidiResolver.h" |
| 40 #include "platform/text/TextRunIterator.h" | 39 #include "platform/text/TextRunIterator.h" |
| 41 #include "platform/weborigin/KURL.h" | 40 #include "platform/weborigin/KURL.h" |
| 42 #include "third_party/skia/include/core/SkAnnotation.h" | 41 #include "third_party/skia/include/core/SkAnnotation.h" |
| 43 #include "third_party/skia/include/core/SkClipStack.h" | 42 #include "third_party/skia/include/core/SkClipStack.h" |
| 44 #include "third_party/skia/include/core/SkColorFilter.h" | 43 #include "third_party/skia/include/core/SkColorFilter.h" |
| 45 #include "third_party/skia/include/core/SkData.h" | 44 #include "third_party/skia/include/core/SkData.h" |
| 46 #include "third_party/skia/include/core/SkDevice.h" | 45 #include "third_party/skia/include/core/SkDevice.h" |
| 47 #include "third_party/skia/include/core/SkPicture.h" | 46 #include "third_party/skia/include/core/SkPicture.h" |
| 48 #include "third_party/skia/include/core/SkPictureRecorder.h" | 47 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 SkXfermode::Mode GraphicsContext::compositeOperation() const | 431 SkXfermode::Mode GraphicsContext::compositeOperation() const |
| 433 { | 432 { |
| 434 return immutableState()->compositeOperation(); | 433 return immutableState()->compositeOperation(); |
| 435 } | 434 } |
| 436 | 435 |
| 437 CompositeOperator GraphicsContext::compositeOperationDeprecated() const | 436 CompositeOperator GraphicsContext::compositeOperationDeprecated() const |
| 438 { | 437 { |
| 439 return compositeOperatorFromSkia(immutableState()->compositeOperation()); | 438 return compositeOperatorFromSkia(immutableState()->compositeOperation()); |
| 440 } | 439 } |
| 441 | 440 |
| 442 WebBlendMode GraphicsContext::blendModeOperation() const | |
| 443 { | |
| 444 return blendModeFromSkia(immutableState()->compositeOperation()); | |
| 445 } | |
| 446 | |
| 447 SkColorFilter* GraphicsContext::colorFilter() const | 441 SkColorFilter* GraphicsContext::colorFilter() const |
| 448 { | 442 { |
| 449 return immutableState()->colorFilter(); | 443 return immutableState()->colorFilter(); |
| 450 } | 444 } |
| 451 | 445 |
| 452 void GraphicsContext::setColorFilter(ColorFilter colorFilter) | 446 void GraphicsContext::setColorFilter(ColorFilter colorFilter) |
| 453 { | 447 { |
| 454 GraphicsContextState* stateToSet = mutableState(); | 448 GraphicsContextState* stateToSet = mutableState(); |
| 455 | 449 |
| 456 // We only support one active color filter at the moment. If (when) this bec
omes a problem, | 450 // We only support one active color filter at the moment. If (when) this bec
omes a problem, |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 } | 1060 } |
| 1067 | 1061 |
| 1068 void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run,
const FloatPoint& point, int h, const Color& backgroundColor, int from, int to) | 1062 void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run,
const FloatPoint& point, int h, const Color& backgroundColor, int from, int to) |
| 1069 { | 1063 { |
| 1070 if (contextDisabled()) | 1064 if (contextDisabled()) |
| 1071 return; | 1065 return; |
| 1072 | 1066 |
| 1073 fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor
); | 1067 fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor
); |
| 1074 } | 1068 } |
| 1075 | 1069 |
| 1076 void GraphicsContext::drawImage(Image* image, const IntPoint& p, CompositeOperat
or op, RespectImageOrientationEnum shouldRespectImageOrientation) | 1070 void GraphicsContext::drawImage(Image* image, const IntPoint& p, SkXfermode::Mod
e op, RespectImageOrientationEnum shouldRespectImageOrientation) |
| 1077 { | 1071 { |
| 1078 if (!image) | 1072 if (!image) |
| 1079 return; | 1073 return; |
| 1080 drawImage(image, FloatRect(IntRect(p, image->size())), FloatRect(FloatPoint(
), FloatSize(image->size())), op, shouldRespectImageOrientation); | 1074 drawImage(image, FloatRect(IntRect(p, image->size())), FloatRect(FloatPoint(
), FloatSize(image->size())), op, shouldRespectImageOrientation); |
| 1081 } | 1075 } |
| 1082 | 1076 |
| 1083 void GraphicsContext::drawImage(Image* image, const IntRect& r, CompositeOperato
r op, RespectImageOrientationEnum shouldRespectImageOrientation) | 1077 void GraphicsContext::drawImage(Image* image, const IntRect& r, SkXfermode::Mode
op, RespectImageOrientationEnum shouldRespectImageOrientation) |
| 1084 { | 1078 { |
| 1085 if (!image) | 1079 if (!image) |
| 1086 return; | 1080 return; |
| 1087 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size
())), op, shouldRespectImageOrientation); | 1081 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size
())), op, shouldRespectImageOrientation); |
| 1088 } | 1082 } |
| 1089 | 1083 |
| 1090 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, CompositeOperator op, RespectImageOrientationEnum shouldRespectImageO
rientation) | |
| 1091 { | |
| 1092 drawImage(image, dest, src, op, WebBlendModeNormal, shouldRespectImageOrient
ation); | |
| 1093 } | |
| 1094 | |
| 1095 void GraphicsContext::drawImage(Image* image, const FloatRect& dest) | 1084 void GraphicsContext::drawImage(Image* image, const FloatRect& dest) |
| 1096 { | 1085 { |
| 1097 if (!image) | 1086 if (!image) |
| 1098 return; | 1087 return; |
| 1099 drawImage(image, dest, FloatRect(IntRect(IntPoint(), image->size()))); | 1088 drawImage(image, dest, FloatRect(IntRect(IntPoint(), image->size()))); |
| 1100 } | 1089 } |
| 1101 | 1090 |
| 1102 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, CompositeOperator op, WebBlendMode blendMode, RespectImageOrientation
Enum shouldRespectImageOrientation) | 1091 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr
ientation) |
| 1103 { | 1092 { |
| 1104 if (contextDisabled() || !image) | 1093 if (contextDisabled() || !image) |
| 1105 return; | 1094 return; |
| 1106 image->draw(this, dest, src, op, blendMode, shouldRespectImageOrientation); | 1095 image->draw(this, dest, src, op, shouldRespectImageOrientation); |
| 1107 } | 1096 } |
| 1108 | 1097 |
| 1109 void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, cons
t IntPoint& srcPoint, const IntSize& tileSize, CompositeOperator op, WebBlendMod
e blendMode, const IntSize& repeatSpacing) | 1098 void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, cons
t IntPoint& srcPoint, const IntSize& tileSize, SkXfermode::Mode op, const IntSiz
e& repeatSpacing) |
| 1110 { | 1099 { |
| 1111 if (contextDisabled() || !image) | 1100 if (contextDisabled() || !image) |
| 1112 return; | 1101 return; |
| 1113 image->drawTiled(this, destRect, srcPoint, tileSize, op, blendMode, repeatSp
acing); | 1102 image->drawTiled(this, destRect, srcPoint, tileSize, op, repeatSpacing); |
| 1114 } | 1103 } |
| 1115 | 1104 |
| 1116 void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const In
tRect& srcRect, | 1105 void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const In
tRect& srcRect, |
| 1117 const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRu
le, CompositeOperator op) | 1106 const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRu
le, SkXfermode::Mode op) |
| 1118 { | 1107 { |
| 1119 if (contextDisabled() || !image) | 1108 if (contextDisabled() || !image) |
| 1120 return; | 1109 return; |
| 1121 | 1110 |
| 1122 if (hRule == Image::StretchTile && vRule == Image::StretchTile) { | 1111 if (hRule == Image::StretchTile && vRule == Image::StretchTile) { |
| 1123 // Just do a scale. | 1112 // Just do a scale. |
| 1124 drawImage(image, dest, srcRect, op); | 1113 drawImage(image, dest, srcRect, op); |
| 1125 return; | 1114 return; |
| 1126 } | 1115 } |
| 1127 | 1116 |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 if (m_trackTextRegion) { | 1849 if (m_trackTextRegion) { |
| 1861 TRACE_EVENT0("skia", "GraphicsContext::didDrawTextInRect"); | 1850 TRACE_EVENT0("skia", "GraphicsContext::didDrawTextInRect"); |
| 1862 m_textRegion.join(textRect); | 1851 m_textRegion.join(textRect); |
| 1863 } | 1852 } |
| 1864 } | 1853 } |
| 1865 | 1854 |
| 1866 int GraphicsContext::preparePaintForDrawRectToRect( | 1855 int GraphicsContext::preparePaintForDrawRectToRect( |
| 1867 SkPaint* paint, | 1856 SkPaint* paint, |
| 1868 const SkRect& srcRect, | 1857 const SkRect& srcRect, |
| 1869 const SkRect& destRect, | 1858 const SkRect& destRect, |
| 1870 CompositeOperator compositeOp, | 1859 SkXfermode::Mode compositeOp, |
| 1871 WebBlendMode blendMode, | |
| 1872 bool isBitmapWithAlpha, | 1860 bool isBitmapWithAlpha, |
| 1873 bool isLazyDecoded, | 1861 bool isLazyDecoded, |
| 1874 bool isDataComplete) const | 1862 bool isDataComplete) const |
| 1875 { | 1863 { |
| 1876 int initialSaveCount = m_canvas->getSaveCount(); | 1864 int initialSaveCount = m_canvas->getSaveCount(); |
| 1877 | 1865 |
| 1878 paint->setColorFilter(this->colorFilter()); | 1866 paint->setColorFilter(this->colorFilter()); |
| 1879 paint->setAlpha(this->getNormalizedAlpha()); | 1867 paint->setAlpha(this->getNormalizedAlpha()); |
| 1880 bool usingImageFilter = false; | 1868 bool usingImageFilter = false; |
| 1881 if (dropShadowImageFilter() && isBitmapWithAlpha) { | 1869 if (dropShadowImageFilter() && isBitmapWithAlpha) { |
| 1882 SkMatrix ctm = getTotalMatrix(); | 1870 SkMatrix ctm = getTotalMatrix(); |
| 1883 SkMatrix invCtm; | 1871 SkMatrix invCtm; |
| 1884 if (ctm.invert(&invCtm)) { | 1872 if (ctm.invert(&invCtm)) { |
| 1885 usingImageFilter = true; | 1873 usingImageFilter = true; |
| 1886 // The image filter is meant to ignore tranforms with respect to | 1874 // The image filter is meant to ignore tranforms with respect to |
| 1887 // the shadow parameters. The matrix tweaks below ensures that the i
mage | 1875 // the shadow parameters. The matrix tweaks below ensures that the i
mage |
| 1888 // filter is applied in post-transform space. We use concat() instea
d of | 1876 // filter is applied in post-transform space. We use concat() instea
d of |
| 1889 // setMatrix() in case this goes into a recording canvas which may n
eed to | 1877 // setMatrix() in case this goes into a recording canvas which may n
eed to |
| 1890 // respect a parent transform at playback time. | 1878 // respect a parent transform at playback time. |
| 1891 m_canvas->save(); | 1879 m_canvas->save(); |
| 1892 m_canvas->concat(invCtm); | 1880 m_canvas->concat(invCtm); |
| 1893 SkRect bounds = destRect; | 1881 SkRect bounds = destRect; |
| 1894 ctm.mapRect(&bounds); | 1882 ctm.mapRect(&bounds); |
| 1895 SkRect filteredBounds; | 1883 SkRect filteredBounds; |
| 1896 dropShadowImageFilter()->computeFastBounds(bounds, &filteredBounds); | 1884 dropShadowImageFilter()->computeFastBounds(bounds, &filteredBounds); |
| 1897 SkPaint layerPaint; | 1885 SkPaint layerPaint; |
| 1898 layerPaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(composite
Op, blendMode)); | 1886 layerPaint.setXfermodeMode(compositeOp); |
| 1899 layerPaint.setImageFilter(dropShadowImageFilter()); | 1887 layerPaint.setImageFilter(dropShadowImageFilter()); |
| 1900 m_canvas->saveLayer(&filteredBounds, &layerPaint); | 1888 m_canvas->saveLayer(&filteredBounds, &layerPaint); |
| 1901 m_canvas->concat(ctm); | 1889 m_canvas->concat(ctm); |
| 1902 } | 1890 } |
| 1903 } | 1891 } |
| 1904 | 1892 |
| 1905 if (!usingImageFilter) { | 1893 if (!usingImageFilter) { |
| 1906 paint->setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blen
dMode)); | 1894 paint->setXfermodeMode(compositeOp); |
| 1907 paint->setLooper(this->drawLooper()); | 1895 paint->setLooper(this->drawLooper()); |
| 1908 } | 1896 } |
| 1909 | 1897 |
| 1910 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); | 1898 paint->setAntiAlias(shouldDrawAntiAliased(this, destRect)); |
| 1911 | 1899 |
| 1912 InterpolationQuality resampling; | 1900 InterpolationQuality resampling; |
| 1913 if (this->isAccelerated()) { | 1901 if (this->isAccelerated()) { |
| 1914 resampling = InterpolationLow; | 1902 resampling = InterpolationLow; |
| 1915 } else if (this->printing()) { | 1903 } else if (this->printing()) { |
| 1916 resampling = InterpolationNone; | 1904 resampling = InterpolationNone; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1941 return initialSaveCount; | 1929 return initialSaveCount; |
| 1942 } | 1930 } |
| 1943 | 1931 |
| 1944 void GraphicsContext::setClient(GraphicsContextClient* client) | 1932 void GraphicsContext::setClient(GraphicsContextClient* client) |
| 1945 { | 1933 { |
| 1946 ASSERT(client == 0 || m_client == 0); // No clobbering | 1934 ASSERT(client == 0 || m_client == 0); // No clobbering |
| 1947 m_client = client; | 1935 m_client = client; |
| 1948 } | 1936 } |
| 1949 | 1937 |
| 1950 } // namespace blink | 1938 } // namespace blink |
| OLD | NEW |