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
3 // found in the LICENSE file.
5 #ifndef RecordingImageBufferSurface_h
6 #define RecordingImageBufferSurface_h
8 #include "platform/graphics/ImageBufferSurface.h"
9 #include "public/platform/WebThread.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "wtf/LinkedStack.h"
12 #include "wtf/OwnPtr.h"
13 #include "wtf/RefPtr.h"
16 class SkPictureRecorder;
17 class RecordingImageBufferSurfaceTest;
23 class RecordingImageBufferFallbackSurfaceFactory {
25 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize&, OpacityMode) = 0;
26 virtual ~RecordingImageBufferFallbackSurfaceFactory() { }
29 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface {
30 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED;
32 RecordingImageBufferSurface(const IntSize&, PassOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMode = NonOpaque);
33 virtual ~RecordingImageBufferSurface();
35 // Implementation of ImageBufferSurface interfaces
36 virtual SkCanvas* canvas() const override;
37 virtual PassRefPtr<SkPicture> getPicture() override;
38 virtual void willDrawVideo() override;
39 virtual bool isValid() const override { return true; }
40 virtual void willAccessPixels() override;
41 virtual void finalizeFrame(const FloatRect&) override;
42 virtual void didClearCanvas() override;
43 virtual void setImageBuffer(ImageBuffer*) override;
44 virtual PassRefPtr<SkImage> newImageSnapshot() const;
46 // Passthroughs to fallback surface
47 virtual const SkBitmap& bitmap() override;
48 virtual bool restore() override;
49 virtual WebLayer* layer() const override;
50 virtual bool isAccelerated() const override;
51 virtual Platform3DObject getBackingTexture() const override;
52 virtual bool cachedBitmapEnabled() const override;
53 virtual const SkBitmap& cachedBitmap() const override;
54 virtual void invalidateCachedBitmap() override;
55 virtual void updateCachedBitmapIfNeeded() override;
56 virtual void setIsHidden(bool) override;
62 // FIXME: handle transferring non-rectangular clip to the new frame, crbug.com/392614
65 typedef LinkedStack<StateRec> StateStack;
66 friend class ::RecordingImageBufferSurfaceTest; // for unit testing
67 void fallBackToRasterCanvas();
68 bool initializeCurrentFrame();
69 bool finalizeFrameInternal();
71 // saves current clip and transform matrix of canvas
72 bool saveState(SkCanvas*, StateStack*);
73 // we should make sure that we can transfer state in saveState
74 void setCurrentState(SkCanvas*, StateStack*);
76 OwnPtr<SkPictureRecorder> m_currentFrame;
77 RefPtr<SkPicture> m_previousFrame;
78 OwnPtr<ImageBufferSurface> m_fallbackSurface;
79 ImageBuffer* m_imageBuffer;
80 int m_initialSaveCount;
81 bool m_frameWasCleared;
82 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactory;