| 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(int) { |
| 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 if (window_delegate_->GetController()) | 156 if (window_delegate_->GetController()) |
| 154 window_delegate_->GetController()->QueueOverlayPlane(OverlayPlane(primary)); | 157 window_delegate_->GetController()->QueueOverlayPlane(OverlayPlane(primary)); |
| 155 | 158 |
| 156 if (!GbmSurfaceless::OnSwapBuffersAsync( | 159 if (!GbmSurfaceless::OnSwapBuffersAsync( |
| 157 base::Bind(&GbmSurface::OnSwapBuffersCallback, | 160 base::Bind(&GbmSurface::OnSwapBuffersCallback, |
| 158 weak_factory_.GetWeakPtr(), callback, pending_buffer))) { | 161 weak_factory_.GetWeakPtr(), callback, pending_buffer))) { |
| 159 callback.Run(); | 162 callback.Run(gfx::SwapFailed); |
| 160 return false; | 163 return false; |
| 161 } | 164 } |
| 162 | 165 |
| 163 return true; | 166 return true; |
| 164 } | 167 } |
| 165 | 168 |
| 166 void GbmSurface::OnSwapBuffersCallback(const SwapCompletionCallback& callback, | 169 void GbmSurface::OnSwapBuffersCallback(const SwapCompletionCallback& callback, |
| 167 gbm_bo* pending_buffer) { | 170 gbm_bo* pending_buffer, |
| 171 int result) { |
| 168 // If there was a frontbuffer, it is no longer active. Release it back to GBM. | 172 // If there was a frontbuffer, it is no longer active. Release it back to GBM. |
| 169 if (current_buffer_) | 173 if (current_buffer_) |
| 170 gbm_surface_release_buffer(native_surface_, current_buffer_); | 174 gbm_surface_release_buffer(native_surface_, current_buffer_); |
| 171 | 175 |
| 172 current_buffer_ = pending_buffer; | 176 current_buffer_ = pending_buffer; |
| 173 callback.Run(); | 177 callback.Run(result); |
| 174 } | 178 } |
| 175 | 179 |
| 176 } // namespace ui | 180 } // namespace ui |
| OLD | NEW |