Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/browser/compositor/software_output_device_mac.h

Issue 2866683003: Use more than double buffering in SoftwareOutputDeviceMac (Closed)
Patch Set: Fix compile Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/compositor/software_output_device_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MAC_H_ 5 #ifndef CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MAC_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MAC_H_
7 7
8 #include <IOSurface/IOSurface.h> 8 #include <IOSurface/IOSurface.h>
9 #include <list>
9 10
10 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "cc/output/software_output_device.h" 13 #include "cc/output/software_output_device.h"
14 #include "content/common/content_export.h"
13 #include "third_party/skia/include/core/SkRefCnt.h" 15 #include "third_party/skia/include/core/SkRefCnt.h"
14 #include "third_party/skia/include/core/SkRegion.h" 16 #include "third_party/skia/include/core/SkRegion.h"
15 #include "ui/gfx/vsync_provider.h" 17 #include "ui/gfx/vsync_provider.h"
16 18
17 class SkCanvas; 19 class SkCanvas;
18 20
19 namespace ui { 21 namespace ui {
20 class Compositor; 22 class Compositor;
21 } 23 }
22 24
23 namespace content { 25 namespace content {
24 26
25 class SoftwareOutputDeviceMac : 27 class CONTENT_EXPORT SoftwareOutputDeviceMac : public cc::SoftwareOutputDevice,
26 public cc::SoftwareOutputDevice, 28 public gfx::VSyncProvider {
27 public gfx::VSyncProvider {
28 public: 29 public:
29 explicit SoftwareOutputDeviceMac(ui::Compositor* compositor); 30 explicit SoftwareOutputDeviceMac(ui::Compositor* compositor);
30 ~SoftwareOutputDeviceMac() override; 31 ~SoftwareOutputDeviceMac() override;
31 32
32 // cc::SoftwareOutputDevice implementation. 33 // cc::SoftwareOutputDevice implementation.
33 void Resize(const gfx::Size& pixel_size, float scale_factor) override; 34 void Resize(const gfx::Size& pixel_size, float scale_factor) override;
34 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override; 35 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override;
35 void EndPaint() override; 36 void EndPaint() override;
36 void DiscardBackbuffer() override; 37 void DiscardBackbuffer() override;
37 void EnsureBackbuffer() override; 38 void EnsureBackbuffer() override;
38 gfx::VSyncProvider* GetVSyncProvider() override; 39 gfx::VSyncProvider* GetVSyncProvider() override;
39 40
40 // gfx::VSyncProvider implementation. 41 // gfx::VSyncProvider implementation.
41 void GetVSyncParameters( 42 void GetVSyncParameters(
42 const gfx::VSyncProvider::UpdateVSyncCallback& callback) override; 43 const gfx::VSyncProvider::UpdateVSyncCallback& callback) override;
43 44
45 // Testing methods.
46 SkRegion LastCopyRegionForTesting() const {
47 return last_copy_region_for_testing_;
48 }
49 IOSurfaceRef CurrentPaintIOSurfaceForTesting() const {
50 return current_paint_buffer_->io_surface.get();
51 }
52 size_t BufferQueueSizeForTesting() const { return buffer_queue_.size(); }
53
44 private: 54 private:
45 bool EnsureBuffersExist(); 55 struct Buffer {
56 Buffer();
57 ~Buffer();
58 base::ScopedCFTypeRef<IOSurfaceRef> io_surface;
59 // The damage of all BeginPaints since this buffer was the back buffer.
60 SkRegion accumulated_damage;
61 };
46 62
47 // Copy the pixels from the previous buffer to the new buffer. 63 // Copy the pixels from the previous buffer to the new buffer, and union
48 void CopyPreviousBufferDamage(const SkRegion& new_damage_rect); 64 // |new_damage_rect| into all |buffer_queue_|'s accumulated damages.
65 void UpdateAndCopyBufferDamage(Buffer* previous_paint_buffer,
66 const SkRegion& new_damage_rect);
49 67
50 ui::Compositor* compositor_; 68 ui::Compositor* compositor_ = nullptr;
51 gfx::Size pixel_size_; 69 gfx::Size pixel_size_;
52 float scale_factor_; 70 float scale_factor_ = 1;
53 71
54 // This surface is double-buffered. The two buffers are in |io_surfaces_|, 72 // The queue of buffers. The back is the most recently painted buffer
55 // and the index of the current buffer is |current_buffer_|. 73 // (sometimes equal to |current_paint_buffer_|), and the front is the
56 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces_[2]; 74 // least recently painted buffer.
57 int current_index_; 75 std::list<std::unique_ptr<Buffer>> buffer_queue_;
58 76
59 // The previous frame's damage rectangle. Used to copy unchanged content 77 // A pointer to the last element of |buffer_queue_| during paint. It is only
60 // between buffers in CopyPreviousBufferDamage. 78 // valid between BeginPaint and EndPaint.
61 SkRegion previous_buffer_damage_region_; 79 Buffer* current_paint_buffer_ = nullptr;
62 80
63 // The SkCanvas wrapps the mapped current IOSurface. It is valid only between 81 // The SkCanvas wraps the mapped |current_paint_buffer_|'s IOSurface. It is
64 // BeginPaint and EndPaint. 82 // valid only between BeginPaint and EndPaint.
65 std::unique_ptr<SkCanvas> canvas_; 83 std::unique_ptr<SkCanvas> current_paint_canvas_;
66 84
67 gfx::VSyncProvider::UpdateVSyncCallback update_vsync_callback_; 85 gfx::VSyncProvider::UpdateVSyncCallback update_vsync_callback_;
68 86
87 SkRegion last_copy_region_for_testing_;
88
69 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceMac); 89 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDeviceMac);
70 }; 90 };
71 91
72 } // namespace content 92 } // namespace content
73 93
74 #endif // CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MAC_H_ 94 #endif // CONTENT_BROWSER_COMPOSITOR_SOFTWARE_OUTPUT_DEVICE_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/compositor/software_output_device_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698