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 15class SkPicture; 16class SkPictureRecorder; 17class RecordingImageBufferSurfaceTest; 18 19namespace blink { 20 21class ImageBuffer; 22 23class PLATFORM_EXPORT RecordingImageBufferSurface : public ImageBufferSurface { 24 WTF_MAKE_NONCOPYABLE(RecordingImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; 25public: 26 RecordingImageBufferSurface(const IntSize&, OpacityMode = NonOpaque); 27 virtual ~RecordingImageBufferSurface(); 28 29 // Implementation of ImageBufferSurface interfaces 30 virtual SkCanvas* canvas() const OVERRIDE; 31 virtual PassRefPtr<SkPicture> getPicture() OVERRIDE; 32 virtual bool isValid() const OVERRIDE { return true; } 33 virtual void willAccessPixels() OVERRIDE; 34 virtual void finalizeFrame(const FloatRect&) OVERRIDE; 35 virtual void didClearCanvas() OVERRIDE; 36 virtual void setImageBuffer(ImageBuffer*) OVERRIDE; 37 38private: 39 struct StateRec { 40 public: 41 SkMatrix m_ctm; 42 // FIXME: handle transferring non-rectangular clip to the new frame, crbug.com/392614 43 SkIRect m_clip; 44 }; 45 typedef LinkedStack<StateRec> StateStack; 46 friend class ::RecordingImageBufferSurfaceTest; // for unit testing 47 void fallBackToRasterCanvas(); 48 bool initializeCurrentFrame(); 49 bool finalizeFrameInternal(); 50 51 // saves current clip and transform matrix of canvas 52 bool saveState(SkCanvas*, StateStack*); 53 // we should make sure that we can transfer state in saveState 54 void setCurrentState(SkCanvas*, StateStack*); 55 56 OwnPtr<SkPictureRecorder> m_currentFrame; 57 RefPtr<SkPicture> m_previousFrame; 58 OwnPtr<SkCanvas> m_rasterCanvas; 59 ImageBuffer* m_imageBuffer; 60 int m_initialSaveCount; 61 bool m_frameWasCleared; 62}; 63 64} // namespace blink 65 66#endif 67