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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h"
7 #include "base/debug/trace_event.h"
8 #include "ui/ozone/common/gpu/ozone_gpu_message_params.h"
9 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
10 #include "ui/ozone/platform/dri/channel_observer.h"
14 GpuPlatformSupportHostGbm::GpuPlatformSupportHostGbm()
15 : host_id_(-1), sender_(NULL) {
18 GpuPlatformSupportHostGbm::~GpuPlatformSupportHostGbm() {}
20 bool GpuPlatformSupportHostGbm::IsConnected() const {
21 return sender_ != NULL;
24 void GpuPlatformSupportHostGbm::RegisterHandler(
25 GpuPlatformSupportHost* handler) {
26 handlers_.push_back(handler);
29 void GpuPlatformSupportHostGbm::UnregisterHandler(
30 GpuPlatformSupportHost* handler) {
31 std::vector<GpuPlatformSupportHost*>::iterator it =
32 std::find(handlers_.begin(), handlers_.end(), handler);
33 if (it != handlers_.end())
37 void GpuPlatformSupportHostGbm::AddChannelObserver(ChannelObserver* observer) {
38 channel_observers_.AddObserver(observer);
41 observer->OnChannelEstablished();
44 void GpuPlatformSupportHostGbm::RemoveChannelObserver(
45 ChannelObserver* observer) {
46 channel_observers_.RemoveObserver(observer);
49 void GpuPlatformSupportHostGbm::OnChannelEstablished(int host_id,
50 IPC::Sender* sender) {
52 "GpuPlatformSupportHostGbm::OnChannelEstablished",
58 while (!queued_messages_.empty()) {
59 Send(queued_messages_.front());
60 queued_messages_.pop();
63 for (size_t i = 0; i < handlers_.size(); ++i)
64 handlers_[i]->OnChannelEstablished(host_id, sender);
67 ChannelObserver, channel_observers_, OnChannelEstablished());
70 void GpuPlatformSupportHostGbm::OnChannelDestroyed(int host_id) {
72 "GpuPlatformSupportHostGbm::OnChannelDestroyed",
75 if (host_id_ == host_id) {
80 ChannelObserver, channel_observers_, OnChannelDestroyed());
83 for (size_t i = 0; i < handlers_.size(); ++i)
84 handlers_[i]->OnChannelDestroyed(host_id);
87 bool GpuPlatformSupportHostGbm::OnMessageReceived(const IPC::Message& message) {
88 for (size_t i = 0; i < handlers_.size(); ++i)
89 if (handlers_[i]->OnMessageReceived(message))
95 bool GpuPlatformSupportHostGbm::Send(IPC::Message* message) {
97 return sender_->Send(message);
99 queued_messages_.push(message);
103 void GpuPlatformSupportHostGbm::SetHardwareCursor(
104 gfx::AcceleratedWidget widget,
105 const std::vector<SkBitmap>& bitmaps,
106 const gfx::Point& location,
107 int frame_delay_ms) {
108 Send(new OzoneGpuMsg_CursorSet(widget, bitmaps, location, frame_delay_ms));
111 void GpuPlatformSupportHostGbm::MoveHardwareCursor(
112 gfx::AcceleratedWidget widget,
113 const gfx::Point& location) {
114 Send(new OzoneGpuMsg_CursorMove(widget, location));