Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / graphics / RecordingImageBufferSurface.h
blob9cd503228ccdb69a0b9d6cc6ca40c6184fa9cb45
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/GraphicsContext.h"
9 #include "platform/graphics/ImageBufferSurface.h"
10 #include "public/platform/WebThread.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "wtf/LinkedStack.h"
13 #include "wtf/OwnPtr.h"
14 #include "wtf/RefPtr.h"
16 class SkPicture;
17 class SkPictureRecorder;
19 namespace blink {
21 class ImageBuffer;
22 class RecordingImageBufferSurfaceTest;
24 class RecordingImageBufferFallbackSurfaceFactory {
25 public:
26 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize&, OpacityMode) = 0;
27 virtual ~RecordingImageBufferFallbackSurfaceFactory() { }
30 class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface {
31 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED(RecordingImageBufferSurface);
32 public:
33 RecordingImageBufferSurface(const IntSize&, PassOwnPtr<RecordingImageBufferFallbackSurfaceFactory> fallbackFactory, OpacityMode = NonOpaque);
34 ~RecordingImageBufferSurface() override;
36 // Implementation of ImageBufferSurface interfaces
37 SkCanvas* canvas() override;
38 void disableDeferral() override;
39 PassRefPtr<SkPicture> getPicture() override;
40 void flush() override;
41 void didDraw(const FloatRect&) override;
42 bool isValid() const override { return true; }
43 bool isRecording() const override { return !m_fallbackSurface; }
44 bool writePixels(const SkImageInfo& origInfo, const void* pixels, size_t rowBytes, int x, int y) override;
45 void willOverwriteCanvas() override;
46 virtual void finalizeFrame(const FloatRect&);
47 void setImageBuffer(ImageBuffer*) override;
48 PassRefPtr<SkImage> newImageSnapshot() override;
49 void draw(GraphicsContext*, const FloatRect& destRect, const FloatRect& srcRect, SkXfermode::Mode) override;
50 bool isExpensiveToPaint() override;
51 void setHasExpensiveOp() override { m_currentFrameHasExpensiveOp = true; }
53 // Passthroughs to fallback surface
54 const SkBitmap& deprecatedBitmapForOverwrite() override;
55 bool restore() override;
56 WebLayer* layer() const override;
57 bool isAccelerated() const override;
58 void setIsHidden(bool) override;
60 private:
61 friend class RecordingImageBufferSurfaceTest; // for unit testing
62 void fallBackToRasterCanvas();
63 bool initializeCurrentFrame();
64 bool finalizeFrameInternal();
65 int approximateOpCount();
67 OwnPtr<SkPictureRecorder> m_currentFrame;
68 RefPtr<SkPicture> m_previousFrame;
69 OwnPtr<ImageBufferSurface> m_fallbackSurface;
70 ImageBuffer* m_imageBuffer;
71 int m_initialSaveCount;
72 int m_currentFramePixelCount;
73 int m_previousFramePixelCount;
74 bool m_frameWasCleared;
75 bool m_didRecordDrawCommandsInCurrentFrame;
76 bool m_currentFrameHasExpensiveOp;
77 bool m_previousFrameHasExpensiveOp;
78 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactory;
81 } // namespace blink
83 #endif