| 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/ImageBufferSurface.h" | 8 #include "platform/graphics/ImageBufferSurface.h" |
| 9 #include "public/platform/WebThread.h" | 9 #include "public/platform/WebThread.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "wtf/LinkedStack.h" | 11 #include "wtf/LinkedStack.h" |
| 12 #include "wtf/OwnPtr.h" | 12 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/RefPtr.h" | 13 #include "wtf/RefPtr.h" |
| 14 | 14 |
| 15 class SkPicture; | 15 class SkPicture; |
| 16 class SkPictureRecorder; | 16 class SkPictureRecorder; |
| 17 class RecordingImageBufferSurfaceTest; | 17 class RecordingImageBufferSurfaceTest; |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 class ImageBuffer; | 21 class ImageBuffer; |
| 22 | 22 |
| 23 class RecordingImageBufferFallbackSurfaceFactory { |
| 24 public: |
| 25 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize&, Opacity
Mode) = 0; |
| 26 virtual ~RecordingImageBufferFallbackSurfaceFactory() { } |
| 27 }; |
| 28 |
| 23 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface { | 29 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface { |
| 24 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; | 30 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; |
| 25 public: | 31 public: |
| 26 RecordingImageBufferSurface(const IntSize&, OpacityMode = NonOpaque); | 32 RecordingImageBufferSurface(const IntSize&, PassOwnPtr<RecordingImageBufferF
allbackSurfaceFactory> fallbackFactory, OpacityMode = NonOpaque); |
| 27 virtual ~RecordingImageBufferSurface(); | 33 virtual ~RecordingImageBufferSurface(); |
| 28 | 34 |
| 29 // Implementation of ImageBufferSurface interfaces | 35 // Implementation of ImageBufferSurface interfaces |
| 30 virtual SkCanvas* canvas() const override; | 36 virtual SkCanvas* canvas() const override; |
| 31 virtual PassRefPtr<SkPicture> getPicture() override; | 37 virtual PassRefPtr<SkPicture> getPicture() override; |
| 32 virtual bool isValid() const override { return true; } | 38 virtual bool isValid() const override { return true; } |
| 33 virtual void willAccessPixels() override; | 39 virtual void willAccessPixels() override; |
| 34 virtual void finalizeFrame(const FloatRect&) override; | 40 virtual void finalizeFrame(const FloatRect&) override; |
| 35 virtual void didClearCanvas() override; | 41 virtual void didClearCanvas() override; |
| 36 virtual void setImageBuffer(ImageBuffer*) override; | 42 virtual void setImageBuffer(ImageBuffer*) override; |
| 37 | 43 |
| 44 // Passthroughs to fallback surface |
| 45 virtual const SkBitmap& bitmap() override; |
| 46 virtual bool restore() override; |
| 47 virtual WebLayer* layer() const override; |
| 48 virtual bool isAccelerated() const override; |
| 49 virtual Platform3DObject getBackingTexture() const override; |
| 50 virtual bool cachedBitmapEnabled() const override; |
| 51 virtual const SkBitmap& cachedBitmap() const override; |
| 52 virtual void invalidateCachedBitmap() override; |
| 53 virtual void updateCachedBitmapIfNeeded() override; |
| 54 virtual void setIsHidden(bool) override; |
| 55 |
| 38 private: | 56 private: |
| 57 typedef ImageBufferSurface INHERITTED; |
| 58 |
| 39 struct StateRec { | 59 struct StateRec { |
| 40 public: | 60 public: |
| 41 SkMatrix m_ctm; | 61 SkMatrix m_ctm; |
| 42 // FIXME: handle transferring non-rectangular clip to the new frame, crb
ug.com/392614 | 62 // FIXME: handle transferring non-rectangular clip to the new frame, crb
ug.com/392614 |
| 43 SkIRect m_clip; | 63 SkIRect m_clip; |
| 44 }; | 64 }; |
| 45 typedef LinkedStack<StateRec> StateStack; | 65 typedef LinkedStack<StateRec> StateStack; |
| 46 friend class ::RecordingImageBufferSurfaceTest; // for unit testing | 66 friend class ::RecordingImageBufferSurfaceTest; // for unit testing |
| 47 void fallBackToRasterCanvas(); | 67 void fallBackToRasterCanvas(); |
| 48 bool initializeCurrentFrame(); | 68 bool initializeCurrentFrame(); |
| 49 bool finalizeFrameInternal(); | 69 bool finalizeFrameInternal(); |
| 50 | 70 |
| 51 // saves current clip and transform matrix of canvas | 71 // saves current clip and transform matrix of canvas |
| 52 bool saveState(SkCanvas*, StateStack*); | 72 bool saveState(SkCanvas*, StateStack*); |
| 53 // we should make sure that we can transfer state in saveState | 73 // we should make sure that we can transfer state in saveState |
| 54 void setCurrentState(SkCanvas*, StateStack*); | 74 void setCurrentState(SkCanvas*, StateStack*); |
| 55 | 75 |
| 56 OwnPtr<SkPictureRecorder> m_currentFrame; | 76 OwnPtr<SkPictureRecorder> m_currentFrame; |
| 57 RefPtr<SkPicture> m_previousFrame; | 77 RefPtr<SkPicture> m_previousFrame; |
| 58 OwnPtr<SkCanvas> m_rasterCanvas; | 78 OwnPtr<ImageBufferSurface> m_fallbackSurface; |
| 59 ImageBuffer* m_imageBuffer; | 79 ImageBuffer* m_imageBuffer; |
| 60 int m_initialSaveCount; | 80 int m_initialSaveCount; |
| 61 bool m_frameWasCleared; | 81 bool m_frameWasCleared; |
| 82 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactory; |
| 62 }; | 83 }; |
| 63 | 84 |
| 64 } // namespace blink | 85 } // namespace blink |
| 65 | 86 |
| 66 #endif | 87 #endif |
| OLD | NEW |