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

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

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Draw layered images with a recording GraphicContext Created 5 years 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
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 13 matching lines...) Expand all
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/PlatformInstrumentation.h" 30 #include "platform/PlatformInstrumentation.h"
31 #include "platform/Timer.h" 31 #include "platform/Timer.h"
32 #include "platform/TraceEvent.h" 32 #include "platform/TraceEvent.h"
33 #include "platform/geometry/FloatRect.h" 33 #include "platform/geometry/FloatRect.h"
34 #include "platform/graphics/ColorSpaceFilter.h"
35 #include "platform/graphics/ColorSpaceProfile.h"
34 #include "platform/graphics/DeferredImageDecoder.h" 36 #include "platform/graphics/DeferredImageDecoder.h"
37 #include "platform/graphics/GraphicsScreen.h"
38 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/ImageObserver.h" 39 #include "platform/graphics/ImageObserver.h"
36 #include "platform/graphics/StaticBitmapImage.h" 40 #include "platform/graphics/StaticBitmapImage.h"
37 #include "platform/graphics/skia/SkiaUtils.h" 41 #include "platform/graphics/skia/SkiaUtils.h"
38 #include "third_party/skia/include/core/SkCanvas.h" 42 #include "third_party/skia/include/core/SkCanvas.h"
43 #include "third_party/skia/include/core/SkColorFilter.h"
39 #include "wtf/PassRefPtr.h" 44 #include "wtf/PassRefPtr.h"
45 #include "wtf/RefPtr.h"
40 #include "wtf/text/WTFString.h" 46 #include "wtf/text/WTFString.h"
41 47
42 namespace blink { 48 namespace blink {
43 49
44 PassRefPtr<BitmapImage> BitmapImage::createWithOrientationForTesting(const SkBit map& bitmap, ImageOrientation orientation) 50 PassRefPtr<BitmapImage> BitmapImage::createWithOrientationForTesting(const SkBit map& bitmap, ImageOrientation orientation)
45 { 51 {
46 if (bitmap.isNull()) { 52 if (bitmap.isNull()) {
47 return BitmapImage::create(); 53 return BitmapImage::create();
48 } 54 }
49 55
(...skipping 12 matching lines...) Expand all
62 , m_repetitionsComplete(0) 68 , m_repetitionsComplete(0)
63 , m_desiredFrameStartTime(0) 69 , m_desiredFrameStartTime(0)
64 , m_frameCount(0) 70 , m_frameCount(0)
65 , m_animationPolicy(ImageAnimationPolicyAllowed) 71 , m_animationPolicy(ImageAnimationPolicyAllowed)
66 , m_animationFinished(false) 72 , m_animationFinished(false)
67 , m_allDataReceived(false) 73 , m_allDataReceived(false)
68 , m_haveSize(false) 74 , m_haveSize(false)
69 , m_sizeAvailable(false) 75 , m_sizeAvailable(false)
70 , m_hasUniformFrameSize(true) 76 , m_hasUniformFrameSize(true)
71 , m_haveFrameCount(false) 77 , m_haveFrameCount(false)
78 , m_drawingToCanvasElement(false)
72 { 79 {
73 } 80 }
74 81
75 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer) 82 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer)
76 : Image(observer) 83 : Image(observer)
77 , m_size(bitmap.width(), bitmap.height()) 84 , m_size(bitmap.width(), bitmap.height())
78 , m_currentFrame(0) 85 , m_currentFrame(0)
79 , m_repetitionCount(cAnimationNone) 86 , m_repetitionCount(cAnimationNone)
80 , m_repetitionCountStatus(Unknown) 87 , m_repetitionCountStatus(Unknown)
81 , m_repetitionsComplete(0) 88 , m_repetitionsComplete(0)
82 , m_frameCount(1) 89 , m_frameCount(1)
83 , m_animationPolicy(ImageAnimationPolicyAllowed) 90 , m_animationPolicy(ImageAnimationPolicyAllowed)
84 , m_animationFinished(true) 91 , m_animationFinished(true)
85 , m_allDataReceived(true) 92 , m_allDataReceived(true)
86 , m_haveSize(true) 93 , m_haveSize(true)
87 , m_sizeAvailable(true) 94 , m_sizeAvailable(true)
88 , m_haveFrameCount(true) 95 , m_haveFrameCount(true)
96 , m_drawingToCanvasElement(false)
89 { 97 {
90 // Since we don't have a decoder, we can't figure out the image orientation. 98 // Since we don't have a decoder, we can't figure out the image orientation.
91 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. 99 // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0.
92 m_sizeRespectingOrientation = m_size; 100 m_sizeRespectingOrientation = m_size;
93 101
94 m_frames.grow(1); 102 m_frames.grow(1);
95 m_frames[0].m_hasAlpha = !bitmap.isOpaque(); 103 m_frames[0].m_hasAlpha = !bitmap.isOpaque();
96 m_frames[0].m_frame = adoptRef(SkImage::NewFromBitmap(bitmap)); 104 m_frames[0].m_frame = adoptRef(SkImage::NewFromBitmap(bitmap));
97 m_frames[0].m_haveMetadata = true; 105 m_frames[0].m_haveMetadata = true;
98 } 106 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 302
295 canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefaul t(adjustedDstRect.size()))); 303 canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefaul t(adjustedDstRect.size())));
296 304
297 if (orientation.usesWidthAsHeight()) { 305 if (orientation.usesWidthAsHeight()) {
298 // The destination rect will have it's width and height already reve rsed for the orientation of 306 // The destination rect will have it's width and height already reve rsed for the orientation of
299 // the image, as it was needed for page layout, so we need to revers e it back here. 307 // the image, as it was needed for page layout, so we need to revers e it back here.
300 adjustedDstRect = FloatRect(adjustedDstRect.x(), adjustedDstRect.y() , adjustedDstRect.height(), adjustedDstRect.width()); 308 adjustedDstRect = FloatRect(adjustedDstRect.x(), adjustedDstRect.y() , adjustedDstRect.height(), adjustedDstRect.width());
301 } 309 }
302 } 310 }
303 311
312 if (RefPtr<ColorSpaceProfile> source = colorProfile()) {
313 // Tagged images (those that have a color profile) are drawn color-corre ct on supported platforms.
314 RefPtr<ColorSpaceProfile> screen = screenColorProfile(currentScreenId()) ;
315 if (RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(source .get(), screen.get())) {
316 fprintf(stderr, "BitmapImage::draw color transform [%s]\n", colorSpa ceFilterKey(colorTransform.get()).latin1().data());
317 if (currentScreenId()) {
318 if (drawingToCanvasElement()) // FIXME: debug for the <canvas> c ase.
319 exit(0);
320 const_cast<SkPaint*>(&paint)->setColorFilter(colorTransform.get( ));
321 } else {
322 if (!drawingToCanvasElement()) // FIXME: Only <canvas> draws out side normal paint flows.
323 exit(0);
324 // FIXME: normal bitmap drawing paths apply the transform filter , but the canvas drawing
325 // path does not. Paint with the color transform, into a local I magebuffer, then extract
326 // the result as a SkImage, which will be used to do the final d rawImageRect() pass.
327 SkPaint transformPaint;
328 transformPaint.setColorFilter(colorTransform.get());
329 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size(), current FrameKnownToBeOpaque() ? Opaque : NonOpaque);
330 FloatRect source = IntRect(IntPoint(), size());
331 SkCanvas::SrcRectConstraint skSrcRectClamp = WebCoreClampingMode ToSkiaRectConstraint(Image::ClampImageToSourceRect);
332 buffer->canvas()->drawImageRect(image.get(), source, source, &tr ansformPaint, skSrcRectClamp);
333 image = buffer->newSkImageSnapshot(PreferNoAcceleration);
334 }
335 fflush(stderr);
336 }
337 } else {
338 // For sRGB assumed images: easy, just interpolate the sRGB color profil e here as the src profile?
339 // FIXME: untagged images should be drawn from sRGB color space, per CSS 2.1 onwards, a change that
340 // would also require that all CSS content, including <canvas>, be drawn from sRGB space to match,
341 // and the same for plugins (Flash, NaCl) which don't define their color space at all, <video> and
342 // OOPIF, and so on ...
343 }
344
304 SkRect skSrcRect = adjustedSrcRect; 345 SkRect skSrcRect = adjustedSrcRect;
305 canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, 346 canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, WebCo reClampingModeToSkiaRectConstraint(clampMode));
306 WebCoreClampingModeToSkiaRectConstraint(clampMode));
307 canvas->restoreToCount(initialSaveCount); 347 canvas->restoreToCount(initialSaveCount);
308 348
309 if (currentFrameIsLazyDecoded()) 349 if (currentFrameIsLazyDecoded())
310 PlatformInstrumentation::didDrawLazyPixelRef(image->uniqueID()); 350 PlatformInstrumentation::didDrawLazyPixelRef(image->uniqueID());
311 351
312 if (ImageObserver* observer = imageObserver()) 352 if (ImageObserver* observer = imageObserver())
313 observer->didDraw(this); 353 observer->didDraw(this);
314 354
315 startAnimation(); 355 startAnimation();
316 } 356 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 destroyDecodedDataIfNecessary(); 704 destroyDecodedDataIfNecessary();
665 705
666 // We need to draw this frame if we advanced to it while not skipping, or if 706 // We need to draw this frame if we advanced to it while not skipping, or if
667 // while trying to skip frames we hit the last frame and thus had to stop. 707 // while trying to skip frames we hit the last frame and thus had to stop.
668 if (skippingFrames != advancedAnimation) 708 if (skippingFrames != advancedAnimation)
669 imageObserver()->animationAdvanced(this); 709 imageObserver()->animationAdvanced(this);
670 return advancedAnimation; 710 return advancedAnimation;
671 } 711 }
672 712
673 } // namespace blink 713 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698