Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / RecordingImageBufferSurface.h
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.
4
5 #ifndef RecordingImageBufferSurface_h
6 #define RecordingImageBufferSurface_h
7
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"
14
15 class SkPicture;
16 class SkPictureRecorder;
17 class RecordingImageBufferSurfaceTest;
18
19 namespace blink {
20
21 class ImageBuffer;
22
23 class RecordingImageBufferFallbackSurfaceFactory {
24 public:
25     virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize&, OpacityMode) = 0;
26     virtual ~RecordingImageBufferFallbackSurfaceFactory() { }
27 };
28
29 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface {
30     WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED;
31 public:
32     RecordingImageBufferSurface(const IntSize&, PassOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMode = NonOpaque);
33     virtual ~RecordingImageBufferSurface();
34
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;
45
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;
57
58 private:
59     struct StateRec {
60     public:
61         SkMatrix m_ctm;
62         // FIXME: handle transferring non-rectangular clip to the new frame, crbug.com/392614
63         SkIRect m_clip;
64     };
65     typedef LinkedStack<StateRec> StateStack;
66     friend class ::RecordingImageBufferSurfaceTest; // for unit testing
67     void fallBackToRasterCanvas();
68     bool initializeCurrentFrame();
69     bool finalizeFrameInternal();
70
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*);
75
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;
83 };
84
85 } // namespace blink
86
87 #endif