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/drm/gpu/gbm_surface.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_surface.h" |
6 | 6 |
7 #include <gbm.h> | 7 #include <gbm.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" | 11 #include "ui/ozone/platform/drm/gpu/drm_buffer.h" |
12 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 12 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
13 #include "ui/ozone/platform/drm/gpu/gbm_buffer_base.h" | 13 #include "ui/ozone/platform/drm/gpu/gbm_buffer_base.h" |
14 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 14 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
15 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" | 15 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" |
16 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h" | 16 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
| 22 void DoNothing(gfx::SwapResult) { |
| 23 } |
| 24 |
22 class GbmSurfaceBuffer : public GbmBufferBase { | 25 class GbmSurfaceBuffer : public GbmBufferBase { |
23 public: | 26 public: |
24 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer( | 27 static scoped_refptr<GbmSurfaceBuffer> CreateBuffer( |
25 const scoped_refptr<DrmDevice>& drm, | 28 const scoped_refptr<DrmDevice>& drm, |
26 gbm_bo* buffer); | 29 gbm_bo* buffer); |
27 static scoped_refptr<GbmSurfaceBuffer> GetBuffer(gbm_bo* buffer); | 30 static scoped_refptr<GbmSurfaceBuffer> GetBuffer(gbm_bo* buffer); |
28 | 31 |
29 private: | 32 private: |
30 GbmSurfaceBuffer(const scoped_refptr<DrmDevice>& drm, gbm_bo* bo); | 33 GbmSurfaceBuffer(const scoped_refptr<DrmDevice>& drm, gbm_bo* bo); |
31 ~GbmSurfaceBuffer() override; | 34 ~GbmSurfaceBuffer() override; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 127 } |
125 | 128 |
126 bool GbmSurface::ResizeNativeWindow(const gfx::Size& viewport_size) { | 129 bool GbmSurface::ResizeNativeWindow(const gfx::Size& viewport_size) { |
127 if (size_ == viewport_size) | 130 if (size_ == viewport_size) |
128 return true; | 131 return true; |
129 | 132 |
130 return false; | 133 return false; |
131 } | 134 } |
132 | 135 |
133 bool GbmSurface::OnSwapBuffers() { | 136 bool GbmSurface::OnSwapBuffers() { |
134 return OnSwapBuffersAsync(base::Bind(&base::DoNothing)); | 137 return OnSwapBuffersAsync(base::Bind(&DoNothing)); |
135 } | 138 } |
136 | 139 |
137 bool GbmSurface::OnSwapBuffersAsync(const SwapCompletionCallback& callback) { | 140 bool GbmSurface::OnSwapBuffersAsync(const SwapCompletionCallback& callback) { |
138 DCHECK(native_surface_); | 141 DCHECK(native_surface_); |
139 | 142 |
140 gbm_bo* pending_buffer = gbm_surface_lock_front_buffer(native_surface_); | 143 gbm_bo* pending_buffer = gbm_surface_lock_front_buffer(native_surface_); |
141 scoped_refptr<GbmSurfaceBuffer> primary = | 144 scoped_refptr<GbmSurfaceBuffer> primary = |
142 GbmSurfaceBuffer::GetBuffer(pending_buffer); | 145 GbmSurfaceBuffer::GetBuffer(pending_buffer); |
143 if (!primary.get()) { | 146 if (!primary.get()) { |
144 primary = GbmSurfaceBuffer::CreateBuffer(gbm_, pending_buffer); | 147 primary = GbmSurfaceBuffer::CreateBuffer(gbm_, pending_buffer); |
145 if (!primary.get()) { | 148 if (!primary.get()) { |
146 LOG(ERROR) << "Failed to associate the buffer with the controller"; | 149 LOG(ERROR) << "Failed to associate the buffer with the controller"; |
147 callback.Run(); | 150 callback.Run(gfx::SwapFailed); |
148 return false; | 151 return false; |
149 } | 152 } |
150 } | 153 } |
151 | 154 |
152 // The primary buffer is a special case. | 155 // The primary buffer is a special case. |
153 window_delegate_->QueueOverlayPlane(OverlayPlane(primary)); | 156 window_delegate_->QueueOverlayPlane(OverlayPlane(primary)); |
154 | 157 |
155 if (!GbmSurfaceless::OnSwapBuffersAsync( | 158 if (!GbmSurfaceless::OnSwapBuffersAsync( |
156 base::Bind(&GbmSurface::OnSwapBuffersCallback, | 159 base::Bind(&GbmSurface::OnSwapBuffersCallback, |
157 weak_factory_.GetWeakPtr(), callback, pending_buffer))) { | 160 weak_factory_.GetWeakPtr(), callback, pending_buffer))) { |
158 callback.Run(); | 161 callback.Run(gfx::SwapFailed); |
159 return false; | 162 return false; |
160 } | 163 } |
161 | 164 |
162 return true; | 165 return true; |
163 } | 166 } |
164 | 167 |
165 void GbmSurface::OnSwapBuffersCallback(const SwapCompletionCallback& callback, | 168 void GbmSurface::OnSwapBuffersCallback(const SwapCompletionCallback& callback, |
166 gbm_bo* pending_buffer) { | 169 gbm_bo* pending_buffer, |
| 170 gfx::SwapResult result) { |
167 // If there was a frontbuffer, it is no longer active. Release it back to GBM. | 171 // If there was a frontbuffer, it is no longer active. Release it back to GBM. |
168 if (current_buffer_) | 172 if (current_buffer_) |
169 gbm_surface_release_buffer(native_surface_, current_buffer_); | 173 gbm_surface_release_buffer(native_surface_, current_buffer_); |
170 | 174 |
171 current_buffer_ = pending_buffer; | 175 current_buffer_ = pending_buffer; |
172 callback.Run(); | 176 callback.Run(result); |
173 } | 177 } |
174 | 178 |
175 } // namespace ui | 179 } // namespace ui |
OLD | NEW |