| 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 CONTENT_RENDERER_GPU_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_GPU_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_GPU_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_ | 6 #define CONTENT_RENDERER_GPU_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_ |
| 7 | 7 |
| 8 #include <unordered_set> | 8 #include <unordered_set> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "cc/scheduler/begin_frame_source.h" | 13 #include "cc/scheduler/begin_frame_source.h" |
| 14 #include "content/renderer/gpu/compositor_forwarding_message_filter.h" | 14 #include "content/renderer/gpu/compositor_forwarding_message_filter.h" |
| 15 | 15 |
| 16 namespace IPC { | 16 namespace IPC { |
| 17 class Message; | 17 class Message; |
| 18 class SyncMessageFilter; | 18 class SyncMessageFilter; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 // This class can be created only on the main thread, but then becomes pinned | 23 // This class can be created only on the main thread, but then becomes pinned |
| 24 // to a fixed thread where cc::Scheduler is running. | 24 // to a fixed thread where cc::Scheduler is running. |
| 25 // |
| 26 // TODO(enne): This only implements the BeginFrameSource interface to |
| 27 // make it easier to give to cc as an external begin frame source. In the |
| 28 // future, if this is owned by an output surface, then the internal |
| 29 // cc::ExternalBeginFrameSource can be the BeginFrameSource passed to cc |
| 30 // directly rather than proxied by this class. |
| 25 class CompositorExternalBeginFrameSource | 31 class CompositorExternalBeginFrameSource |
| 26 : public cc::BeginFrameSource, | 32 : public cc::BeginFrameSource, |
| 33 public cc::ExternalBeginFrameSourceClient, |
| 27 public NON_EXPORTED_BASE(base::NonThreadSafe) { | 34 public NON_EXPORTED_BASE(base::NonThreadSafe) { |
| 28 public: | 35 public: |
| 29 explicit CompositorExternalBeginFrameSource( | 36 explicit CompositorExternalBeginFrameSource( |
| 30 CompositorForwardingMessageFilter* filter, | 37 CompositorForwardingMessageFilter* filter, |
| 31 IPC::SyncMessageFilter* sync_message_filter, | 38 IPC::SyncMessageFilter* sync_message_filter, |
| 32 int routing_id); | 39 int routing_id); |
| 33 ~CompositorExternalBeginFrameSource() override; | 40 ~CompositorExternalBeginFrameSource() override; |
| 34 | 41 |
| 35 // cc::BeginFrameSource implementation. | 42 // cc::BeginFrameSource implementation. |
| 36 void AddObserver(cc::BeginFrameObserver* obs) override; | 43 void AddObserver(cc::BeginFrameObserver* obs) override; |
| 37 void RemoveObserver(cc::BeginFrameObserver* obs) override; | 44 void RemoveObserver(cc::BeginFrameObserver* obs) override; |
| 38 void DidFinishFrame(cc::BeginFrameObserver* obs, | 45 void DidFinishFrame(cc::BeginFrameObserver* obs, |
| 39 size_t remaining_frames) override {} | 46 size_t remaining_frames) override {} |
| 40 | 47 |
| 48 // cc::ExternalBeginFrameSourceClient implementation. |
| 49 void OnNeedsBeginFrames(bool need_begin_frames) override; |
| 50 |
| 41 private: | 51 private: |
| 42 class CompositorExternalBeginFrameSourceProxy | 52 class CompositorExternalBeginFrameSourceProxy |
| 43 : public base::RefCountedThreadSafe< | 53 : public base::RefCountedThreadSafe< |
| 44 CompositorExternalBeginFrameSourceProxy> { | 54 CompositorExternalBeginFrameSourceProxy> { |
| 45 public: | 55 public: |
| 46 explicit CompositorExternalBeginFrameSourceProxy( | 56 explicit CompositorExternalBeginFrameSourceProxy( |
| 47 CompositorExternalBeginFrameSource* begin_frame_source) | 57 CompositorExternalBeginFrameSource* begin_frame_source) |
| 48 : begin_frame_source_(begin_frame_source) {} | 58 : begin_frame_source_(begin_frame_source) {} |
| 49 void ClearBeginFrameSource() { begin_frame_source_ = NULL; } | 59 void ClearBeginFrameSource() { begin_frame_source_ = NULL; } |
| 50 void OnMessageReceived(const IPC::Message& message) { | 60 void OnMessageReceived(const IPC::Message& message) { |
| 51 if (begin_frame_source_) | 61 if (begin_frame_source_) |
| 52 begin_frame_source_->OnMessageReceived(message); | 62 begin_frame_source_->OnMessageReceived(message); |
| 53 } | 63 } |
| 54 | 64 |
| 55 private: | 65 private: |
| 56 friend class base::RefCountedThreadSafe< | 66 friend class base::RefCountedThreadSafe< |
| 57 CompositorExternalBeginFrameSourceProxy>; | 67 CompositorExternalBeginFrameSourceProxy>; |
| 58 virtual ~CompositorExternalBeginFrameSourceProxy() {} | 68 virtual ~CompositorExternalBeginFrameSourceProxy() {} |
| 59 | 69 |
| 60 CompositorExternalBeginFrameSource* begin_frame_source_; | 70 CompositorExternalBeginFrameSource* begin_frame_source_; |
| 61 | 71 |
| 62 DISALLOW_COPY_AND_ASSIGN(CompositorExternalBeginFrameSourceProxy); | 72 DISALLOW_COPY_AND_ASSIGN(CompositorExternalBeginFrameSourceProxy); |
| 63 }; | 73 }; |
| 64 | 74 |
| 65 void SetClientReady(); | |
| 66 void OnMessageReceived(const IPC::Message& message); | 75 void OnMessageReceived(const IPC::Message& message); |
| 67 | |
| 68 void OnSetBeginFrameSourcePaused(bool paused); | 76 void OnSetBeginFrameSourcePaused(bool paused); |
| 69 void OnBeginFrame(const cc::BeginFrameArgs& args); | 77 void OnBeginFrame(const cc::BeginFrameArgs& args); |
| 70 bool Send(IPC::Message* message); | 78 bool Send(IPC::Message* message); |
| 71 | 79 |
| 80 // Shared helper implementation. |
| 81 cc::ExternalBeginFrameSource external_begin_frame_source_; |
| 82 |
| 72 scoped_refptr<CompositorForwardingMessageFilter> begin_frame_source_filter_; | 83 scoped_refptr<CompositorForwardingMessageFilter> begin_frame_source_filter_; |
| 73 scoped_refptr<CompositorExternalBeginFrameSourceProxy> | 84 scoped_refptr<CompositorExternalBeginFrameSourceProxy> |
| 74 begin_frame_source_proxy_; | 85 begin_frame_source_proxy_; |
| 75 scoped_refptr<IPC::SyncMessageFilter> message_sender_; | 86 scoped_refptr<IPC::SyncMessageFilter> message_sender_; |
| 76 int routing_id_; | 87 int routing_id_; |
| 77 CompositorForwardingMessageFilter::Handler begin_frame_source_filter_handler_; | 88 CompositorForwardingMessageFilter::Handler begin_frame_source_filter_handler_; |
| 78 cc::BeginFrameArgs missed_begin_frame_args_; | |
| 79 std::unordered_set<cc::BeginFrameObserver*> observers_; | |
| 80 bool paused_ = false; | |
| 81 | 89 |
| 82 DISALLOW_COPY_AND_ASSIGN(CompositorExternalBeginFrameSource); | 90 DISALLOW_COPY_AND_ASSIGN(CompositorExternalBeginFrameSource); |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 } // namespace content | 93 } // namespace content |
| 86 | 94 |
| 87 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_ | 95 #endif // CONTENT_RENDERER_GPU_COMPOSITOR_EXTERNAL_BEGIN_FRAME_SOURCE_H_ |
| OLD | NEW |