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

Side by Side Diff: Source/core/platform/image-decoders/ImageDecoder.h

Issue 15350006: Decode GIF image frames on demand. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008-2009 Torch Mobile, Inc. 3 * Copyright (C) 2008-2009 Torch Mobile, Inc.
4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
5 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) 5 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // FrameData::clear()). 110 // FrameData::clear()).
111 PassNativeImagePtr asNewNativeImage() const; 111 PassNativeImagePtr asNewNativeImage() const;
112 112
113 bool hasAlpha() const; 113 bool hasAlpha() const;
114 const IntRect& originalFrameRect() const { return m_originalFrameRect; } 114 const IntRect& originalFrameRect() const { return m_originalFrameRect; }
115 FrameStatus status() const { return m_status; } 115 FrameStatus status() const { return m_status; }
116 unsigned duration() const { return m_duration; } 116 unsigned duration() const { return m_duration; }
117 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } 117 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; }
118 bool premultiplyAlpha() const { return m_premultiplyAlpha; } 118 bool premultiplyAlpha() const { return m_premultiplyAlpha; }
119 void reportMemoryUsage(MemoryObjectInfo*) const; 119 void reportMemoryUsage(MemoryObjectInfo*) const;
120 size_t requiredPreviousFrameIndex() const { return m_requiredPreviousFra meIndex; }
120 121
121 void setHasAlpha(bool alpha); 122 void setHasAlpha(bool alpha);
122 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } 123 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; }
123 void setStatus(FrameStatus status); 124 void setStatus(FrameStatus status);
124 void setDuration(unsigned duration) { m_duration = duration; } 125 void setDuration(unsigned duration) { m_duration = duration; }
125 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } 126 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; }
126 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } 127 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; }
128 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) { m_requir edPreviousFrameIndex = previousFrameIndex; }
127 129
128 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, un signed a) 130 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, un signed a)
129 { 131 {
130 setRGBA(getAddr(x, y), r, g, b, a); 132 setRGBA(getAddr(x, y), r, g, b, a);
131 } 133 }
132 134
133 inline PixelData* getAddr(int x, int y) 135 inline PixelData* getAddr(int x, int y)
134 { 136 {
135 return m_bitmap->bitmap().getAddr32(x, y); 137 return m_bitmap->bitmap().getAddr32(x, y);
136 } 138 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 SkBitmap::Allocator* m_allocator; 197 SkBitmap::Allocator* m_allocator;
196 bool m_hasAlpha; 198 bool m_hasAlpha;
197 IntRect m_originalFrameRect; // This will always just be the entire 199 IntRect m_originalFrameRect; // This will always just be the entire
198 // buffer except for GIF frames whose 200 // buffer except for GIF frames whose
199 // original rect was smaller than the 201 // original rect was smaller than the
200 // overall image size. 202 // overall image size.
201 FrameStatus m_status; 203 FrameStatus m_status;
202 unsigned m_duration; 204 unsigned m_duration;
203 FrameDisposalMethod m_disposalMethod; 205 FrameDisposalMethod m_disposalMethod;
204 bool m_premultiplyAlpha; 206 bool m_premultiplyAlpha;
207
208 // The frame that must be decoded before this frame can be decoded.
209 // |notFound| if this frame doesn't require any previous frame.
210 size_t m_requiredPreviousFrameIndex;
205 }; 211 };
206 212
207 // ImageDecoder is a base for all format-specific decoders 213 // ImageDecoder is a base for all format-specific decoders
208 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. 214 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache.
209 // 215 //
210 // ENABLE(IMAGE_DECODER_DOWN_SAMPLING) allows image decoders to downsample 216 // ENABLE(IMAGE_DECODER_DOWN_SAMPLING) allows image decoders to downsample
211 // at decode time. Image decoders will downsample any images larger than 217 // at decode time. Image decoders will downsample any images larger than
212 // |m_maxNumPixels|. FIXME: Not yet supported by all decoders. 218 // |m_maxNumPixels|. FIXME: Not yet supported by all decoders.
213 class ImageDecoder { 219 class ImageDecoder {
214 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED; 220 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // to enable easy tailcalling. Subclasses may override this to also 370 // to enable easy tailcalling. Subclasses may override this to also
365 // clean up any local data. 371 // clean up any local data.
366 virtual bool setFailed() 372 virtual bool setFailed()
367 { 373 {
368 m_failed = true; 374 m_failed = true;
369 return false; 375 return false;
370 } 376 }
371 377
372 bool failed() const { return m_failed; } 378 bool failed() const { return m_failed; }
373 379
374 // Clears decoded pixel data from before the provided frame unless that 380 // Clears decoded pixel data except the provided frame unless that
375 // data may be needed to decode future frames (e.g. due to GIF frame 381 // data may be needed to decode future frames (e.g. due to GIF frame
376 // compositing). 382 // compositing). Pass a value greater than the frame count to clear
377 virtual void clearFrameBufferCache(size_t) { } 383 // decoded pixel data of all frames.
384 void clearFrameBufferCache(size_t clearExceptFrame);
378 385
379 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) 386 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
380 void setMaxNumPixels(int m) { m_maxNumPixels = m; } 387 void setMaxNumPixels(int m) { m_maxNumPixels = m; }
381 #endif 388 #endif
382 389
383 // If the image has a cursor hot-spot, stores it in the argument 390 // If the image has a cursor hot-spot, stores it in the argument
384 // and returns true. Otherwise returns false. 391 // and returns true. Otherwise returns false.
385 virtual bool hotSpot(IntPoint&) const { return false; } 392 virtual bool hotSpot(IntPoint&) const { return false; }
386 393
387 virtual void reportMemoryUsage(MemoryObjectInfo*) const; 394 virtual void reportMemoryUsage(MemoryObjectInfo*) const;
388 395
389 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) 396 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator)
390 { 397 {
391 // FIXME: this doesn't work for images with multiple frames. 398 // FIXME: this doesn't work for images with multiple frames.
392 if (m_frameBufferCache.isEmpty()) 399 if (m_frameBufferCache.isEmpty())
393 m_frameBufferCache.resize(1); 400 m_frameBufferCache.resize(1);
394 m_frameBufferCache[0].setMemoryAllocator(allocator); 401 m_frameBufferCache[0].setMemoryAllocator(allocator);
395 } 402 }
396 403
397 protected: 404 protected:
405 // Finds the previous required frame for decoding the given frame based
406 // on the parsed meta data. Returns notFound if this frame doesn't
407 // require any previous frame. Subclasses should call this function and
408 // cache the result by calling ImageFrame::setRequiredPreviousFrame()
409 // when a new frame is created.
410 size_t findRequiredPreviousFrame(size_t frameIndex);
411
398 void prepareScaleDataIfNecessary(); 412 void prepareScaleDataIfNecessary();
399 int upperBoundScaledX(int origX, int searchStart = 0); 413 int upperBoundScaledX(int origX, int searchStart = 0);
400 int lowerBoundScaledX(int origX, int searchStart = 0); 414 int lowerBoundScaledX(int origX, int searchStart = 0);
401 int upperBoundScaledY(int origY, int searchStart = 0); 415 int upperBoundScaledY(int origY, int searchStart = 0);
402 int lowerBoundScaledY(int origY, int searchStart = 0); 416 int lowerBoundScaledY(int origY, int searchStart = 0);
403 int scaledY(int origY, int searchStart = 0); 417 int scaledY(int origY, int searchStart = 0);
418 virtual void clearFrameBuffer(size_t frameIndex);
404 419
405 RefPtr<SharedBuffer> m_data; // The encoded data. 420 RefPtr<SharedBuffer> m_data; // The encoded data.
406 Vector<ImageFrame, 1> m_frameBufferCache; 421 Vector<ImageFrame, 1> m_frameBufferCache;
407 bool m_scaled; 422 bool m_scaled;
408 Vector<int> m_scaledColumns; 423 Vector<int> m_scaledColumns;
409 Vector<int> m_scaledRows; 424 Vector<int> m_scaledRows;
410 bool m_premultiplyAlpha; 425 bool m_premultiplyAlpha;
411 bool m_ignoreGammaAndColorProfile; 426 bool m_ignoreGammaAndColorProfile;
412 ImageOrientation m_orientation; 427 ImageOrientation m_orientation;
413 428
(...skipping 10 matching lines...) Expand all
424 IntSize m_size; 439 IntSize m_size;
425 bool m_sizeAvailable; 440 bool m_sizeAvailable;
426 int m_maxNumPixels; 441 int m_maxNumPixels;
427 bool m_isAllDataReceived; 442 bool m_isAllDataReceived;
428 bool m_failed; 443 bool m_failed;
429 }; 444 };
430 445
431 } // namespace WebCore 446 } // namespace WebCore
432 447
433 #endif 448 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698