| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * 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 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 280 |
| 281 // Now measure the length of the two transformed vectors relative to the | 281 // Now measure the length of the two transformed vectors relative to the |
| 282 // transformed origin to see how big the bitmap will be. Note: for skews, | 282 // transformed origin to see how big the bitmap will be. Note: for skews, |
| 283 // this isn't the best thing, but we don't have skews. | 283 // this isn't the best thing, but we don't have skews. |
| 284 SkPoint dest_points[3]; | 284 SkPoint dest_points[3]; |
| 285 matrix.mapPoints(dest_points, src_points, 3); | 285 matrix.mapPoints(dest_points, src_points, 3); |
| 286 *dest_width = SkScalarToFloat((dest_points[1] - dest_points[0]).length()); | 286 *dest_width = SkScalarToFloat((dest_points[1] - dest_points[0]).length()); |
| 287 *dest_height = SkScalarToFloat((dest_points[2] - dest_points[0]).length()); | 287 *dest_height = SkScalarToFloat((dest_points[2] - dest_points[0]).length()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 // A helper method for translating negative width and height values. |
| 291 FloatRect normalizeRect(const FloatRect& rect) |
| 292 { |
| 293 FloatRect norm = rect; |
| 294 if (norm.width() < 0) { |
| 295 norm.setX(norm.x() + norm.width()); |
| 296 norm.setWidth(-norm.width()); |
| 297 } |
| 298 if (norm.height() < 0) { |
| 299 norm.setY(norm.y() + norm.height()); |
| 300 norm.setHeight(-norm.height()); |
| 301 } |
| 302 return norm; |
| 303 } |
| 304 |
| 290 } // namespace | 305 } // namespace |
| 291 | 306 |
| 292 void FrameData::clear() | 307 void FrameData::clear() |
| 293 { | 308 { |
| 294 // ImageSource::createFrameAtIndex() allocated |m_frame| and passed | 309 // ImageSource::createFrameAtIndex() allocated |m_frame| and passed |
| 295 // ownership to BitmapImage; we must delete it here. | 310 // ownership to BitmapImage; we must delete it here. |
| 296 delete m_frame; | 311 delete m_frame; |
| 297 m_frame = 0; | 312 m_frame = 0; |
| 298 // NOTE: We purposefully don't reset metadata here, so that even if we | 313 // NOTE: We purposefully don't reset metadata here, so that even if we |
| 299 // throw away previously-decoded data, animation loops can still access | 314 // throw away previously-decoded data, animation loops can still access |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 432 |
| 418 // Spin the animation to the correct frame before we try to draw it, so we | 433 // Spin the animation to the correct frame before we try to draw it, so we |
| 419 // don't draw an old frame and then immediately need to draw a newer one, | 434 // don't draw an old frame and then immediately need to draw a newer one, |
| 420 // causing flicker and wasting CPU. | 435 // causing flicker and wasting CPU. |
| 421 startAnimation(); | 436 startAnimation(); |
| 422 | 437 |
| 423 const NativeImageSkia* bm = nativeImageForCurrentFrame(); | 438 const NativeImageSkia* bm = nativeImageForCurrentFrame(); |
| 424 if (!bm) | 439 if (!bm) |
| 425 return; // It's too early and we don't have an image yet. | 440 return; // It's too early and we don't have an image yet. |
| 426 | 441 |
| 427 if (srcRect.isEmpty() || dstRect.isEmpty()) | 442 FloatRect normDstRect = normalizeRect(dstRect); |
| 443 FloatRect normSrcRect = normalizeRect(srcRect); |
| 444 |
| 445 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) |
| 428 return; // Nothing to draw. | 446 return; // Nothing to draw. |
| 429 | 447 |
| 430 paintSkBitmap(ctxt->platformContext(), | 448 paintSkBitmap(ctxt->platformContext(), |
| 431 *bm, | 449 *bm, |
| 432 enclosingIntRect(srcRect), | 450 enclosingIntRect(normSrcRect), |
| 433 enclosingIntRect(dstRect), | 451 enclosingIntRect(normDstRect), |
| 434 WebCoreCompositeToSkiaComposite(compositeOp)); | 452 WebCoreCompositeToSkiaComposite(compositeOp)); |
| 435 } | 453 } |
| 436 | 454 |
| 437 void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt, | 455 void BitmapImageSingleFrameSkia::draw(GraphicsContext* ctxt, |
| 438 const FloatRect& dstRect, | 456 const FloatRect& dstRect, |
| 439 const FloatRect& srcRect, | 457 const FloatRect& srcRect, |
| 440 CompositeOperator compositeOp) | 458 CompositeOperator compositeOp) |
| 441 { | 459 { |
| 442 if (srcRect.isEmpty() || dstRect.isEmpty()) | 460 FloatRect normDstRect = normalizeRect(dstRect); |
| 461 FloatRect normSrcRect = normalizeRect(srcRect); |
| 462 |
| 463 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) |
| 443 return; // Nothing to draw. | 464 return; // Nothing to draw. |
| 444 | 465 |
| 445 paintSkBitmap(ctxt->platformContext(), | 466 paintSkBitmap(ctxt->platformContext(), |
| 446 m_nativeImage, | 467 m_nativeImage, |
| 447 enclosingIntRect(srcRect), | 468 enclosingIntRect(normSrcRect), |
| 448 enclosingIntRect(dstRect), | 469 enclosingIntRect(normDstRect), |
| 449 WebCoreCompositeToSkiaComposite(compositeOp)); | 470 WebCoreCompositeToSkiaComposite(compositeOp)); |
| 450 } | 471 } |
| 451 | 472 |
| 452 PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create( | 473 PassRefPtr<BitmapImageSingleFrameSkia> BitmapImageSingleFrameSkia::create( |
| 453 const SkBitmap& bitmap) | 474 const SkBitmap& bitmap) |
| 454 { | 475 { |
| 455 RefPtr<BitmapImageSingleFrameSkia> image(new BitmapImageSingleFrameSkia()); | 476 RefPtr<BitmapImageSingleFrameSkia> image(new BitmapImageSingleFrameSkia()); |
| 456 if (!bitmap.copyTo(&image->m_nativeImage, bitmap.config())) | 477 if (!bitmap.copyTo(&image->m_nativeImage, bitmap.config())) |
| 457 return 0; | 478 return 0; |
| 458 return image.release(); | 479 return image.release(); |
| 459 } | 480 } |
| 460 | 481 |
| 461 } // namespace WebCore | 482 } // namespace WebCore |
| OLD | NEW |