Chromium Code Reviews| 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, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple 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 12 matching lines...) Expand all Loading... | |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "platform/graphics/BitmapImage.h" | 28 #include "platform/graphics/BitmapImage.h" |
| 29 | 29 |
| 30 #include "platform/Timer.h" | 30 #include "platform/Timer.h" |
| 31 #include "platform/TraceEvent.h" | 31 #include "platform/TraceEvent.h" |
| 32 #include "platform/geometry/FloatRect.h" | 32 #include "platform/geometry/FloatRect.h" |
| 33 #include "platform/graphics/ColorSpaceFilter.h" | |
| 33 #include "platform/graphics/GraphicsContextStateSaver.h" | 34 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 34 #include "platform/graphics/ImageObserver.h" | 35 #include "platform/graphics/ImageObserver.h" |
| 35 #include "platform/graphics/skia/NativeImageSkia.h" | 36 #include "platform/graphics/skia/NativeImageSkia.h" |
| 36 #include "platform/graphics/skia/SkiaUtils.h" | 37 #include "platform/graphics/skia/SkiaUtils.h" |
| 37 #include "wtf/CurrentTime.h" | 38 #include "wtf/CurrentTime.h" |
| 38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 39 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
| 40 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 // Feed all the data we've seen so far to the image decoder. | 238 // Feed all the data we've seen so far to the image decoder. |
| 238 m_allDataReceived = allDataReceived; | 239 m_allDataReceived = allDataReceived; |
| 239 ASSERT(data()); | 240 ASSERT(data()); |
| 240 m_source.setData(*data(), allDataReceived); | 241 m_source.setData(*data(), allDataReceived); |
| 241 | 242 |
| 242 m_haveFrameCount = false; | 243 m_haveFrameCount = false; |
| 243 m_hasUniformFrameSize = true; | 244 m_hasUniformFrameSize = true; |
| 244 return isSizeAvailable(); | 245 return isSizeAvailable(); |
| 245 } | 246 } |
| 246 | 247 |
| 247 bool BitmapImage::isAllDataReceived() const | |
| 248 { | |
| 249 return m_allDataReceived; | |
| 250 } | |
| 251 | |
| 252 bool BitmapImage::hasColorProfile() const | |
| 253 { | |
| 254 return m_source.hasColorProfile(); | |
| 255 } | |
| 256 | |
| 257 String BitmapImage::filenameExtension() const | 248 String BitmapImage::filenameExtension() const |
| 258 { | 249 { |
| 259 return m_source.filenameExtension(); | 250 return m_source.filenameExtension(); |
| 260 } | 251 } |
| 261 | 252 |
| 262 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode) | 253 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode) |
| 263 { | 254 { |
| 264 draw(ctxt, dstRect, srcRect, compositeOp, blendMode, DoNotRespectImageOrient ation); | 255 draw(ctxt, dstRect, srcRect, compositeOp, blendMode, DoNotRespectImageOrient ation); |
| 265 } | 256 } |
| 266 | 257 |
| 267 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode, RespectImageOrientationEnum shouldRespectImageOrientation) | 258 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode, RespectImageOrientationEnum shouldRespectImageOrientation) |
| 268 { | 259 { |
| 269 // Spin the animation to the correct frame before we try to draw it, so we | 260 // Spin the animation to the correct frame before we try to draw it, so we |
| 270 // don't draw an old frame and then immediately need to draw a newer one, | 261 // don't draw an old frame and then immediately need to draw a newer one, |
| 271 // causing flicker and wasting CPU. | 262 // causing flicker and wasting CPU. |
| 272 startAnimation(); | 263 startAnimation(); |
| 273 | 264 |
| 274 RefPtr<NativeImageSkia> bm = nativeImageForCurrentFrame(); | 265 RefPtr<NativeImageSkia> bitmap = nativeImageForCurrentFrame(); |
| 275 if (!bm) | 266 if (!bitmap) |
| 276 return; // It's too early and we don't have an image yet. | 267 return; // It's too early and we don't have an image yet. |
| 277 | 268 |
| 278 FloatRect normDstRect = adjustForNegativeSize(dstRect); | 269 FloatRect normDstRect = adjustForNegativeSize(dstRect); |
| 279 FloatRect normSrcRect = adjustForNegativeSize(srcRect); | 270 FloatRect normSrcRect = adjustForNegativeSize(srcRect); |
| 280 normSrcRect.intersect(FloatRect(0, 0, bm->bitmap().width(), bm->bitmap().hei ght())); | 271 normSrcRect.intersect(FloatRect(0, 0, bitmap->bitmap().width(), bitmap->bitm ap().height())); |
| 281 | 272 |
| 282 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) | 273 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) |
| 283 return; // Nothing to draw. | 274 return; // Nothing to draw. |
| 284 | 275 |
| 285 ImageOrientation orientation = DefaultImageOrientation; | 276 ImageOrientation orientation = DefaultImageOrientation; |
| 286 if (shouldRespectImageOrientation == RespectImageOrientation) | 277 if (shouldRespectImageOrientation == RespectImageOrientation) |
| 287 orientation = frameOrientationAtIndex(m_currentFrame); | 278 orientation = frameOrientationAtIndex(m_currentFrame); |
| 288 | 279 |
| 289 GraphicsContextStateSaver saveContext(*ctxt, false); | 280 GraphicsContextStateSaver saveContext(*ctxt, false); |
| 290 if (orientation != DefaultImageOrientation) { | 281 if (orientation != DefaultImageOrientation) { |
| 291 saveContext.save(); | 282 saveContext.save(); |
| 292 | 283 |
| 293 // ImageOrientation expects the origin to be at (0, 0) | 284 // ImageOrientation expects the origin to be at (0, 0) |
| 294 ctxt->translate(normDstRect.x(), normDstRect.y()); | 285 ctxt->translate(normDstRect.x(), normDstRect.y()); |
| 295 normDstRect.setLocation(FloatPoint()); | 286 normDstRect.setLocation(FloatPoint()); |
| 296 | 287 |
| 297 ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size())); | 288 ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size())); |
| 298 | 289 |
| 299 if (orientation.usesWidthAsHeight()) { | 290 if (orientation.usesWidthAsHeight()) { |
| 300 // The destination rect will have it's width and height already reve rsed for the orientation of | 291 // The destination rect will have it's width and height already reve rsed for the orientation of |
| 301 // the image, as it was needed for page layout, so we need to revers e it back here. | 292 // the image, as it was needed for page layout, so we need to revers e it back here. |
| 302 normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRec t.height(), normDstRect.width()); | 293 normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRec t.height(), normDstRect.width()); |
| 303 } | 294 } |
| 304 } | 295 } |
| 305 | 296 |
| 306 bm->draw(ctxt, normSrcRect, normDstRect, WebCoreCompositeToSkiaComposite(com positeOp, blendMode)); | 297 // Tagged images (those that have a color profile) are drawn color-correct o n supported platforms. |
| 298 | |
| 299 if (RefPtr<ColorSpaceProfile> source = colorProfile()) { | |
| 300 RefPtr<ColorSpaceProfile> screen = screenColorProfile(currentScreenId()) ; | |
| 301 | |
| 302 RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(source.get (), screen.get()); | |
|
sugoi1
2014/08/29 18:51:11
Note: If you put "RefPtr<SkColorFilter> colorTrans
Noel Gordon
2014/09/01 16:48:39
Yeah possible. I wrote it this way because colorPr
| |
| 303 bitmap->draw(ctxt, normSrcRect, normDstRect, WebCoreCompositeToSkiaCompo site(compositeOp, blendMode), colorTransform); | |
| 304 | |
| 305 if (ImageObserver* observer = imageObserver()) | |
| 306 observer->didDraw(this); | |
| 307 | |
| 308 return; | |
| 309 } | |
| 310 | |
| 311 // FIXME: untagged images should be drawn from sRGB color space, per CSS2.1 onwards, a change that | |
| 312 // would also require that all CSS content, including <canvas>, be drawn fro m sRGB space to match, | |
| 313 // and the same for plugins (Flash, NaCl), which don't define their color sp ace at all. | |
| 314 | |
| 315 bitmap->draw(ctxt, normSrcRect, normDstRect, WebCoreCompositeToSkiaComposite (compositeOp, blendMode)); | |
| 307 | 316 |
| 308 if (ImageObserver* observer = imageObserver()) | 317 if (ImageObserver* observer = imageObserver()) |
| 309 observer->didDraw(this); | 318 observer->didDraw(this); |
| 310 } | 319 } |
| 311 | 320 |
| 321 void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& srcRect, c onst FloatSize& scale, | |
| 322 const FloatPoint& phase, CompositeOperator compositeOp, const FloatRect& des tRect, blink::WebBlendMode blendMode, const IntSize& repeatSpacing) | |
| 323 { | |
| 324 TRACE_EVENT0("skia", "Image::drawPattern"); | |
| 325 | |
| 326 RefPtr<NativeImageSkia> bitmap = nativeImageForCurrentFrame(); | |
| 327 if (!bitmap) | |
| 328 return; | |
| 329 | |
| 330 // Tagged images (those that have a color profile) are drawn color-correct o n supported platforms. | |
| 331 | |
| 332 if (RefPtr<ColorSpaceProfile> source = colorProfile()) { | |
| 333 RefPtr<ColorSpaceProfile> screen = screenColorProfile(currentScreenId()) ; | |
| 334 | |
| 335 RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(source.get (), screen.get()); | |
|
sugoi1
2014/08/29 18:51:11
Same here
| |
| 336 bitmap->drawPattern(ctxt, adjustForNegativeSize(srcRect), scale, phase, compositeOp, destRect, blendMode, repeatSpacing, colorTransform); | |
| 337 | |
| 338 return; | |
| 339 } | |
| 340 | |
| 341 // FIXME: untagged images should be drawn from sRGB color space, per CSS2.1 onwards, a change that | |
| 342 // would also require that all CSS content, including <canvas>, be drawn fro m sRGB space to match, | |
| 343 // and the same for plugins (Flash, NaCl), which don't define their color sp ace at all. | |
| 344 | |
| 345 bitmap->drawPattern(ctxt, adjustForNegativeSize(srcRect), scale, phase, comp ositeOp, destRect, blendMode, repeatSpacing); | |
| 346 } | |
| 347 | |
| 348 void BitmapImage::resetDecoder() | |
| 349 { | |
| 350 m_source.resetDecoder(); | |
| 351 } | |
| 352 | |
| 312 size_t BitmapImage::frameCount() | 353 size_t BitmapImage::frameCount() |
| 313 { | 354 { |
| 314 if (!m_haveFrameCount) { | 355 if (!m_haveFrameCount) { |
| 315 m_frameCount = m_source.frameCount(); | 356 m_frameCount = m_source.frameCount(); |
| 316 // If decoder is not initialized yet, m_source.frameCount() returns 0. | 357 // If decoder is not initialized yet, m_source.frameCount() returns 0. |
| 317 if (m_frameCount) { | 358 if (m_frameCount) { |
| 318 m_haveFrameCount = true; | 359 m_haveFrameCount = true; |
| 319 } | 360 } |
| 320 } | 361 } |
| 321 return m_frameCount; | 362 return m_frameCount; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 } | 665 } |
| 625 return m_isSolidColor && !m_currentFrame; | 666 return m_isSolidColor && !m_currentFrame; |
| 626 } | 667 } |
| 627 | 668 |
| 628 Color BitmapImage::solidColor() const | 669 Color BitmapImage::solidColor() const |
| 629 { | 670 { |
| 630 return m_solidColor; | 671 return m_solidColor; |
| 631 } | 672 } |
| 632 | 673 |
| 633 } | 674 } |
| OLD | NEW |