| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 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 17 matching lines...) Expand all Loading... |
| 28 #include "core/platform/image-decoders/ImageDecoder.h" | 28 #include "core/platform/image-decoders/ImageDecoder.h" |
| 29 #include "wtf/PassOwnPtr.h" | 29 #include "wtf/PassOwnPtr.h" |
| 30 | 30 |
| 31 namespace WebCore { | 31 namespace WebCore { |
| 32 | 32 |
| 33 class MockImageDecoderClient { | 33 class MockImageDecoderClient { |
| 34 public: | 34 public: |
| 35 virtual void decoderBeingDestroyed() = 0; | 35 virtual void decoderBeingDestroyed() = 0; |
| 36 virtual void frameBufferRequested() = 0; | 36 virtual void frameBufferRequested() = 0; |
| 37 virtual ImageFrame::FrameStatus frameStatus() = 0; | 37 virtual ImageFrame::FrameStatus frameStatus() = 0; |
| 38 virtual size_t frameCount() = 0; |
| 39 virtual int repetitionCount() const = 0; |
| 40 virtual float frameDuration() const = 0; |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 class MockImageDecoder : public ImageDecoder { | 43 class MockImageDecoder : public ImageDecoder { |
| 41 public: | 44 public: |
| 42 static PassOwnPtr<MockImageDecoder> create(MockImageDecoderClient* client) {
return adoptPtr(new MockImageDecoder(client)); } | 45 static PassOwnPtr<MockImageDecoder> create(MockImageDecoderClient* client) {
return adoptPtr(new MockImageDecoder(client)); } |
| 43 | 46 |
| 44 MockImageDecoder(MockImageDecoderClient* client) | 47 MockImageDecoder(MockImageDecoderClient* client) |
| 45 : ImageDecoder(ImageSource::AlphaPremultiplied, ImageSource::GammaAndCol
orProfileApplied) | 48 : ImageDecoder(ImageSource::AlphaPremultiplied, ImageSource::GammaAndCol
orProfileApplied) |
| 46 , m_frameBufferRequestCount(0) | |
| 47 , m_client(client) | 49 , m_client(client) |
| 48 { } | 50 { } |
| 49 | 51 |
| 50 ~MockImageDecoder() | 52 ~MockImageDecoder() |
| 51 { | 53 { |
| 52 m_client->decoderBeingDestroyed(); | 54 m_client->decoderBeingDestroyed(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 virtual bool setSize(unsigned width, unsigned height) | 57 virtual bool setSize(unsigned width, unsigned height) |
| 56 { | 58 { |
| 57 ImageDecoder::setSize(width, height); | 59 ImageDecoder::setSize(width, height); |
| 58 m_frameBufferCache.resize(1); | 60 m_frameBufferCache.resize(1); |
| 59 m_frameBufferCache[0].setSize(width, height); | 61 m_frameBufferCache[0].setSize(width, height); |
| 60 return true; | 62 return true; |
| 61 } | 63 } |
| 62 | 64 |
| 63 virtual void setFrameHasAlpha(bool hasAlpha) { m_frameBufferCache[0].setHasA
lpha(hasAlpha); } | 65 virtual void setFrameHasAlpha(bool hasAlpha) { m_frameBufferCache[0].setHasA
lpha(hasAlpha); } |
| 64 | 66 |
| 67 virtual size_t frameCount() |
| 68 { |
| 69 return m_client->frameCount(); |
| 70 } |
| 71 |
| 72 virtual int repetitionCount() const |
| 73 { |
| 74 return m_client->repetitionCount(); |
| 75 } |
| 76 |
| 65 virtual ImageFrame* frameBufferAtIndex(size_t) | 77 virtual ImageFrame* frameBufferAtIndex(size_t) |
| 66 { | 78 { |
| 67 ++m_frameBufferRequestCount; | |
| 68 m_client->frameBufferRequested(); | 79 m_client->frameBufferRequested(); |
| 69 | 80 |
| 70 m_frameBufferCache[0].setStatus(m_client->frameStatus()); | 81 m_frameBufferCache[0].setStatus(m_client->frameStatus()); |
| 71 return &m_frameBufferCache[0]; | 82 return &m_frameBufferCache[0]; |
| 72 } | 83 } |
| 73 | 84 |
| 74 int frameBufferRequestCount() const { return m_frameBufferRequestCount; } | 85 virtual bool frameIsCompleteAtIndex(size_t) const |
| 86 { |
| 87 return m_client->frameStatus() == ImageFrame::FrameComplete; |
| 88 } |
| 89 |
| 90 virtual float frameDurationAtIndex(size_t) const |
| 91 { |
| 92 return m_client->frameDuration(); |
| 93 } |
| 75 | 94 |
| 76 private: | 95 private: |
| 77 int m_frameBufferRequestCount; | |
| 78 MockImageDecoderClient* m_client; | 96 MockImageDecoderClient* m_client; |
| 79 }; | 97 }; |
| 80 | 98 |
| 81 } // namespace WebCore | 99 } // namespace WebCore |
| 82 | 100 |
| 83 #endif // MockImageDecoder_h | 101 #endif // MockImageDecoder_h |
| OLD | NEW |