OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ | 5 #ifndef SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ |
6 #define SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ | 6 #define SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <mutex> | 9 #include <mutex> |
10 #include <queue> | 10 #include <queue> |
(...skipping 16 matching lines...) Expand all Loading... | |
27 public: | 27 public: |
28 GpuOutput(mojo::InterfaceHandle<mojo::ContextProvider> context_provider, | 28 GpuOutput(mojo::InterfaceHandle<mojo::ContextProvider> context_provider, |
29 const SchedulerCallbacks& scheduler_callbacks, | 29 const SchedulerCallbacks& scheduler_callbacks, |
30 const base::Closure& error_callback); | 30 const base::Closure& error_callback); |
31 ~GpuOutput() override; | 31 ~GpuOutput() override; |
32 | 32 |
33 Scheduler* GetScheduler() override; | 33 Scheduler* GetScheduler() override; |
34 void SubmitFrame(const scoped_refptr<RenderFrame>& frame) override; | 34 void SubmitFrame(const scoped_refptr<RenderFrame>& frame) override; |
35 | 35 |
36 private: | 36 private: |
37 struct FrameData : public base::RefCountedThreadSafe<FrameData> { | 37 struct FrameData { |
38 FrameData(const scoped_refptr<RenderFrame>& frame, int64_t submit_time); | 38 FrameData(const scoped_refptr<RenderFrame>& frame, int64_t submit_time); |
39 ~FrameData(); | |
39 | 40 |
40 void Recycle(); | 41 void ClearDrawState(); |
41 | 42 |
42 const scoped_refptr<RenderFrame> frame; | 43 const scoped_refptr<RenderFrame> frame; |
43 const int64_t submit_time; | 44 const int64_t submit_time; |
mikejurka
2016/05/25 21:11:46
i would be a bit more descriptive, call this draw_
jeffbrown
2016/05/25 23:45:44
I think that might get confused with draw_time. s
| |
44 bool drawn = false; // set when DrawFrame is called | 45 bool drawn = false; // set when |DrawFrame| is called |
45 int64_t draw_time = 0; // 0 if not drawn | 46 bool finished = false; // set when drawing is finished |
mikejurka
2016/05/25 21:11:46
why not call these draw_started and draw_finished?
jeffbrown
2016/05/25 23:45:44
Sure, draw_started and draw_finished makes sense.
| |
46 int64_t wait_time = 0; // 0 if not drawn | 47 int64_t draw_time = 0; // time when drawing began |
mikejurka
2016/05/25 21:11:46
similarly, why not call this draw_start_time
jeffbrown
2016/05/25 23:45:44
Ok.
| |
48 int64_t wait_time = 0; // time when awaiting for finish began | |
mikejurka
2016/05/25 21:11:46
wait_time implies a timespan rather than an absolu
jeffbrown
2016/05/25 23:45:43
draw_issued_time?
| |
47 | 49 |
48 private: | 50 private: |
49 friend class base::RefCountedThreadSafe<FrameData>; | |
50 | |
51 ~FrameData(); | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(FrameData); | 51 DISALLOW_COPY_AND_ASSIGN(FrameData); |
54 }; | 52 }; |
55 | 53 |
56 // |GpuRasterizer::Callbacks|: | 54 // |GpuRasterizer::Callbacks|: |
57 void OnRasterizerReady(int64_t vsync_timebase, | 55 void OnRasterizerReady(int64_t vsync_timebase, |
58 int64_t vsync_interval) override; | 56 int64_t vsync_interval) override; |
59 void OnRasterizerSuspended() override; | 57 void OnRasterizerSuspended() override; |
60 void OnRasterizerFinishedDraw(bool presented) override; | 58 void OnRasterizerFinishedDraw(bool presented) override; |
61 void OnRasterizerError() override; | 59 void OnRasterizerError() override; |
62 | 60 |
(...skipping 16 matching lines...) Expand all Loading... | |
79 // The rasterizer itself runs on its own thread. | 77 // The rasterizer itself runs on its own thread. |
80 std::unique_ptr<base::Thread> rasterizer_thread_; | 78 std::unique_ptr<base::Thread> rasterizer_thread_; |
81 scoped_refptr<base::SingleThreadTaskRunner> rasterizer_task_runner_; | 79 scoped_refptr<base::SingleThreadTaskRunner> rasterizer_task_runner_; |
82 base::WaitableEvent rasterizer_initialized_; | 80 base::WaitableEvent rasterizer_initialized_; |
83 std::unique_ptr<GpuRasterizer> rasterizer_; | 81 std::unique_ptr<GpuRasterizer> rasterizer_; |
84 | 82 |
85 // Holds state shared between the compositor and rasterizer threads. | 83 // Holds state shared between the compositor and rasterizer threads. |
86 struct { | 84 struct { |
87 std::mutex mutex; // guards all shared state | 85 std::mutex mutex; // guards all shared state |
88 | 86 |
89 // The most recently submitted frame. | 87 // Queue of frames. |
90 // Only null until the first frame has been submitted. | 88 // |
91 scoped_refptr<FrameData> current_frame_data; | 89 // The head of this queue consists of up to |pipeline_depth| frames |
92 | 90 // which are drawn and awaiting finish. These frames are popped off |
93 // Frames drawn and awaiting completion by the rasterizer. | 91 // the queue when finished unless the queue would become empty (such |
94 std::queue<scoped_refptr<FrameData>> drawn_frames_awaiting_finish; | 92 // that we always retain the current frame as the tail). |
93 // | |
94 // The tail of this queue is a single frame which is either drawn or | |
95 // finished and represents the current (most recently submitted) | |
96 // content. | |
97 // | |
98 // The queue is only ever empty until the first frame is submitted. | |
99 // Subsequently, it always contains at least one frame. | |
100 std::queue<std::unique_ptr<FrameData>> frames; | |
95 | 101 |
96 // Set to true when the rasterizer is ready to draw. | 102 // Set to true when the rasterizer is ready to draw. |
97 bool rasterizer_ready = false; | 103 bool rasterizer_ready = false; |
98 | 104 |
99 // Set to true when a request to draw has been scheduled. | 105 // Set to true when a request to draw has been scheduled. |
100 bool draw_scheduled = false; | 106 bool draw_scheduled = false; |
101 } shared_state_; | 107 } shared_state_; |
102 | 108 |
103 DISALLOW_COPY_AND_ASSIGN(GpuOutput); | 109 DISALLOW_COPY_AND_ASSIGN(GpuOutput); |
104 }; | 110 }; |
105 | 111 |
106 } // namespace compositor | 112 } // namespace compositor |
107 | 113 |
108 #endif // SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ | 114 #endif // SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ |
OLD | NEW |