OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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). |
377 virtual void clearFrameBufferCache(size_t) { } | 383 void clearFrameBufferCache(size_t clearExceptFrame); |
378 | 384 |
379 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) | 385 #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |
380 void setMaxNumPixels(int m) { m_maxNumPixels = m; } | 386 void setMaxNumPixels(int m) { m_maxNumPixels = m; } |
381 #endif | 387 #endif |
382 | 388 |
383 // If the image has a cursor hot-spot, stores it in the argument | 389 // If the image has a cursor hot-spot, stores it in the argument |
384 // and returns true. Otherwise returns false. | 390 // and returns true. Otherwise returns false. |
385 virtual bool hotSpot(IntPoint&) const { return false; } | 391 virtual bool hotSpot(IntPoint&) const { return false; } |
386 | 392 |
387 virtual void reportMemoryUsage(MemoryObjectInfo*) const; | 393 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
388 | 394 |
389 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) | 395 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) |
390 { | 396 { |
391 // FIXME: this doesn't work for images with multiple frames. | 397 // FIXME: this doesn't work for images with multiple frames. |
392 if (m_frameBufferCache.isEmpty()) | 398 if (m_frameBufferCache.isEmpty()) |
393 m_frameBufferCache.resize(1); | 399 m_frameBufferCache.resize(1); |
394 m_frameBufferCache[0].setMemoryAllocator(allocator); | 400 m_frameBufferCache[0].setMemoryAllocator(allocator); |
395 } | 401 } |
396 | 402 |
397 protected: | 403 protected: |
| 404 // Finds the previous required frame for decoding the given frame. |
| 405 // Returns notFound if this frame doesn't require any previous frame. |
| 406 // Subclasses should call this function and cache the result by calling |
| 407 // ImageFrame::setRequiredPreviousFrame() when a new frame is created. |
| 408 size_t findRequiredPreviousFrame(size_t frameIndex); |
| 409 |
398 void prepareScaleDataIfNecessary(); | 410 void prepareScaleDataIfNecessary(); |
399 int upperBoundScaledX(int origX, int searchStart = 0); | 411 int upperBoundScaledX(int origX, int searchStart = 0); |
400 int lowerBoundScaledX(int origX, int searchStart = 0); | 412 int lowerBoundScaledX(int origX, int searchStart = 0); |
401 int upperBoundScaledY(int origY, int searchStart = 0); | 413 int upperBoundScaledY(int origY, int searchStart = 0); |
402 int lowerBoundScaledY(int origY, int searchStart = 0); | 414 int lowerBoundScaledY(int origY, int searchStart = 0); |
403 int scaledY(int origY, int searchStart = 0); | 415 int scaledY(int origY, int searchStart = 0); |
404 | 416 |
405 RefPtr<SharedBuffer> m_data; // The encoded data. | 417 RefPtr<SharedBuffer> m_data; // The encoded data. |
406 Vector<ImageFrame, 1> m_frameBufferCache; | 418 Vector<ImageFrame, 1> m_frameBufferCache; |
407 bool m_scaled; | 419 bool m_scaled; |
(...skipping 16 matching lines...) Expand all Loading... |
424 IntSize m_size; | 436 IntSize m_size; |
425 bool m_sizeAvailable; | 437 bool m_sizeAvailable; |
426 int m_maxNumPixels; | 438 int m_maxNumPixels; |
427 bool m_isAllDataReceived; | 439 bool m_isAllDataReceived; |
428 bool m_failed; | 440 bool m_failed; |
429 }; | 441 }; |
430 | 442 |
431 } // namespace WebCore | 443 } // namespace WebCore |
432 | 444 |
433 #endif | 445 #endif |
OLD | NEW |