| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RecordingImageBufferSurface_h | 5 #ifndef RecordingImageBufferSurface_h |
| 6 #define RecordingImageBufferSurface_h | 6 #define RecordingImageBufferSurface_h |
| 7 | 7 |
| 8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/GraphicsContextClient.h" | |
| 10 #include "platform/graphics/ImageBufferSurface.h" | 9 #include "platform/graphics/ImageBufferSurface.h" |
| 11 #include "public/platform/WebThread.h" | 10 #include "public/platform/WebThread.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "wtf/LinkedStack.h" | 12 #include "wtf/LinkedStack.h" |
| 14 #include "wtf/OwnPtr.h" | 13 #include "wtf/OwnPtr.h" |
| 15 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
| 16 | 15 |
| 17 class SkPicture; | 16 class SkPicture; |
| 18 class SkPictureRecorder; | 17 class SkPictureRecorder; |
| 19 class RecordingImageBufferSurfaceTest; | 18 class RecordingImageBufferSurfaceTest; |
| 20 | 19 |
| 21 namespace blink { | 20 namespace blink { |
| 22 | 21 |
| 23 class ImageBuffer; | 22 class ImageBuffer; |
| 24 | 23 |
| 25 class RecordingImageBufferFallbackSurfaceFactory { | 24 class RecordingImageBufferFallbackSurfaceFactory { |
| 26 public: | 25 public: |
| 27 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize&, Opacity
Mode) = 0; | 26 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize&, Opacity
Mode) = 0; |
| 28 virtual ~RecordingImageBufferFallbackSurfaceFactory() { } | 27 virtual ~RecordingImageBufferFallbackSurfaceFactory() { } |
| 29 }; | 28 }; |
| 30 | 29 |
| 31 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface, p
ublic GraphicsContextClient { | 30 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface { |
| 32 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; | 31 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; |
| 33 public: | 32 public: |
| 34 RecordingImageBufferSurface(const IntSize&, PassOwnPtr<RecordingImageBufferF
allbackSurfaceFactory> fallbackFactory, OpacityMode = NonOpaque); | 33 RecordingImageBufferSurface(const IntSize&, PassOwnPtr<RecordingImageBufferF
allbackSurfaceFactory> fallbackFactory, OpacityMode = NonOpaque); |
| 35 virtual ~RecordingImageBufferSurface(); | 34 virtual ~RecordingImageBufferSurface(); |
| 36 | 35 |
| 37 // Implementation of ImageBufferSurface interfaces | 36 // Implementation of ImageBufferSurface interfaces |
| 38 virtual SkCanvas* canvas() const override; | 37 SkCanvas* canvas() const override; |
| 39 virtual PassRefPtr<SkPicture> getPicture() override; | 38 PassRefPtr<SkPicture> getPicture() override; |
| 40 virtual void willDrawVideo() override; | 39 void willDrawVideo() override; |
| 41 virtual void didDraw() override; | 40 void didDraw() override; |
| 42 virtual bool isValid() const override { return true; } | 41 bool isValid() const override { return true; } |
| 43 virtual bool isRecording() const override { return !m_fallbackSurface; } | 42 bool isRecording() const override { return !m_fallbackSurface; } |
| 44 virtual void willAccessPixels() override; | 43 void willAccessPixels() override; |
| 45 virtual void finalizeFrame(const FloatRect&) override; | 44 void willOverwriteCanvas() override; |
| 46 virtual void setImageBuffer(ImageBuffer*) override; | 45 void finalizeFrame(const FloatRect&) override; |
| 47 virtual PassRefPtr<SkImage> newImageSnapshot() const override; | 46 void setImageBuffer(ImageBuffer*) override; |
| 48 virtual bool needsClipTracking() const override { return !m_fallbackSurface;
} | 47 PassRefPtr<SkImage> newImageSnapshot() const override; |
| 48 bool needsClipTracking() const override { return !m_fallbackSurface; } |
| 49 void draw(GraphicsContext*, const FloatRect& destRect, const FloatRect& srcR
ect, SkXfermode::Mode, bool needsCopy) override; | 49 void draw(GraphicsContext*, const FloatRect& destRect, const FloatRect& srcR
ect, SkXfermode::Mode, bool needsCopy) override; |
| 50 | 50 |
| 51 // Passthroughs to fallback surface | 51 // Passthroughs to fallback surface |
| 52 virtual const SkBitmap& bitmap() override; | 52 const SkBitmap& bitmap() override; |
| 53 virtual bool restore() override; | 53 bool restore() override; |
| 54 virtual WebLayer* layer() const override; | 54 WebLayer* layer() const override; |
| 55 virtual bool isAccelerated() const override; | 55 bool isAccelerated() const override; |
| 56 virtual Platform3DObject getBackingTexture() const override; | 56 Platform3DObject getBackingTexture() const override; |
| 57 virtual bool cachedBitmapEnabled() const override; | 57 bool cachedBitmapEnabled() const override; |
| 58 virtual const SkBitmap& cachedBitmap() const override; | 58 const SkBitmap& cachedBitmap() const override; |
| 59 virtual void invalidateCachedBitmap() override; | 59 void invalidateCachedBitmap() override; |
| 60 virtual void updateCachedBitmapIfNeeded() override; | 60 void updateCachedBitmapIfNeeded() override; |
| 61 virtual void setIsHidden(bool) override; | 61 void setIsHidden(bool) override; |
| 62 | 62 |
| 63 // Implementation of GraphicsContextClient | |
| 64 virtual void willOverwriteCanvas() override; | |
| 65 private: | 63 private: |
| 66 friend class ::RecordingImageBufferSurfaceTest; // for unit testing | 64 friend class ::RecordingImageBufferSurfaceTest; // for unit testing |
| 67 void fallBackToRasterCanvas(); | 65 void fallBackToRasterCanvas(); |
| 68 bool initializeCurrentFrame(); | 66 bool initializeCurrentFrame(); |
| 69 bool finalizeFrameInternal(); | 67 bool finalizeFrameInternal(); |
| 70 | 68 |
| 71 OwnPtr<SkPictureRecorder> m_currentFrame; | 69 OwnPtr<SkPictureRecorder> m_currentFrame; |
| 72 RefPtr<SkPicture> m_previousFrame; | 70 RefPtr<SkPicture> m_previousFrame; |
| 73 OwnPtr<ImageBufferSurface> m_fallbackSurface; | 71 OwnPtr<ImageBufferSurface> m_fallbackSurface; |
| 74 ImageBuffer* m_imageBuffer; | 72 ImageBuffer* m_imageBuffer; |
| 75 int m_initialSaveCount; | 73 int m_initialSaveCount; |
| 76 bool m_frameWasCleared; | 74 bool m_frameWasCleared; |
| 77 bool m_didRecordDrawCommandsInCurrentFrame; | 75 bool m_didRecordDrawCommandsInCurrentFrame; |
| 78 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactory; | 76 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactory; |
| 79 }; | 77 }; |
| 80 | 78 |
| 81 } // namespace blink | 79 } // namespace blink |
| 82 | 80 |
| 83 #endif | 81 #endif |
| OLD | NEW |