| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if (!m_encodedImageData.get()) | 85 if (!m_encodedImageData.get()) |
| 86 return true; | 86 return true; |
| 87 | 87 |
| 88 int length = m_encodedImageData->size(); | 88 int length = m_encodedImageData->size(); |
| 89 if (!length) | 89 if (!length) |
| 90 return true; | 90 return true; |
| 91 | 91 |
| 92 return dataChanged(allDataReceived); | 92 return dataChanged(allDataReceived); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect,
const Color& color, CompositeOperator op) | 95 void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect,
const Color& color, SkXfermode::Mode op) |
| 96 { | 96 { |
| 97 if (!color.alpha()) | 97 if (!color.alpha()) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 SkXfermode::Mode previousOperation = ctxt->compositeOperation(); | 100 SkXfermode::Mode previousOperation = ctxt->compositeOperation(); |
| 101 ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ?
SkXfermode::kSrc_Mode : WebCoreCompositeToSkiaComposite(op)); | 101 ctxt->setCompositeOperation(!color.hasAlpha() && op == SkXfermode::kSrcOver_
Mode ? SkXfermode::kSrc_Mode : op); |
| 102 ctxt->fillRect(dstRect, color); | 102 ctxt->fillRect(dstRect, color); |
| 103 ctxt->setCompositeOperation(previousOperation); | 103 ctxt->setCompositeOperation(previousOperation); |
| 104 } | 104 } |
| 105 | 105 |
| 106 FloatRect Image::adjustForNegativeSize(const FloatRect& rect) | 106 FloatRect Image::adjustForNegativeSize(const FloatRect& rect) |
| 107 { | 107 { |
| 108 FloatRect norm = rect; | 108 FloatRect norm = rect; |
| 109 if (norm.width() < 0) { | 109 if (norm.width() < 0) { |
| 110 norm.setX(norm.x() + norm.width()); | 110 norm.setX(norm.x() + norm.width()); |
| 111 norm.setWidth(-norm.width()); | 111 norm.setWidth(-norm.width()); |
| 112 } | 112 } |
| 113 if (norm.height() < 0) { | 113 if (norm.height() < 0) { |
| 114 norm.setY(norm.y() + norm.height()); | 114 norm.setY(norm.y() + norm.height()); |
| 115 norm.setHeight(-norm.height()); | 115 norm.setHeight(-norm.height()); |
| 116 } | 116 } |
| 117 return norm; | 117 return norm; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
oatPoint& srcPoint, const FloatSize& scaledTileSize, CompositeOperator op, WebBl
endMode blendMode, const IntSize& repeatSpacing) | 120 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl
oatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const
IntSize& repeatSpacing) |
| 121 { | 121 { |
| 122 if (mayFillWithSolidColor()) { | 122 if (mayFillWithSolidColor()) { |
| 123 fillWithSolidColor(ctxt, destRect, solidColor(), op); | 123 fillWithSolidColor(ctxt, destRect, solidColor(), op); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // See <https://webkit.org/b/59043>. | 127 // See <https://webkit.org/b/59043>. |
| 128 ASSERT(!isBitmapImage() || notSolidColor()); | 128 ASSERT(!isBitmapImage() || notSolidColor()); |
| 129 | 129 |
| 130 FloatSize intrinsicTileSize = size(); | 130 FloatSize intrinsicTileSize = size(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he
ight()) - actualTileSize.height(), actualTileSize.height())); | 142 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he
ight()) - actualTileSize.height(), actualTileSize.height())); |
| 143 oneTileRect.setSize(scaledTileSize); | 143 oneTileRect.setSize(scaledTileSize); |
| 144 | 144 |
| 145 // Check and see if a single draw of the image can cover the entire area we
are supposed to tile. | 145 // Check and see if a single draw of the image can cover the entire area we
are supposed to tile. |
| 146 if (oneTileRect.contains(destRect)) { | 146 if (oneTileRect.contains(destRect)) { |
| 147 FloatRect visibleSrcRect; | 147 FloatRect visibleSrcRect; |
| 148 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); | 148 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); |
| 149 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); | 149 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); |
| 150 visibleSrcRect.setWidth(destRect.width() / scale.width()); | 150 visibleSrcRect.setWidth(destRect.width() / scale.width()); |
| 151 visibleSrcRect.setHeight(destRect.height() / scale.height()); | 151 visibleSrcRect.setHeight(destRect.height() / scale.height()); |
| 152 draw(ctxt, destRect, visibleSrcRect, op, blendMode, DoNotRespectImageOri
entation); | 152 draw(ctxt, destRect, visibleSrcRect, op, DoNotRespectImageOrientation); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 | 155 |
| 156 FloatRect tileRect(FloatPoint(), intrinsicTileSize); | 156 FloatRect tileRect(FloatPoint(), intrinsicTileSize); |
| 157 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, ble
ndMode, repeatSpacing); | 157 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep
eatSpacing); |
| 158 | 158 |
| 159 startAnimation(); | 159 startAnimation(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // FIXME: Merge with the other drawTiled eventually, since we need a combination
of both for some things. | 162 // FIXME: Merge with the other drawTiled eventually, since we need a combination
of both for some things. |
| 163 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
atRect& srcRect, | 163 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& dstRect, const Flo
atRect& srcRect, |
| 164 const FloatSize& providedTileScaleFactor, TileRule hRule, TileRule vRule, Co
mpositeOperator op) | 164 const FloatSize& providedTileScaleFactor, TileRule hRule, TileRule vRule, Sk
Xfermode::Mode op) |
| 165 { | 165 { |
| 166 if (mayFillWithSolidColor()) { | 166 if (mayFillWithSolidColor()) { |
| 167 fillWithSolidColor(ctxt, dstRect, solidColor(), op); | 167 fillWithSolidColor(ctxt, dstRect, solidColor(), op); |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // FIXME: We do not support 'space' yet. For now just map it to 'repeat'. | 171 // FIXME: We do not support 'space' yet. For now just map it to 'repeat'. |
| 172 if (hRule == SpaceTile) | 172 if (hRule == SpaceTile) |
| 173 hRule = RepeatTile; | 173 hRule = RepeatTile; |
| 174 if (vRule == SpaceTile) | 174 if (vRule == SpaceTile) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 212 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); |
| 213 ctxt->setImageInterpolationQuality(previousInterpolationQuality); | 213 ctxt->setImageInterpolationQuality(previousInterpolationQuality); |
| 214 } else { | 214 } else { |
| 215 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 215 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); |
| 216 } | 216 } |
| 217 | 217 |
| 218 startAnimation(); | 218 startAnimation(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect,
const FloatSize& scale, | 221 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect,
const FloatSize& scale, |
| 222 const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& des
tRect, WebBlendMode blendMode, const IntSize& repeatSpacing) | 222 const FloatPoint& phase, SkXfermode::Mode op, const FloatRect& destRect, con
st IntSize& repeatSpacing) |
| 223 { | 223 { |
| 224 TRACE_EVENT0("skia", "Image::drawPattern"); | 224 TRACE_EVENT0("skia", "Image::drawPattern"); |
| 225 if (RefPtr<NativeImageSkia> bitmap = nativeImageForCurrentFrame()) | 225 if (RefPtr<NativeImageSkia> bitmap = nativeImageForCurrentFrame()) |
| 226 bitmap->drawPattern(context, adjustForNegativeSize(floatSrcRect), scale,
phase, compositeOp, destRect, blendMode, repeatSpacing); | 226 bitmap->drawPattern(context, adjustForNegativeSize(floatSrcRect), scale,
phase, op, destRect, repeatSpacing); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic
Height, FloatSize& intrinsicRatio) | 229 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic
Height, FloatSize& intrinsicRatio) |
| 230 { | 230 { |
| 231 intrinsicRatio = size(); | 231 intrinsicRatio = size(); |
| 232 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); | 232 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); |
| 233 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); | 233 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); |
| 234 } | 234 } |
| 235 | 235 |
| 236 PassRefPtr<Image> Image::imageForDefaultFrame() | 236 PassRefPtr<Image> Image::imageForDefaultFrame() |
| 237 { | 237 { |
| 238 RefPtr<Image> image(this); | 238 RefPtr<Image> image(this); |
| 239 | 239 |
| 240 return image.release(); | 240 return image.release(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 PassRefPtr<SkImage> Image::skImage() | 243 PassRefPtr<SkImage> Image::skImage() |
| 244 { | 244 { |
| 245 return nullptr; | 245 return nullptr; |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace blink | 248 } // namespace blink |
| OLD | NEW |