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 #include "ui/ozone/platform/dri/gbm_surface.h" | 5 #include "ui/ozone/platform/dri/gbm_surface.h" |
6 | 6 |
7 #include <gbm.h> | 7 #include <gbm.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/ozone/platform/dri/dri_buffer.h" | 10 #include "ui/ozone/platform/dri/dri_buffer.h" |
| 11 #include "ui/ozone/platform/dri/dri_window_delegate.h" |
11 #include "ui/ozone/platform/dri/dri_wrapper.h" | 12 #include "ui/ozone/platform/dri/dri_wrapper.h" |
12 #include "ui/ozone/platform/dri/gbm_buffer_base.h" | 13 #include "ui/ozone/platform/dri/gbm_buffer_base.h" |
| 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
13 #include "ui/ozone/platform/dri/scanout_buffer.h" | 15 #include "ui/ozone/platform/dri/scanout_buffer.h" |
14 | 16 |
15 namespace ui { | 17 namespace ui { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 class GbmSurfaceBuffer : public GbmBufferBase { | 21 class GbmSurfaceBuffer : public GbmBufferBase { |
20 public: | 22 public: |
21 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer(DriWrapper* dri, | 23 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer(DriWrapper* dri, |
22 gbm_bo* buffer); | 24 gbm_bo* buffer); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 68 } |
67 | 69 |
68 // static | 70 // static |
69 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) { | 71 void GbmSurfaceBuffer::Destroy(gbm_bo* buffer, void* data) { |
70 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data); | 72 GbmSurfaceBuffer* scoped_buffer = static_cast<GbmSurfaceBuffer*>(data); |
71 scoped_buffer->self_ = NULL; | 73 scoped_buffer->self_ = NULL; |
72 } | 74 } |
73 | 75 |
74 } // namespace | 76 } // namespace |
75 | 77 |
76 GbmSurface::GbmSurface( | 78 GbmSurface::GbmSurface(DriWindowDelegate* window_delegate, |
77 const base::WeakPtr<HardwareDisplayController>& controller, | 79 gbm_device* device, |
78 gbm_device* device, | 80 DriWrapper* dri) |
79 DriWrapper* dri) | 81 : GbmSurfaceless(window_delegate), |
80 : GbmSurfaceless(controller), | |
81 gbm_device_(device), | 82 gbm_device_(device), |
82 dri_(dri), | 83 dri_(dri), |
83 native_surface_(NULL), | 84 native_surface_(NULL), |
84 current_buffer_(NULL) {} | 85 current_buffer_(NULL) { |
| 86 } |
85 | 87 |
86 GbmSurface::~GbmSurface() { | 88 GbmSurface::~GbmSurface() { |
87 if (current_buffer_) | 89 if (current_buffer_) |
88 gbm_surface_release_buffer(native_surface_, current_buffer_); | 90 gbm_surface_release_buffer(native_surface_, current_buffer_); |
89 | 91 |
90 if (native_surface_) | 92 if (native_surface_) |
91 gbm_surface_destroy(native_surface_); | 93 gbm_surface_destroy(native_surface_); |
92 } | 94 } |
93 | 95 |
94 bool GbmSurface::Initialize() { | 96 bool GbmSurface::Initialize() { |
| 97 // If we're initializing the surface without a controller (possible on startup |
| 98 // where the surface creation can happen before the native window delegate |
| 99 // IPCs arrive), initialize the size to a valid value such that surface |
| 100 // creation doesn't fail. |
| 101 gfx::Size size(1, 1); |
| 102 if (window_delegate_->GetController()) { |
| 103 const drmModeModeInfo& mode = window_delegate_->GetController()->get_mode(); |
| 104 size.SetSize(mode.hdisplay, mode.vdisplay); |
| 105 } |
95 // TODO(dnicoara) Check underlying system support for pixel format. | 106 // TODO(dnicoara) Check underlying system support for pixel format. |
96 native_surface_ = gbm_surface_create( | 107 native_surface_ = |
97 gbm_device_, | 108 gbm_surface_create(gbm_device_, |
98 controller_->get_mode().hdisplay, | 109 size.width(), |
99 controller_->get_mode().vdisplay, | 110 size.height(), |
100 GBM_BO_FORMAT_XRGB8888, | 111 GBM_BO_FORMAT_XRGB8888, |
101 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); | 112 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); |
102 | 113 |
103 if (!native_surface_) | 114 if (!native_surface_) |
104 return false; | 115 return false; |
105 | 116 |
106 size_.SetSize(controller_->get_mode().hdisplay, | 117 size_ = size; |
107 controller_->get_mode().vdisplay); | |
108 return true; | 118 return true; |
109 } | 119 } |
110 | 120 |
111 intptr_t GbmSurface::GetNativeWindow() { | 121 intptr_t GbmSurface::GetNativeWindow() { |
112 DCHECK(native_surface_); | 122 DCHECK(native_surface_); |
113 return reinterpret_cast<intptr_t>(native_surface_); | 123 return reinterpret_cast<intptr_t>(native_surface_); |
114 } | 124 } |
115 | 125 |
116 bool GbmSurface::ResizeNativeWindow(const gfx::Size& viewport_size) { | 126 bool GbmSurface::ResizeNativeWindow(const gfx::Size& viewport_size) { |
117 if (size_ == viewport_size) | 127 if (size_ == viewport_size) |
(...skipping 10 matching lines...) Expand all Loading... |
128 GbmSurfaceBuffer::GetBuffer(pending_buffer); | 138 GbmSurfaceBuffer::GetBuffer(pending_buffer); |
129 if (!primary) { | 139 if (!primary) { |
130 primary = GbmSurfaceBuffer::CreateBuffer(dri_, pending_buffer); | 140 primary = GbmSurfaceBuffer::CreateBuffer(dri_, pending_buffer); |
131 if (!primary) { | 141 if (!primary) { |
132 LOG(ERROR) << "Failed to associate the buffer with the controller"; | 142 LOG(ERROR) << "Failed to associate the buffer with the controller"; |
133 return false; | 143 return false; |
134 } | 144 } |
135 } | 145 } |
136 | 146 |
137 // The primary buffer is a special case. | 147 // The primary buffer is a special case. |
138 controller_->QueueOverlayPlane(OverlayPlane(primary)); | 148 if (window_delegate_->GetController()) |
| 149 window_delegate_->GetController()->QueueOverlayPlane(OverlayPlane(primary)); |
139 | 150 |
140 if (!GbmSurfaceless::OnSwapBuffers()) | 151 if (!GbmSurfaceless::OnSwapBuffers()) |
141 return false; | 152 return false; |
142 | 153 |
143 // If there was a frontbuffer, it is no longer active. Release it back to GBM. | 154 // If there was a frontbuffer, it is no longer active. Release it back to GBM. |
144 if (current_buffer_) | 155 if (current_buffer_) |
145 gbm_surface_release_buffer(native_surface_, current_buffer_); | 156 gbm_surface_release_buffer(native_surface_, current_buffer_); |
146 | 157 |
147 current_buffer_ = pending_buffer; | 158 current_buffer_ = pending_buffer; |
148 return true; | 159 return true; |
149 } | 160 } |
150 | 161 |
151 } // namespace ui | 162 } // namespace ui |
OLD | NEW |