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

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

Issue 1309393007: [poc] redecode Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: resetColorProfileForTesting rename 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/ColorSpaceProfile.h"
34 #include "platform/graphics/DeferredImageDecoder.h" 35 #include "platform/graphics/DeferredImageDecoder.h"
36 #include "platform/graphics/GraphicsScreen.h"
35 #include "platform/graphics/ImageObserver.h" 37 #include "platform/graphics/ImageObserver.h"
36 #include "platform/graphics/StaticBitmapImage.h" 38 #include "platform/graphics/StaticBitmapImage.h"
37 #include "platform/graphics/skia/SkiaUtils.h" 39 #include "platform/graphics/skia/SkiaUtils.h"
38 #include "third_party/skia/include/core/SkCanvas.h" 40 #include "third_party/skia/include/core/SkCanvas.h"
39 #include "wtf/PassRefPtr.h" 41 #include "wtf/PassRefPtr.h"
42 #include "wtf/RefPtr.h"
40 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
41 44
42 namespace blink { 45 namespace blink {
43 46
44 PassRefPtr<BitmapImage> BitmapImage::createWithOrientationForTesting(const SkBit map& bitmap, ImageOrientation orientation) 47 PassRefPtr<BitmapImage> BitmapImage::createWithOrientationForTesting(const SkBit map& bitmap, ImageOrientation orientation)
45 { 48 {
46 if (bitmap.isNull()) { 49 if (bitmap.isNull()) {
47 return BitmapImage::create(); 50 return BitmapImage::create();
48 } 51 }
49 52
(...skipping 13 matching lines...) Expand all
63 , m_desiredFrameStartTime(0) 66 , m_desiredFrameStartTime(0)
64 , m_frameCount(0) 67 , m_frameCount(0)
65 , m_animationPolicy(ImageAnimationPolicyAllowed) 68 , m_animationPolicy(ImageAnimationPolicyAllowed)
66 , m_animationFinished(false) 69 , m_animationFinished(false)
67 , m_allDataReceived(false) 70 , m_allDataReceived(false)
68 , m_haveSize(false) 71 , m_haveSize(false)
69 , m_sizeAvailable(false) 72 , m_sizeAvailable(false)
70 , m_hasUniformFrameSize(true) 73 , m_hasUniformFrameSize(true)
71 , m_haveFrameCount(false) 74 , m_haveFrameCount(false)
72 { 75 {
76 fprintf(stderr, "BitmapImage %p created (page %ld)\n", this, (long int)curre ntScreenId());
73 } 77 }
74 78
75 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer) 79 BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer)
76 : Image(observer) 80 : Image(observer)
77 , m_size(bitmap.width(), bitmap.height()) 81 , m_size(bitmap.width(), bitmap.height())
78 , m_currentFrame(0) 82 , m_currentFrame(0)
79 , m_repetitionCount(cAnimationNone) 83 , m_repetitionCount(cAnimationNone)
80 , m_repetitionCountStatus(Unknown) 84 , m_repetitionCountStatus(Unknown)
81 , m_repetitionsComplete(0) 85 , m_repetitionsComplete(0)
82 , m_frameCount(1) 86 , m_frameCount(1)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 158 }
155 159
156 void BitmapImage::cacheFrame(size_t index) 160 void BitmapImage::cacheFrame(size_t index)
157 { 161 {
158 size_t numFrames = frameCount(); 162 size_t numFrames = frameCount();
159 if (m_frames.size() < numFrames) 163 if (m_frames.size() < numFrames)
160 m_frames.grow(numFrames); 164 m_frames.grow(numFrames);
161 165
162 int deltaBytes = totalFrameBytes(); 166 int deltaBytes = totalFrameBytes();
163 167
168 fprintf(stderr, "BitmapImage %p cacheframe(index=%d)\n", this, (int)index);
164 169
165 // We are caching frame snapshots. This is OK even for partially decoded fr ames, 170 // We are caching frame snapshots. This is OK even for partially decoded fr ames,
166 // as they are cleared by dataChanged() when new data arrives. 171 // as they are cleared by dataChanged() when new data arrives.
167 m_frames[index].m_frame = m_source.createFrameAtIndex(index); 172 m_frames[index].m_frame = m_source.createFrameAtIndex(index);
168 173
169 m_frames[index].m_orientation = m_source.orientationAtIndex(index); 174 m_frames[index].m_orientation = m_source.orientationAtIndex(index);
170 m_frames[index].m_haveMetadata = true; 175 m_frames[index].m_haveMetadata = true;
171 m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index); 176 m_frames[index].m_isComplete = m_source.frameIsCompleteAtIndex(index);
172 if (repetitionCount(false) != cAnimationNone) 177 if (repetitionCount(false) != cAnimationNone)
173 m_frames[index].m_duration = m_source.frameDurationAtIndex(index); 178 m_frames[index].m_duration = m_source.frameDurationAtIndex(index);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 267
263 String BitmapImage::filenameExtension() const 268 String BitmapImage::filenameExtension() const
264 { 269 {
265 return m_source.filenameExtension(); 270 return m_source.filenameExtension();
266 } 271 }
267 272
268 void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum shouldRespectImag eOrientation, ImageClampingMode clampMode) 273 void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum shouldRespectImag eOrientation, ImageClampingMode clampMode)
269 { 274 {
270 TRACE_EVENT0("skia", "BitmapImage::draw"); 275 TRACE_EVENT0("skia", "BitmapImage::draw");
271 276
277 if (imageColorProfilesEnabled() && hasColorProfile())
278 notifyDeviceProfile(screenColorProfile(currentScreenId()).get());
279
272 RefPtr<SkImage> image = imageForCurrentFrame(); 280 RefPtr<SkImage> image = imageForCurrentFrame();
273 if (!image) 281 if (!image)
274 return; // It's too early and we don't have an image yet. 282 return; // It's too early and we don't have an image yet.
275 283
276 FloatRect adjustedSrcRect = srcRect; 284 FloatRect adjustedSrcRect = srcRect;
277 adjustedSrcRect.intersect(FloatRect(0, 0, image->width(), image->height())); 285 adjustedSrcRect.intersect(FloatRect(0, 0, image->width(), image->height()));
278 286
279 if (adjustedSrcRect.isEmpty() || dstRect.isEmpty()) 287 if (adjustedSrcRect.isEmpty() || dstRect.isEmpty())
280 return; // Nothing to draw. 288 return; // Nothing to draw.
281 289
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 671 }
664 destroyDecodedDataIfNecessary(); 672 destroyDecodedDataIfNecessary();
665 673
666 // We need to draw this frame if we advanced to it while not skipping, or if 674 // 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. 675 // while trying to skip frames we hit the last frame and thus had to stop.
668 if (skippingFrames != advancedAnimation) 676 if (skippingFrames != advancedAnimation)
669 imageObserver()->animationAdvanced(this); 677 imageObserver()->animationAdvanced(this);
670 return advancedAnimation; 678 return advancedAnimation;
671 } 679 }
672 680
681 void BitmapImage::notifyDeviceProfile(ColorSpaceProfile* deviceProfile)
682 {
683 RELEASE_ASSERT(imageColorProfilesEnabled() && hasColorProfile());
684
685 if (m_source.deviceProfile() == deviceProfile)
686 return;
687
688 if (!imageObserver())
689 return;
690
691 imageObserver()->deviceProfileChanged(this, deviceProfile);
692 }
693
694 bool BitmapImage::resetDecoder(ColorSpaceProfile* deviceProfile)
695 {
696 RELEASE_ASSERT(imageColorProfilesEnabled() && hasColorProfile());
697
698 if (m_source.deviceProfile() == deviceProfile)
699 return false;
700
701 fprintf(stderr, "BitmapImage %p resetDecoder\n", this);
702 m_source.resetDecoder();
703 m_source.setDeviceProfile(deviceProfile);
704 return true;
705 }
706
673 } // namespace blink 707 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698