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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 bool BitmapImage::hasColorProfile() const | 273 bool BitmapImage::hasColorProfile() const |
274 { | 274 { |
275 return m_source.hasColorProfile(); | 275 return m_source.hasColorProfile(); |
276 } | 276 } |
277 | 277 |
278 String BitmapImage::filenameExtension() const | 278 String BitmapImage::filenameExtension() const |
279 { | 279 { |
280 return m_source.filenameExtension(); | 280 return m_source.filenameExtension(); |
281 } | 281 } |
282 | 282 |
283 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl
oatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum shou
ldRespectImageOrientation) | 283 bool BitmapImage::isLazyDecodedBitmap() |
| 284 { |
| 285 SkBitmap bitmap; |
| 286 if (!bitmapForCurrentFrame(&bitmap)) |
| 287 return false; |
| 288 return DeferredImageDecoder::isLazyDecoded(bitmap); |
| 289 } |
| 290 |
| 291 bool BitmapImage::isImmutableBitmap() |
| 292 { |
| 293 SkBitmap bitmap; |
| 294 if (!bitmapForCurrentFrame(&bitmap)) |
| 295 return false; |
| 296 return bitmap.isImmutable(); |
| 297 } |
| 298 |
| 299 void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect&
dstRect, const FloatRect& srcRect, RespectImageOrientationEnum shouldRespectImag
eOrientation, bool shouldClampToSourceRect) |
284 { | 300 { |
285 TRACE_EVENT0("skia", "BitmapImage::draw"); | 301 TRACE_EVENT0("skia", "BitmapImage::draw"); |
| 302 |
| 303 ASSERT(dstRect.width() >= 0 && dstRect.height() >= 0); |
| 304 ASSERT(srcRect.width() >= 0 && srcRect.height() >= 0); |
286 SkBitmap bitmap; | 305 SkBitmap bitmap; |
287 if (!bitmapForCurrentFrame(&bitmap)) | 306 if (!bitmapForCurrentFrame(&bitmap)) |
288 return; // It's too early and we don't have an image yet. | 307 return; // It's too early and we don't have an image yet. |
289 | 308 |
290 FloatRect normDstRect = adjustForNegativeSize(dstRect); | 309 FloatRect adjustedSrcRect = srcRect; |
291 FloatRect normSrcRect = adjustForNegativeSize(srcRect); | 310 adjustedSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height())); |
292 normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height())); | |
293 | 311 |
294 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) | 312 if (adjustedSrcRect.isEmpty() || dstRect.isEmpty()) |
295 return; // Nothing to draw. | 313 return; // Nothing to draw. |
296 | 314 |
297 ImageOrientation orientation = DefaultImageOrientation; | 315 ImageOrientation orientation = DefaultImageOrientation; |
298 if (shouldRespectImageOrientation == RespectImageOrientation) | 316 if (shouldRespectImageOrientation == RespectImageOrientation) |
299 orientation = frameOrientationAtIndex(m_currentFrame); | 317 orientation = frameOrientationAtIndex(m_currentFrame); |
300 | 318 |
301 GraphicsContextStateSaver saveContext(*ctxt, false); | 319 int initialSaveCount = canvas->getSaveCount(); |
| 320 FloatRect adjustedDstRect = dstRect; |
302 if (orientation != DefaultImageOrientation) { | 321 if (orientation != DefaultImageOrientation) { |
303 saveContext.save(); | 322 canvas->save(); |
304 | 323 |
305 // ImageOrientation expects the origin to be at (0, 0) | 324 // ImageOrientation expects the origin to be at (0, 0) |
306 ctxt->translate(normDstRect.x(), normDstRect.y()); | 325 canvas->translate(adjustedDstRect.x(), adjustedDstRect.y()); |
307 normDstRect.setLocation(FloatPoint()); | 326 adjustedDstRect.setLocation(FloatPoint()); |
308 | 327 |
309 ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size())); | 328 canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefaul
t(adjustedDstRect.size()))); |
310 | 329 |
311 if (orientation.usesWidthAsHeight()) { | 330 if (orientation.usesWidthAsHeight()) { |
312 // The destination rect will have it's width and height already reve
rsed for the orientation of | 331 // The destination rect will have it's width and height already reve
rsed for the orientation of |
313 // the image, as it was needed for page layout, so we need to revers
e it back here. | 332 // the image, as it was needed for page layout, so we need to revers
e it back here. |
314 normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRec
t.height(), normDstRect.width()); | 333 adjustedDstRect = FloatRect(adjustedDstRect.x(), adjustedDstRect.y()
, adjustedDstRect.height(), adjustedDstRect.width()); |
315 } | 334 } |
316 } | 335 } |
317 | 336 |
318 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap); | 337 SkRect skSrcRect = adjustedSrcRect; |
319 bool isOpaque = bitmap.isOpaque(); | 338 SkCanvas::DrawBitmapRectFlags flags = |
| 339 shouldClampToSourceRect ? SkCanvas::kNone_DrawBitmapRectFlag : SkCanvas:
:kBleed_DrawBitmapRectFlag; |
| 340 canvas->drawBitmapRectToRect(bitmap, &skSrcRect, adjustedDstRect, &paint, fl
ags); |
| 341 canvas->restoreToCount(initialSaveCount); |
320 | 342 |
321 { | 343 if (DeferredImageDecoder::isLazyDecoded(bitmap)) |
322 SkPaint paint; | |
323 SkRect skSrcRect = normSrcRect; | |
324 int initialSaveCount = ctxt->preparePaintForDrawRectToRect(&paint, skSrc
Rect, normDstRect, compositeOp, !isOpaque, isLazyDecoded, bitmap.isImmutable()); | |
325 // We want to filter it if we decided to do interpolation above, or if | |
326 // there is something interesting going on with the matrix (like a rotat
ion). | |
327 // Note: for serialization, we will want to subset the bitmap first so w
e | |
328 // don't send extra pixels. | |
329 ctxt->drawBitmapRect(bitmap, &skSrcRect, normDstRect, &paint); | |
330 ctxt->canvas()->restoreToCount(initialSaveCount); | |
331 } | |
332 | |
333 if (isLazyDecoded) | |
334 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID()); | 344 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID()); |
335 | 345 |
336 if (ImageObserver* observer = imageObserver()) | 346 if (ImageObserver* observer = imageObserver()) |
337 observer->didDraw(this); | 347 observer->didDraw(this); |
338 | 348 |
339 startAnimation(); | 349 startAnimation(); |
340 } | 350 } |
341 | 351 |
342 size_t BitmapImage::frameCount() | 352 size_t BitmapImage::frameCount() |
343 { | 353 { |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 691 |
682 return m_isSolidColor && !m_currentFrame; | 692 return m_isSolidColor && !m_currentFrame; |
683 } | 693 } |
684 | 694 |
685 Color BitmapImage::solidColor() const | 695 Color BitmapImage::solidColor() const |
686 { | 696 { |
687 return m_solidColor; | 697 return m_solidColor; |
688 } | 698 } |
689 | 699 |
690 } // namespace blink | 700 } // namespace blink |
OLD | NEW |