OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ | |
6 #define SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ | |
7 | |
8 #include <memory> | |
9 #include <mutex> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/task_runner.h" | |
16 #include "base/threading/thread.h" | |
17 #include "mojo/services/gpu/interfaces/context_provider.mojom.h" | |
18 #include "services/gfx/compositor/backend/output.h" | |
19 #include "services/gfx/compositor/backend/vsync_scheduler.h" | |
20 | |
21 namespace compositor { | |
22 | |
23 class GpuRasterizer; | |
24 | |
25 // Renderer backed by a ContextProvider. | |
26 class GpuOutput : public Output { | |
27 public: | |
28 GpuOutput(mojo::ContextProviderPtr context_provider, | |
29 const SchedulerCallbacks& scheduler_callbacks, | |
30 const base::Closure& error_callback); | |
31 ~GpuOutput() override; | |
32 | |
33 Scheduler* scheduler() override; | |
34 void SubmitFrame(const std::shared_ptr<RenderFrame>& frame) override; | |
35 | |
36 private: | |
37 // Frame queue, held by a std::shared_ptr. | |
38 // This object acts as a shared fifo between both threads. | |
39 class FrameQueue { | |
40 public: | |
41 FrameQueue(); | |
42 ~FrameQueue(); | |
43 | |
44 // Puts a pending frame into the queue, drops existing frames if needed. | |
45 // Returns true if the queue was previously empty. | |
46 bool PutFrame(const std::shared_ptr<RenderFrame>& frame); | |
47 | |
48 // Takes a pending frame from the queue. | |
49 std::shared_ptr<RenderFrame> TakeFrame(); | |
abarth
2016/01/10 04:22:09
Do we want to use shared_ptr in production code?
jeffbrown
2016/01/16 03:28:31
I don't have strong opinions on this. shared_ptr
| |
50 | |
51 private: | |
52 std::mutex mutex_; | |
53 std::shared_ptr<RenderFrame> next_frame_; // guarded by |mutex_| | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(FrameQueue); | |
56 }; | |
57 | |
58 // Wrapper around state which is only accessible by the rasterizer thread. | |
59 class RasterizerDelegate { | |
60 public: | |
61 explicit RasterizerDelegate(const std::shared_ptr<FrameQueue>& frame_queue); | |
62 ~RasterizerDelegate(); | |
63 | |
64 void CreateRasterizer( | |
65 mojo::InterfacePtrInfo<mojo::ContextProvider> context_provider_info, | |
66 const std::shared_ptr<VsyncScheduler>& scheduler, | |
67 const scoped_refptr<base::TaskRunner>& task_runner, | |
68 const base::Closure& error_callback); | |
69 | |
70 void SubmitNextFrame(); | |
71 | |
72 private: | |
73 std::shared_ptr<FrameQueue> frame_queue_; | |
74 std::unique_ptr<GpuRasterizer> rasterizer_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(RasterizerDelegate); | |
77 }; | |
78 | |
79 std::shared_ptr<FrameQueue> frame_queue_; | |
80 std::shared_ptr<VsyncScheduler> scheduler_; | |
81 scoped_ptr<RasterizerDelegate> rasterizer_delegate_; // can't use unique_ptr | |
82 // here due to | |
83 // base::Bind (sadness) | |
84 std::unique_ptr<base::Thread> rasterizer_thread_; | |
85 scoped_refptr<base::SingleThreadTaskRunner> rasterizer_task_runner_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(GpuOutput); | |
88 }; | |
89 | |
90 } // namespace compositor | |
91 | |
92 #endif // SERVICES_GFX_COMPOSITOR_BACKEND_GPU_OUTPUT_H_ | |
OLD | NEW |