Home | History | Annotate | Download | only in dri
      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.
      4 
      5 #include "ui/ozone/platform/dri/gpu_platform_support_gbm.h"
      6 
      7 #include "ipc/ipc_message_macros.h"
      8 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
      9 #include "ui/ozone/platform/dri/dri_surface_factory.h"
     10 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h"
     11 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h"
     12 
     13 namespace ui {
     14 
     15 GpuPlatformSupportGbm::GpuPlatformSupportGbm(
     16     DriSurfaceFactory* dri,
     17     DriWindowDelegateManager* window_manager,
     18     ScreenManager* screen_manager)
     19     : sender_(NULL),
     20       dri_(dri),
     21       window_manager_(window_manager),
     22       screen_manager_(screen_manager) {
     23 }
     24 
     25 GpuPlatformSupportGbm::~GpuPlatformSupportGbm() {}
     26 
     27 void GpuPlatformSupportGbm::AddHandler(scoped_ptr<GpuPlatformSupport> handler) {
     28   handlers_.push_back(handler.release());
     29 }
     30 
     31 void GpuPlatformSupportGbm::OnChannelEstablished(IPC::Sender* sender) {
     32   sender_ = sender;
     33 
     34   for (size_t i = 0; i < handlers_.size(); ++i)
     35     handlers_[i]->OnChannelEstablished(sender);
     36 }
     37 
     38 bool GpuPlatformSupportGbm::OnMessageReceived(const IPC::Message& message) {
     39   bool handled = true;
     40 
     41   IPC_BEGIN_MESSAGE_MAP(GpuPlatformSupportGbm, message)
     42   IPC_MESSAGE_HANDLER(OzoneGpuMsg_CreateWindowDelegate, OnCreateWindowDelegate)
     43   IPC_MESSAGE_HANDLER(OzoneGpuMsg_DestroyWindowDelegate,
     44                       OnDestroyWindowDelegate)
     45   IPC_MESSAGE_HANDLER(OzoneGpuMsg_WindowBoundsChanged, OnWindowBoundsChanged)
     46 
     47   IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorSet, OnCursorSet)
     48   IPC_MESSAGE_HANDLER(OzoneGpuMsg_CursorMove, OnCursorMove)
     49   IPC_MESSAGE_UNHANDLED(handled = false);
     50   IPC_END_MESSAGE_MAP()
     51 
     52   if (!handled)
     53     for (size_t i = 0; i < handlers_.size(); ++i)
     54       if (handlers_[i]->OnMessageReceived(message))
     55         return true;
     56 
     57   return false;
     58 }
     59 
     60 void GpuPlatformSupportGbm::OnCreateWindowDelegate(
     61     gfx::AcceleratedWidget widget) {
     62   // Due to how the GPU process starts up this IPC call may happen after the IPC
     63   // to create a surface. Since a surface wants to know the window associated
     64   // with it, we create it ahead of time. So when this call happens we do not
     65   // create a delegate if it already exists.
     66   if (!window_manager_->HasWindowDelegate(widget)) {
     67     scoped_ptr<DriWindowDelegate> delegate(
     68         new DriWindowDelegateImpl(widget, screen_manager_));
     69     delegate->Initialize();
     70     window_manager_->AddWindowDelegate(widget, delegate.Pass());
     71   }
     72 }
     73 
     74 void GpuPlatformSupportGbm::OnDestroyWindowDelegate(
     75     gfx::AcceleratedWidget widget) {
     76   scoped_ptr<DriWindowDelegate> delegate =
     77       window_manager_->RemoveWindowDelegate(widget);
     78   delegate->Shutdown();
     79 }
     80 
     81 void GpuPlatformSupportGbm::OnWindowBoundsChanged(gfx::AcceleratedWidget widget,
     82                                                   const gfx::Rect& bounds) {
     83   window_manager_->GetWindowDelegate(widget)->OnBoundsChanged(bounds);
     84 }
     85 
     86 void GpuPlatformSupportGbm::OnCursorSet(gfx::AcceleratedWidget widget,
     87                                         const std::vector<SkBitmap>& bitmaps,
     88                                         const gfx::Point& location,
     89                                         int frame_delay_ms) {
     90   dri_->SetHardwareCursor(widget, bitmaps, location, frame_delay_ms);
     91 }
     92 
     93 void GpuPlatformSupportGbm::OnCursorMove(gfx::AcceleratedWidget widget,
     94                                          const gfx::Point& location) {
     95   dri_->MoveHardwareCursor(widget, location);
     96 }
     97 
     98 }  // namespace ui
     99