OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 21 matching lines...) Expand all Loading... |
32 #include "platform/PlatformInstrumentation.h" | 32 #include "platform/PlatformInstrumentation.h" |
33 #include "platform/RuntimeEnabledFeatures.h" | 33 #include "platform/RuntimeEnabledFeatures.h" |
34 #include "platform/SharedBuffer.h" | 34 #include "platform/SharedBuffer.h" |
35 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
36 #include "platform/geometry/FloatPoint.h" | 36 #include "platform/geometry/FloatPoint.h" |
37 #include "platform/geometry/FloatRect.h" | 37 #include "platform/geometry/FloatRect.h" |
38 #include "platform/geometry/FloatSize.h" | 38 #include "platform/geometry/FloatSize.h" |
39 #include "platform/graphics/BitmapImage.h" | 39 #include "platform/graphics/BitmapImage.h" |
40 #include "platform/graphics/DeferredImageDecoder.h" | 40 #include "platform/graphics/DeferredImageDecoder.h" |
41 #include "platform/graphics/GraphicsContext.h" | 41 #include "platform/graphics/GraphicsContext.h" |
| 42 #include "platform/weborigin/KURL.h" |
42 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
43 #include "public/platform/WebData.h" | 44 #include "public/platform/WebData.h" |
44 #include "third_party/skia/include/core/SkCanvas.h" | 45 #include "third_party/skia/include/core/SkCanvas.h" |
45 #include "third_party/skia/include/core/SkImage.h" | 46 #include "third_party/skia/include/core/SkImage.h" |
46 #include "third_party/skia/include/core/SkPictureRecorder.h" | 47 #include "third_party/skia/include/core/SkPictureRecorder.h" |
47 #include "wtf/MainThread.h" | 48 #include "wtf/MainThread.h" |
48 #include "wtf/StdLibExtras.h" | 49 #include "wtf/StdLibExtras.h" |
49 | 50 |
50 #include <math.h> | 51 #include <math.h> |
51 | 52 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (!m_encodedImageData.get()) | 90 if (!m_encodedImageData.get()) |
90 return true; | 91 return true; |
91 | 92 |
92 int length = m_encodedImageData->size(); | 93 int length = m_encodedImageData->size(); |
93 if (!length) | 94 if (!length) |
94 return true; | 95 return true; |
95 | 96 |
96 return dataChanged(allDataReceived); | 97 return dataChanged(allDataReceived); |
97 } | 98 } |
98 | 99 |
99 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
oatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const
IntSize& repeatSpacing) | 100 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
oatPoint& srcPoint, const FloatSize& scaledTileSize, |
| 101 const KURL& url, SkXfermode::Mode op, const IntSize& repeatSpacing) |
100 { | 102 { |
101 FloatSize intrinsicTileSize = size(); | 103 FloatSize intrinsicTileSize = size(); |
102 if (hasRelativeWidth()) | 104 if (hasRelativeWidth()) |
103 intrinsicTileSize.setWidth(scaledTileSize.width()); | 105 intrinsicTileSize.setWidth(scaledTileSize.width()); |
104 if (hasRelativeHeight()) | 106 if (hasRelativeHeight()) |
105 intrinsicTileSize.setHeight(scaledTileSize.height()); | 107 intrinsicTileSize.setHeight(scaledTileSize.height()); |
106 | 108 |
107 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), | 109 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), |
108 scaledTileSize.height() / intrinsicTileSize.height()); | 110 scaledTileSize.height() / intrinsicTileSize.height()); |
109 | 111 |
110 FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), sca
ledTileSize.height() + repeatSpacing.height()); | 112 FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), sca
ledTileSize.height() + repeatSpacing.height()); |
111 FloatRect oneTileRect; | 113 FloatRect oneTileRect; |
112 oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.wi
dth()) - actualTileSize.width(), actualTileSize.width())); | 114 oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.wi
dth()) - actualTileSize.width(), actualTileSize.width())); |
113 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he
ight()) - actualTileSize.height(), actualTileSize.height())); | 115 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he
ight()) - actualTileSize.height(), actualTileSize.height())); |
114 oneTileRect.setSize(scaledTileSize); | 116 oneTileRect.setSize(scaledTileSize); |
115 | 117 |
116 // Check and see if a single draw of the image can cover the entire area we
are supposed to tile. | 118 // Check and see if a single draw of the image can cover the entire area we
are supposed to tile. |
117 if (oneTileRect.contains(destRect)) { | 119 if (oneTileRect.contains(destRect)) { |
118 FloatRect visibleSrcRect; | 120 FloatRect visibleSrcRect; |
119 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); | 121 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); |
120 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); | 122 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); |
121 visibleSrcRect.setWidth(destRect.width() / scale.width()); | 123 visibleSrcRect.setWidth(destRect.width() / scale.width()); |
122 visibleSrcRect.setHeight(destRect.height() / scale.height()); | 124 visibleSrcRect.setHeight(destRect.height() / scale.height()); |
123 ctxt->drawImage(this, destRect, visibleSrcRect, op, DoNotRespectImageOri
entation); | 125 ctxt->drawImage(this, destRect, visibleSrcRect, url, op, DoNotRespectIma
geOrientation); |
124 return; | 126 return; |
125 } | 127 } |
126 | 128 |
127 FloatRect tileRect(FloatPoint(), intrinsicTileSize); | 129 FloatRect tileRect(FloatPoint(), intrinsicTileSize); |
128 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep
eatSpacing); | 130 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), url, op, destRect
, repeatSpacing); |
129 | 131 |
130 startAnimation(); | 132 startAnimation(); |
131 } | 133 } |
132 | 134 |
133 // FIXME: Merge with the other drawTiled eventually, since we need a combination
of both for some things. | 135 // FIXME: Merge with the other drawTiled eventually, since we need a combination
of both for some things. |
134 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
atRect& srcRect, | 136 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
atRect& srcRect, |
135 const FloatSize& providedTileScaleFactor, TileRule hRule, TileRule vRule, Sk
Xfermode::Mode op) | 137 const FloatSize& providedTileScaleFactor, const KURL& url, TileRule hRule, T
ileRule vRule, SkXfermode::Mode op) |
136 { | 138 { |
137 // FIXME: We do not support 'space' yet. For now just map it to 'repeat'. | 139 // FIXME: We do not support 'space' yet. For now just map it to 'repeat'. |
138 if (hRule == SpaceTile) | 140 if (hRule == SpaceTile) |
139 hRule = RepeatTile; | 141 hRule = RepeatTile; |
140 if (vRule == SpaceTile) | 142 if (vRule == SpaceTile) |
141 vRule = RepeatTile; | 143 vRule = RepeatTile; |
142 | 144 |
143 // FIXME: if this code is used for background-repeat: round (in addition to | 145 // FIXME: if this code is used for background-repeat: round (in addition to |
144 // border-image-repeat), then add logic to deal with the background-size: au
to | 146 // border-image-repeat), then add logic to deal with the background-size: au
to |
145 // special case. The aspect ratio should be maintained in this case. | 147 // special case. The aspect ratio should be maintained in this case. |
(...skipping 22 matching lines...) Expand all Loading... |
168 float scaledTileHeight = tileScaleFactor.height() * srcRect.height(); | 170 float scaledTileHeight = tileScaleFactor.height() * srcRect.height(); |
169 if (hRule == Image::RepeatTile) | 171 if (hRule == Image::RepeatTile) |
170 hPhase -= (dstRect.width() - scaledTileWidth) / 2; | 172 hPhase -= (dstRect.width() - scaledTileWidth) / 2; |
171 if (vRule == Image::RepeatTile) | 173 if (vRule == Image::RepeatTile) |
172 vPhase -= (dstRect.height() - scaledTileHeight) / 2; | 174 vPhase -= (dstRect.height() - scaledTileHeight) / 2; |
173 FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase); | 175 FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase); |
174 | 176 |
175 if (useLowInterpolationQuality) { | 177 if (useLowInterpolationQuality) { |
176 InterpolationQuality previousInterpolationQuality = ctxt->imageInterpola
tionQuality(); | 178 InterpolationQuality previousInterpolationQuality = ctxt->imageInterpola
tionQuality(); |
177 ctxt->setImageInterpolationQuality(InterpolationLow); | 179 ctxt->setImageInterpolationQuality(InterpolationLow); |
178 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 180 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, KURL(), op, ds
tRect); // TODO(davve): empty url |
179 ctxt->setImageInterpolationQuality(previousInterpolationQuality); | 181 ctxt->setImageInterpolationQuality(previousInterpolationQuality); |
180 } else { | 182 } else { |
181 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 183 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, KURL(), op, ds
tRect); // TODO(davve): empty url |
182 } | 184 } |
183 | 185 |
184 startAnimation(); | 186 startAnimation(); |
185 } | 187 } |
186 | 188 |
187 namespace { | 189 namespace { |
188 | 190 |
189 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s
haderMatrix, | 191 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s
haderMatrix, |
190 const SkPaint& paint, const FloatSize& spacing) | 192 const SkPaint& paint, const FloatSize& spacing) |
191 { | 193 { |
(...skipping 11 matching lines...) Expand all Loading... |
203 canvas->drawImage(image, 0, 0, &paint); | 205 canvas->drawImage(image, 0, 0, &paint); |
204 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture())
; | 206 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture())
; |
205 | 207 |
206 return adoptRef(SkShader::CreatePictureShader( | 208 return adoptRef(SkShader::CreatePictureShader( |
207 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &
shaderMatrix, nullptr)); | 209 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &
shaderMatrix, nullptr)); |
208 } | 210 } |
209 | 211 |
210 } // anonymous namespace | 212 } // anonymous namespace |
211 | 213 |
212 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect,
const FloatSize& scale, | 214 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect,
const FloatSize& scale, |
213 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest
Rect, const IntSize& repeatSpacing) | 215 const FloatPoint& phase, const KURL& url, SkXfermode::Mode compositeOp, cons
t FloatRect& destRect, const IntSize& repeatSpacing) |
214 { | 216 { |
215 TRACE_EVENT0("skia", "Image::drawPattern"); | 217 TRACE_EVENT0("skia", "Image::drawPattern"); |
216 | 218 |
217 RefPtr<SkImage> image = imageForCurrentFrame(); | 219 RefPtr<SkImage> image = imageForCurrentFrame(); |
218 if (!image) | 220 if (!image) |
219 return; | 221 return; |
220 | 222 |
221 FloatRect normSrcRect = floatSrcRect; | 223 FloatRect normSrcRect = floatSrcRect; |
222 | 224 |
223 normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height())); | 225 normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height())); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 } | 278 } |
277 | 279 |
278 bool Image::deprecatedBitmapForCurrentFrame(SkBitmap* bitmap) | 280 bool Image::deprecatedBitmapForCurrentFrame(SkBitmap* bitmap) |
279 { | 281 { |
280 RefPtr<SkImage> image = imageForCurrentFrame(); | 282 RefPtr<SkImage> image = imageForCurrentFrame(); |
281 | 283 |
282 return image && image->asLegacyBitmap(bitmap, SkImage::kRO_LegacyBitmapMode)
; | 284 return image && image->asLegacyBitmap(bitmap, SkImage::kRO_LegacyBitmapMode)
; |
283 } | 285 } |
284 | 286 |
285 } // namespace blink | 287 } // namespace blink |
OLD | NEW |