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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (!m_encodedImageData.get()) | 89 if (!m_encodedImageData.get()) |
90 return true; | 90 return true; |
91 | 91 |
92 int length = m_encodedImageData->size(); | 92 int length = m_encodedImageData->size(); |
93 if (!length) | 93 if (!length) |
94 return true; | 94 return true; |
95 | 95 |
96 return dataChanged(allDataReceived); | 96 return dataChanged(allDataReceived); |
97 } | 97 } |
98 | 98 |
99 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
oatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const
FloatSize& repeatSpacing) | 99 void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& destRect, const Fl
oatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const
FloatSize& repeatSpacing) |
100 { | 100 { |
101 FloatSize intrinsicTileSize = FloatSize(size()); | 101 FloatSize intrinsicTileSize = FloatSize(size()); |
102 if (hasRelativeWidth()) | 102 if (hasRelativeWidth()) |
103 intrinsicTileSize.setWidth(scaledTileSize.width()); | 103 intrinsicTileSize.setWidth(scaledTileSize.width()); |
104 if (hasRelativeHeight()) | 104 if (hasRelativeHeight()) |
105 intrinsicTileSize.setHeight(scaledTileSize.height()); | 105 intrinsicTileSize.setHeight(scaledTileSize.height()); |
106 | 106 |
107 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), | 107 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), |
108 scaledTileSize.height() / intrinsicTileSize.height()); | 108 scaledTileSize.height() / intrinsicTileSize.height()); |
109 | 109 |
110 FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), sca
ledTileSize.height() + repeatSpacing.height()); | 110 FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), sca
ledTileSize.height() + repeatSpacing.height()); |
111 FloatRect oneTileRect; | 111 FloatRect oneTileRect; |
112 oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.wi
dth()) - actualTileSize.width(), actualTileSize.width())); | 112 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())); | 113 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he
ight()) - actualTileSize.height(), actualTileSize.height())); |
114 oneTileRect.setSize(scaledTileSize); | 114 oneTileRect.setSize(scaledTileSize); |
115 | 115 |
116 // Check and see if a single draw of the image can cover the entire area we
are supposed to tile. | 116 // 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)) { | 117 if (oneTileRect.contains(destRect)) { |
118 FloatRect visibleSrcRect; | 118 FloatRect visibleSrcRect; |
119 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); | 119 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); |
120 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); | 120 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); |
121 visibleSrcRect.setWidth(destRect.width() / scale.width()); | 121 visibleSrcRect.setWidth(destRect.width() / scale.width()); |
122 visibleSrcRect.setHeight(destRect.height() / scale.height()); | 122 visibleSrcRect.setHeight(destRect.height() / scale.height()); |
123 ctxt->drawImage(this, destRect, visibleSrcRect, op, DoNotRespectImageOri
entation); | 123 ctxt.drawImage(this, destRect, visibleSrcRect, op, DoNotRespectImageOrie
ntation); |
124 return; | 124 return; |
125 } | 125 } |
126 | 126 |
127 FloatRect tileRect(FloatPoint(), intrinsicTileSize); | 127 FloatRect tileRect(FloatPoint(), intrinsicTileSize); |
128 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep
eatSpacing); | 128 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep
eatSpacing); |
129 | 129 |
130 startAnimation(); | 130 startAnimation(); |
131 } | 131 } |
132 | 132 |
133 // FIXME: Merge with the other drawTiled eventually, since we need a combination
of both for some things. | 133 // 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, | 134 void Image::drawTiled(GraphicsContext& ctxt, const FloatRect& dstRect, const Flo
atRect& srcRect, |
135 const FloatSize& providedTileScaleFactor, TileRule hRule, TileRule vRule, Sk
Xfermode::Mode op) | 135 const FloatSize& providedTileScaleFactor, TileRule hRule, TileRule vRule, Sk
Xfermode::Mode op) |
136 { | 136 { |
137 // FIXME: We do not support 'space' yet. For now just map it to 'repeat'. | 137 // FIXME: We do not support 'space' yet. For now just map it to 'repeat'. |
138 if (hRule == SpaceTile) | 138 if (hRule == SpaceTile) |
139 hRule = RepeatTile; | 139 hRule = RepeatTile; |
140 if (vRule == SpaceTile) | 140 if (vRule == SpaceTile) |
141 vRule = RepeatTile; | 141 vRule = RepeatTile; |
142 | 142 |
143 // FIXME: if this code is used for background-repeat: round (in addition to | 143 // 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 | 144 // border-image-repeat), then add logic to deal with the background-size: au
to |
(...skipping 21 matching lines...) Expand all Loading... |
166 float vPhase = tileScaleFactor.height() * srcRect.y(); | 166 float vPhase = tileScaleFactor.height() * srcRect.y(); |
167 float scaledTileWidth = tileScaleFactor.width() * srcRect.width(); | 167 float scaledTileWidth = tileScaleFactor.width() * srcRect.width(); |
168 float scaledTileHeight = tileScaleFactor.height() * srcRect.height(); | 168 float scaledTileHeight = tileScaleFactor.height() * srcRect.height(); |
169 if (hRule == Image::RepeatTile) | 169 if (hRule == Image::RepeatTile) |
170 hPhase -= (dstRect.width() - scaledTileWidth) / 2; | 170 hPhase -= (dstRect.width() - scaledTileWidth) / 2; |
171 if (vRule == Image::RepeatTile) | 171 if (vRule == Image::RepeatTile) |
172 vPhase -= (dstRect.height() - scaledTileHeight) / 2; | 172 vPhase -= (dstRect.height() - scaledTileHeight) / 2; |
173 FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase); | 173 FloatPoint patternPhase(dstRect.x() - hPhase, dstRect.y() - vPhase); |
174 | 174 |
175 if (useLowInterpolationQuality) { | 175 if (useLowInterpolationQuality) { |
176 InterpolationQuality previousInterpolationQuality = ctxt->imageInterpola
tionQuality(); | 176 InterpolationQuality previousInterpolationQuality = ctxt.imageInterpolat
ionQuality(); |
177 ctxt->setImageInterpolationQuality(InterpolationLow); | 177 ctxt.setImageInterpolationQuality(InterpolationLow); |
178 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 178 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); |
179 ctxt->setImageInterpolationQuality(previousInterpolationQuality); | 179 ctxt.setImageInterpolationQuality(previousInterpolationQuality); |
180 } else { | 180 } else { |
181 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 181 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); |
182 } | 182 } |
183 | 183 |
184 startAnimation(); | 184 startAnimation(); |
185 } | 185 } |
186 | 186 |
187 namespace { | 187 namespace { |
188 | 188 |
189 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s
haderMatrix, | 189 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s
haderMatrix, |
(...skipping 12 matching lines...) Expand all Loading... |
202 SkCanvas* canvas = recorder.beginRecording(tileRect); | 202 SkCanvas* canvas = recorder.beginRecording(tileRect); |
203 canvas->drawImage(image, 0, 0, &paint); | 203 canvas->drawImage(image, 0, 0, &paint); |
204 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture())
; | 204 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture())
; |
205 | 205 |
206 return adoptRef(SkShader::CreatePictureShader( | 206 return adoptRef(SkShader::CreatePictureShader( |
207 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &
shaderMatrix, nullptr)); | 207 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &
shaderMatrix, nullptr)); |
208 } | 208 } |
209 | 209 |
210 } // anonymous namespace | 210 } // anonymous namespace |
211 | 211 |
212 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect,
const FloatSize& scale, | 212 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect,
const FloatSize& scale, |
213 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest
Rect, const FloatSize& repeatSpacing) | 213 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest
Rect, const FloatSize& repeatSpacing) |
214 { | 214 { |
215 TRACE_EVENT0("skia", "Image::drawPattern"); | 215 TRACE_EVENT0("skia", "Image::drawPattern"); |
216 | 216 |
217 RefPtr<SkImage> image = imageForCurrentFrame(); | 217 RefPtr<SkImage> image = imageForCurrentFrame(); |
218 if (!image) | 218 if (!image) |
219 return; | 219 return; |
220 | 220 |
221 FloatRect normSrcRect = floatSrcRect; | 221 FloatRect normSrcRect = floatSrcRect; |
222 | 222 |
(...skipping 15 matching lines...) Expand all Loading... |
238 localMatrix.preScale(scale.width(), scale.height()); | 238 localMatrix.preScale(scale.width(), scale.height()); |
239 | 239 |
240 // Fetch this now as subsetting may swap the image. | 240 // Fetch this now as subsetting may swap the image. |
241 auto imageID = image->uniqueID(); | 241 auto imageID = image->uniqueID(); |
242 | 242 |
243 image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect))); | 243 image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect))); |
244 if (!image) | 244 if (!image) |
245 return; | 245 return; |
246 | 246 |
247 { | 247 { |
248 SkPaint paint = context->fillPaint(); | 248 SkPaint paint = context.fillPaint(); |
249 paint.setColor(SK_ColorBLACK); | 249 paint.setColor(SK_ColorBLACK); |
250 paint.setXfermodeMode(compositeOp); | 250 paint.setXfermodeMode(compositeOp); |
251 paint.setFilterQuality(context->computeFilterQuality(this, destRect, nor
mSrcRect)); | 251 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm
SrcRect)); |
252 paint.setAntiAlias(context->shouldAntialias()); | 252 paint.setAntiAlias(context.shouldAntialias()); |
253 RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix,
paint, | 253 RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix,
paint, |
254 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh
t() / scale.height())); | 254 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh
t() / scale.height())); |
255 paint.setShader(shader.get()); | 255 paint.setShader(shader.get()); |
256 context->drawRect(destRect, paint); | 256 context.drawRect(destRect, paint); |
257 } | 257 } |
258 | 258 |
259 if (currentFrameIsLazyDecoded()) | 259 if (currentFrameIsLazyDecoded()) |
260 PlatformInstrumentation::didDrawLazyPixelRef(imageID); | 260 PlatformInstrumentation::didDrawLazyPixelRef(imageID); |
261 } | 261 } |
262 | 262 |
263 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic
Height, FloatSize& intrinsicRatio) | 263 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic
Height, FloatSize& intrinsicRatio) |
264 { | 264 { |
265 intrinsicRatio = FloatSize(size()); | 265 intrinsicRatio = FloatSize(size()); |
266 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); | 266 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); |
267 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); | 267 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); |
268 } | 268 } |
269 | 269 |
270 PassRefPtr<Image> Image::imageForDefaultFrame() | 270 PassRefPtr<Image> Image::imageForDefaultFrame() |
271 { | 271 { |
272 RefPtr<Image> image(this); | 272 RefPtr<Image> image(this); |
273 | 273 |
274 return image.release(); | 274 return image.release(); |
275 } | 275 } |
276 | 276 |
277 bool Image::isTextureBacked() | 277 bool Image::isTextureBacked() |
278 { | 278 { |
279 return imageForCurrentFrame()->isTextureBacked(); | 279 return imageForCurrentFrame()->isTextureBacked(); |
280 } | 280 } |
281 | 281 |
282 } // namespace blink | 282 } // namespace blink |
OLD | NEW |