| 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/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/ImageBufferSurface.h" | 9 #include "platform/graphics/ImageBufferSurface.h" |
| 10 #include "public/platform/WebThread.h" | 10 #include "public/platform/WebThread.h" |
| 11 #include "third_party/skia/include/core/SkRefCnt.h" |
| 11 #include "wtf/Allocator.h" | 12 #include "wtf/Allocator.h" |
| 12 #include "wtf/Noncopyable.h" | 13 #include "wtf/Noncopyable.h" |
| 13 #include "wtf/RefPtr.h" | |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 class SkCanvas; | 16 class SkCanvas; |
| 17 class SkPicture; | 17 class SkPicture; |
| 18 class SkPictureRecorder; | 18 class SkPictureRecorder; |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 class ImageBuffer; | 22 class ImageBuffer; |
| 23 class RecordingImageBufferSurfaceTest; | 23 class RecordingImageBufferSurfaceTest; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 // If the fallbackFactory is null the buffer surface should only be used | 38 // If the fallbackFactory is null the buffer surface should only be used |
| 39 // for one frame and should not be used for any operations which need a | 39 // for one frame and should not be used for any operations which need a |
| 40 // raster surface, (i.e. writePixels). | 40 // raster surface, (i.e. writePixels). |
| 41 // Only #getPicture should be used to access the resulting frame. | 41 // Only #getPicture should be used to access the resulting frame. |
| 42 RecordingImageBufferSurface(const IntSize&, std::unique_ptr<RecordingImageBu
fferFallbackSurfaceFactory> fallbackFactory = nullptr, OpacityMode = NonOpaque,
sk_sp<SkColorSpace> = nullptr); | 42 RecordingImageBufferSurface(const IntSize&, std::unique_ptr<RecordingImageBu
fferFallbackSurfaceFactory> fallbackFactory = nullptr, OpacityMode = NonOpaque,
sk_sp<SkColorSpace> = nullptr); |
| 43 ~RecordingImageBufferSurface() override; | 43 ~RecordingImageBufferSurface() override; |
| 44 | 44 |
| 45 // Implementation of ImageBufferSurface interfaces | 45 // Implementation of ImageBufferSurface interfaces |
| 46 SkCanvas* canvas() override; | 46 SkCanvas* canvas() override; |
| 47 void disableDeferral(DisableDeferralReason) override; | 47 void disableDeferral(DisableDeferralReason) override; |
| 48 PassRefPtr<SkPicture> getPicture() override; | 48 sk_sp<SkPicture> getPicture() override; |
| 49 void flush(FlushReason) override; | 49 void flush(FlushReason) override; |
| 50 void didDraw(const FloatRect&) override; | 50 void didDraw(const FloatRect&) override; |
| 51 bool isValid() const override { return true; } | 51 bool isValid() const override { return true; } |
| 52 bool isRecording() const override { return !m_fallbackSurface; } | 52 bool isRecording() const override { return !m_fallbackSurface; } |
| 53 bool writePixels(const SkImageInfo& origInfo, const void* pixels, size_t row
Bytes, int x, int y) override; | 53 bool writePixels(const SkImageInfo& origInfo, const void* pixels, size_t row
Bytes, int x, int y) override; |
| 54 void willOverwriteCanvas() override; | 54 void willOverwriteCanvas() override; |
| 55 virtual void finalizeFrame(const FloatRect&); | 55 virtual void finalizeFrame(const FloatRect&); |
| 56 void setImageBuffer(ImageBuffer*) override; | 56 void setImageBuffer(ImageBuffer*) override; |
| 57 PassRefPtr<SkImage> newImageSnapshot(AccelerationHint, SnapshotReason) overr
ide; | 57 sk_sp<SkImage> newImageSnapshot(AccelerationHint, SnapshotReason) override; |
| 58 void draw(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcR
ect, SkXfermode::Mode) override; | 58 void draw(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcR
ect, SkXfermode::Mode) override; |
| 59 bool isExpensiveToPaint() override; | 59 bool isExpensiveToPaint() override; |
| 60 void setHasExpensiveOp() override { m_currentFrameHasExpensiveOp = true; } | 60 void setHasExpensiveOp() override { m_currentFrameHasExpensiveOp = true; } |
| 61 | 61 |
| 62 // Passthroughs to fallback surface | 62 // Passthroughs to fallback surface |
| 63 bool restore() override; | 63 bool restore() override; |
| 64 WebLayer* layer() const override; | 64 WebLayer* layer() const override; |
| 65 bool isAccelerated() const override; | 65 bool isAccelerated() const override; |
| 66 void setIsHidden(bool) override; | 66 void setIsHidden(bool) override; |
| 67 | 67 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 94 FallbackReasonCount, | 94 FallbackReasonCount, |
| 95 }; | 95 }; |
| 96 private: | 96 private: |
| 97 friend class RecordingImageBufferSurfaceTest; // for unit testing | 97 friend class RecordingImageBufferSurfaceTest; // for unit testing |
| 98 void fallBackToRasterCanvas(FallbackReason); | 98 void fallBackToRasterCanvas(FallbackReason); |
| 99 void initializeCurrentFrame(); | 99 void initializeCurrentFrame(); |
| 100 bool finalizeFrameInternal(FallbackReason*); | 100 bool finalizeFrameInternal(FallbackReason*); |
| 101 int approximateOpCount(); | 101 int approximateOpCount(); |
| 102 | 102 |
| 103 std::unique_ptr<SkPictureRecorder> m_currentFrame; | 103 std::unique_ptr<SkPictureRecorder> m_currentFrame; |
| 104 RefPtr<SkPicture> m_previousFrame; | 104 sk_sp<SkPicture> m_previousFrame; |
| 105 std::unique_ptr<ImageBufferSurface> m_fallbackSurface; | 105 std::unique_ptr<ImageBufferSurface> m_fallbackSurface; |
| 106 ImageBuffer* m_imageBuffer; | 106 ImageBuffer* m_imageBuffer; |
| 107 int m_initialSaveCount; | 107 int m_initialSaveCount; |
| 108 int m_currentFramePixelCount; | 108 int m_currentFramePixelCount; |
| 109 int m_previousFramePixelCount; | 109 int m_previousFramePixelCount; |
| 110 bool m_frameWasCleared; | 110 bool m_frameWasCleared; |
| 111 bool m_didRecordDrawCommandsInCurrentFrame; | 111 bool m_didRecordDrawCommandsInCurrentFrame; |
| 112 bool m_currentFrameHasExpensiveOp; | 112 bool m_currentFrameHasExpensiveOp; |
| 113 bool m_previousFrameHasExpensiveOp; | 113 bool m_previousFrameHasExpensiveOp; |
| 114 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactor
y; | 114 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> m_fallbackFactor
y; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 } // namespace blink | 117 } // namespace blink |
| 118 | 118 |
| 119 #endif | 119 #endif |
| OLD | NEW |