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