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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 bool BitmapImage::hasColorProfile() const | 265 bool BitmapImage::hasColorProfile() const |
266 { | 266 { |
267 return m_source.hasColorProfile(); | 267 return m_source.hasColorProfile(); |
268 } | 268 } |
269 | 269 |
270 String BitmapImage::filenameExtension() const | 270 String BitmapImage::filenameExtension() const |
271 { | 271 { |
272 return m_source.filenameExtension(); | 272 return m_source.filenameExtension(); |
273 } | 273 } |
274 | 274 |
275 void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl
oatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum shou
ldRespectImageOrientation) | 275 bool BitmapImage::isLazyDecodedBitmap() |
| 276 { |
| 277 SkBitmap bitmap; |
| 278 if (!bitmapForCurrentFrame(&bitmap)) |
| 279 return false; |
| 280 return DeferredImageDecoder::isLazyDecoded(bitmap); |
| 281 } |
| 282 |
| 283 bool BitmapImage::isImmutableBitmap() |
| 284 { |
| 285 SkBitmap bitmap; |
| 286 if (!bitmapForCurrentFrame(&bitmap)) |
| 287 return false; |
| 288 return bitmap.isImmutable(); |
| 289 } |
| 290 |
| 291 void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect&
dstRect, const FloatRect& srcRect, RespectImageOrientationEnum shouldRespectImag
eOrientation) |
276 { | 292 { |
277 TRACE_EVENT0("skia", "BitmapImage::draw"); | 293 TRACE_EVENT0("skia", "BitmapImage::draw"); |
278 SkBitmap bitmap; | 294 SkBitmap bitmap; |
279 if (!bitmapForCurrentFrame(&bitmap)) | 295 if (!bitmapForCurrentFrame(&bitmap)) |
280 return; // It's too early and we don't have an image yet. | 296 return; // It's too early and we don't have an image yet. |
281 | 297 |
282 FloatRect normDstRect = adjustForNegativeSize(dstRect); | 298 FloatRect normDstRect = adjustForNegativeSize(dstRect); |
283 FloatRect normSrcRect = adjustForNegativeSize(srcRect); | 299 FloatRect normSrcRect = adjustForNegativeSize(srcRect); |
284 normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height())); | 300 normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height())); |
285 | 301 |
286 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) | 302 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) |
287 return; // Nothing to draw. | 303 return; // Nothing to draw. |
288 | 304 |
289 ImageOrientation orientation = DefaultImageOrientation; | 305 ImageOrientation orientation = DefaultImageOrientation; |
290 if (shouldRespectImageOrientation == RespectImageOrientation) | 306 if (shouldRespectImageOrientation == RespectImageOrientation) |
291 orientation = frameOrientationAtIndex(m_currentFrame); | 307 orientation = frameOrientationAtIndex(m_currentFrame); |
292 | 308 |
293 GraphicsContextStateSaver saveContext(*ctxt, false); | 309 int initialSaveCount = canvas->getSaveCount(); |
294 if (orientation != DefaultImageOrientation) { | 310 if (orientation != DefaultImageOrientation) { |
295 saveContext.save(); | 311 canvas->save(); |
296 | 312 |
297 // ImageOrientation expects the origin to be at (0, 0) | 313 // ImageOrientation expects the origin to be at (0, 0) |
298 ctxt->translate(normDstRect.x(), normDstRect.y()); | 314 canvas->translate(normDstRect.x(), normDstRect.y()); |
299 normDstRect.setLocation(FloatPoint()); | 315 normDstRect.setLocation(FloatPoint()); |
300 | 316 |
301 ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size())); | 317 canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefaul
t(normDstRect.size()))); |
302 | 318 |
303 if (orientation.usesWidthAsHeight()) { | 319 if (orientation.usesWidthAsHeight()) { |
304 // The destination rect will have it's width and height already reve
rsed for the orientation of | 320 // The destination rect will have it's width and height already reve
rsed for the orientation of |
305 // the image, as it was needed for page layout, so we need to revers
e it back here. | 321 // the image, as it was needed for page layout, so we need to revers
e it back here. |
306 normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRec
t.height(), normDstRect.width()); | 322 normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRec
t.height(), normDstRect.width()); |
307 } | 323 } |
308 } | 324 } |
309 | 325 |
310 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap); | 326 SkRect skSrcRect = normSrcRect; |
311 bool isOpaque = bitmap.isOpaque(); | 327 canvas->drawBitmapRectToRect(bitmap, &skSrcRect, normDstRect, &paint); |
| 328 canvas->restoreToCount(initialSaveCount); |
312 | 329 |
313 { | 330 if (DeferredImageDecoder::isLazyDecoded(bitmap)) |
314 SkPaint paint; | |
315 SkRect skSrcRect = normSrcRect; | |
316 int initialSaveCount = ctxt->preparePaintForDrawRectToRect(&paint, skSrc
Rect, normDstRect, compositeOp, !isOpaque, isLazyDecoded, bitmap.isImmutable()); | |
317 // We want to filter it if we decided to do interpolation above, or if | |
318 // there is something interesting going on with the matrix (like a rotat
ion). | |
319 // Note: for serialization, we will want to subset the bitmap first so w
e | |
320 // don't send extra pixels. | |
321 ctxt->drawBitmapRect(bitmap, &skSrcRect, normDstRect, &paint); | |
322 ctxt->canvas()->restoreToCount(initialSaveCount); | |
323 } | |
324 | |
325 if (isLazyDecoded) | |
326 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID()); | 331 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID()); |
327 | 332 |
328 if (ImageObserver* observer = imageObserver()) | 333 if (ImageObserver* observer = imageObserver()) |
329 observer->didDraw(this); | 334 observer->didDraw(this); |
330 | 335 |
331 startAnimation(); | 336 startAnimation(); |
332 } | 337 } |
333 | 338 |
334 size_t BitmapImage::frameCount() | 339 size_t BitmapImage::frameCount() |
335 { | 340 { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 670 |
666 return m_isSolidColor && !m_currentFrame; | 671 return m_isSolidColor && !m_currentFrame; |
667 } | 672 } |
668 | 673 |
669 Color BitmapImage::solidColor() const | 674 Color BitmapImage::solidColor() const |
670 { | 675 { |
671 return m_solidColor; | 676 return m_solidColor; |
672 } | 677 } |
673 | 678 |
674 } // namespace blink | 679 } // namespace blink |
OLD | NEW |