Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1044)

Side by Side Diff: Source/platform/graphics/BitmapImage.cpp

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: pdr corrections + needsrebaselines Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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, const ImageFilterQualityHelper* filterHelper)
284 { 300 {
285 TRACE_EVENT0("skia", "BitmapImage::draw"); 301 TRACE_EVENT0("skia", "BitmapImage::draw");
286 SkBitmap bitmap; 302 SkBitmap bitmap;
287 if (!bitmapForCurrentFrame(&bitmap)) 303 if (!bitmapForCurrentFrame(&bitmap))
288 return; // It's too early and we don't have an image yet. 304 return; // It's too early and we don't have an image yet.
289 305
290 FloatRect normDstRect = adjustForNegativeSize(dstRect); 306 FloatRect normDstRect = adjustForNegativeSize(dstRect);
291 FloatRect normSrcRect = adjustForNegativeSize(srcRect); 307 FloatRect normSrcRect = adjustForNegativeSize(srcRect);
292 normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height())); 308 normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height()));
293 309
294 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) 310 if (normSrcRect.isEmpty() || normDstRect.isEmpty())
295 return; // Nothing to draw. 311 return; // Nothing to draw.
296 312
297 ImageOrientation orientation = DefaultImageOrientation; 313 ImageOrientation orientation = DefaultImageOrientation;
298 if (shouldRespectImageOrientation == RespectImageOrientation) 314 if (shouldRespectImageOrientation == RespectImageOrientation)
299 orientation = frameOrientationAtIndex(m_currentFrame); 315 orientation = frameOrientationAtIndex(m_currentFrame);
300 316
301 GraphicsContextStateSaver saveContext(*ctxt, false); 317 int initialSaveCount = canvas->getSaveCount();
302 if (orientation != DefaultImageOrientation) { 318 if (orientation != DefaultImageOrientation) {
303 saveContext.save(); 319 canvas->save();
304 320
305 // ImageOrientation expects the origin to be at (0, 0) 321 // ImageOrientation expects the origin to be at (0, 0)
306 ctxt->translate(normDstRect.x(), normDstRect.y()); 322 canvas->translate(normDstRect.x(), normDstRect.y());
307 normDstRect.setLocation(FloatPoint()); 323 normDstRect.setLocation(FloatPoint());
308 324
309 ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size())); 325 canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefaul t(normDstRect.size())));
310 326
311 if (orientation.usesWidthAsHeight()) { 327 if (orientation.usesWidthAsHeight()) {
312 // The destination rect will have it's width and height already reve rsed for the orientation of 328 // 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. 329 // 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()); 330 normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRec t.height(), normDstRect.width());
315 } 331 }
316 } 332 }
317 333
318 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap); 334 SkRect skSrcRect = normSrcRect;
319 bool isOpaque = bitmap.isOpaque(); 335 SkPaint bitmapPaint = paint;
336 bitmapPaint.setFilterQuality(filterHelper->computeFilterQuality(this, normDs tRect, skSrcRect));
337 SkCanvas::DrawBitmapRectFlags flags =
338 filterHelper->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmapRect Flag : SkCanvas::kBleed_DrawBitmapRectFlag;
339 bitmapPaint.setAntiAlias(filterHelper->shouldDrawAntiAliased(normDstRect));
340 canvas->drawBitmapRectToRect(bitmap, &skSrcRect, normDstRect, &bitmapPaint, flags);
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 683
674 return m_isSolidColor && !m_currentFrame; 684 return m_isSolidColor && !m_currentFrame;
675 } 685 }
676 686
677 Color BitmapImage::solidColor() const 687 Color BitmapImage::solidColor() const
678 { 688 {
679 return m_solidColor; 689 return m_solidColor;
680 } 690 }
681 691
682 } // namespace blink 692 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698