| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_surfaceless.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 GbmSurfaceless::GbmSurfaceless(GbmSurfaceFactory* surface_factory, | 31 GbmSurfaceless::GbmSurfaceless(GbmSurfaceFactory* surface_factory, |
| 32 std::unique_ptr<DrmWindowProxy> window, | 32 std::unique_ptr<DrmWindowProxy> window, |
| 33 gfx::AcceleratedWidget widget) | 33 gfx::AcceleratedWidget widget) |
| 34 : SurfacelessEGL(gfx::Size()), | 34 : SurfacelessEGL(gfx::Size()), |
| 35 surface_factory_(surface_factory), | 35 surface_factory_(surface_factory), |
| 36 window_(std::move(window)), | 36 window_(std::move(window)), |
| 37 widget_(widget), | 37 widget_(widget), |
| 38 has_implicit_external_sync_( | 38 has_implicit_external_sync_( |
| 39 HasEGLExtension("EGL_ARM_implicit_external_sync")), | 39 HasEGLExtension("EGL_ARM_implicit_external_sync")), |
| 40 has_image_flush_external_( |
| 41 HasEGLExtension("EGL_EXT_image_flush_external")), |
| 40 weak_factory_(this) { | 42 weak_factory_(this) { |
| 41 surface_factory_->RegisterSurface(window_->widget(), this); | 43 surface_factory_->RegisterSurface(window_->widget(), this); |
| 42 unsubmitted_frames_.push_back(base::MakeUnique<PendingFrame>()); | 44 unsubmitted_frames_.push_back(base::MakeUnique<PendingFrame>()); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void GbmSurfaceless::QueueOverlayPlane(const OverlayPlane& plane) { | 47 void GbmSurfaceless::QueueOverlayPlane(const OverlayPlane& plane) { |
| 46 planes_.push_back(plane); | 48 planes_.push_back(plane); |
| 47 } | 49 } |
| 48 | 50 |
| 49 bool GbmSurfaceless::Initialize(gl::GLSurfaceFormat format) { | 51 bool GbmSurfaceless::Initialize(gl::GLSurfaceFormat format) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 98 } |
| 97 | 99 |
| 98 void GbmSurfaceless::SwapBuffersAsync(const SwapCompletionCallback& callback) { | 100 void GbmSurfaceless::SwapBuffersAsync(const SwapCompletionCallback& callback) { |
| 99 TRACE_EVENT0("drm", "GbmSurfaceless::SwapBuffersAsync"); | 101 TRACE_EVENT0("drm", "GbmSurfaceless::SwapBuffersAsync"); |
| 100 // If last swap failed, don't try to schedule new ones. | 102 // If last swap failed, don't try to schedule new ones. |
| 101 if (!last_swap_buffers_result_) { | 103 if (!last_swap_buffers_result_) { |
| 102 callback.Run(gfx::SwapResult::SWAP_FAILED); | 104 callback.Run(gfx::SwapResult::SWAP_FAILED); |
| 103 return; | 105 return; |
| 104 } | 106 } |
| 105 | 107 |
| 108 glFlush(); |
| 106 unsubmitted_frames_.back()->Flush(); | 109 unsubmitted_frames_.back()->Flush(); |
| 107 | 110 |
| 108 SwapCompletionCallback surface_swap_callback = base::Bind( | 111 SwapCompletionCallback surface_swap_callback = base::Bind( |
| 109 &GbmSurfaceless::SwapCompleted, weak_factory_.GetWeakPtr(), callback); | 112 &GbmSurfaceless::SwapCompleted, weak_factory_.GetWeakPtr(), callback); |
| 110 | 113 |
| 111 PendingFrame* frame = unsubmitted_frames_.back().get(); | 114 PendingFrame* frame = unsubmitted_frames_.back().get(); |
| 112 frame->callback = surface_swap_callback; | 115 frame->callback = surface_swap_callback; |
| 113 unsubmitted_frames_.push_back(base::MakeUnique<PendingFrame>()); | 116 unsubmitted_frames_.push_back(base::MakeUnique<PendingFrame>()); |
| 114 | 117 |
| 115 // TODO: the following should be replaced by a per surface flush as it gets | 118 // TODO: the following should be replaced by a per surface flush as it gets |
| 116 // implemented in GL drivers. | 119 // implemented in GL drivers. |
| 117 EGLSyncKHR fence = InsertFence(has_implicit_external_sync_); | 120 if (has_implicit_external_sync_ || has_image_flush_external_) { |
| 118 if (!fence) { | 121 EGLSyncKHR fence = InsertFence(has_implicit_external_sync_); |
| 119 callback.Run(gfx::SwapResult::SWAP_FAILED); | 122 if (!fence) { |
| 120 return; | 123 callback.Run(gfx::SwapResult::SWAP_FAILED); |
| 124 return; |
| 125 } |
| 126 |
| 127 base::Closure fence_wait_task = |
| 128 base::Bind(&WaitForFence, GetDisplay(), fence); |
| 129 |
| 130 base::Closure fence_retired_callback = |
| 131 base::Bind(&GbmSurfaceless::FenceRetired, weak_factory_.GetWeakPtr(), |
| 132 fence, frame); |
| 133 |
| 134 base::PostTaskWithTraitsAndReply( |
| 135 FROM_HERE, base::TaskTraits() |
| 136 .WithShutdownBehavior( |
| 137 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 138 .MayBlock(), |
| 139 fence_wait_task, fence_retired_callback); |
| 140 return; // Defer frame submission until fence signals. |
| 121 } | 141 } |
| 122 | 142 |
| 123 base::Closure fence_wait_task = | 143 frame->ready = true; |
| 124 base::Bind(&WaitForFence, GetDisplay(), fence); | 144 SubmitFrame(); |
| 125 | |
| 126 base::Closure fence_retired_callback = base::Bind( | |
| 127 &GbmSurfaceless::FenceRetired, weak_factory_.GetWeakPtr(), fence, frame); | |
| 128 | |
| 129 base::PostTaskWithTraitsAndReply( | |
| 130 FROM_HERE, | |
| 131 base::TaskTraits() | |
| 132 .WithShutdownBehavior( | |
| 133 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | |
| 134 .MayBlock(), | |
| 135 fence_wait_task, fence_retired_callback); | |
| 136 } | 145 } |
| 137 | 146 |
| 138 void GbmSurfaceless::PostSubBufferAsync( | 147 void GbmSurfaceless::PostSubBufferAsync( |
| 139 int x, | 148 int x, |
| 140 int y, | 149 int y, |
| 141 int width, | 150 int width, |
| 142 int height, | 151 int height, |
| 143 const SwapCompletionCallback& callback) { | 152 const SwapCompletionCallback& callback) { |
| 144 // The actual sub buffer handling is handled at higher layers. | 153 // The actual sub buffer handling is handled at higher layers. |
| 145 SwapBuffersAsync(callback); | 154 SwapBuffersAsync(callback); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 unsubmitted_frames_.erase(unsubmitted_frames_.begin()); | 206 unsubmitted_frames_.erase(unsubmitted_frames_.begin()); |
| 198 swap_buffers_pending_ = true; | 207 swap_buffers_pending_ = true; |
| 199 | 208 |
| 200 if (!frame->ScheduleOverlayPlanes(widget_)) { | 209 if (!frame->ScheduleOverlayPlanes(widget_)) { |
| 201 // |callback| is a wrapper for SwapCompleted(). Call it to properly | 210 // |callback| is a wrapper for SwapCompleted(). Call it to properly |
| 202 // propagate the failed state. | 211 // propagate the failed state. |
| 203 frame->callback.Run(gfx::SwapResult::SWAP_FAILED); | 212 frame->callback.Run(gfx::SwapResult::SWAP_FAILED); |
| 204 return; | 213 return; |
| 205 } | 214 } |
| 206 | 215 |
| 216 if (IsUniversalDisplayLinkDevice()) |
| 217 glFinish(); |
| 218 |
| 207 window_->SchedulePageFlip(planes_, frame->callback); | 219 window_->SchedulePageFlip(planes_, frame->callback); |
| 208 planes_.clear(); | 220 planes_.clear(); |
| 209 } | 221 } |
| 210 } | 222 } |
| 211 | 223 |
| 212 EGLSyncKHR GbmSurfaceless::InsertFence(bool implicit) { | 224 EGLSyncKHR GbmSurfaceless::InsertFence(bool implicit) { |
| 213 const EGLint attrib_list[] = {EGL_SYNC_CONDITION_KHR, | 225 const EGLint attrib_list[] = {EGL_SYNC_CONDITION_KHR, |
| 214 EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM, | 226 EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM, |
| 215 EGL_NONE}; | 227 EGL_NONE}; |
| 216 return eglCreateSyncKHR(GetDisplay(), EGL_SYNC_FENCE_KHR, | 228 return eglCreateSyncKHR(GetDisplay(), EGL_SYNC_FENCE_KHR, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 228 callback.Run(result); | 240 callback.Run(result); |
| 229 swap_buffers_pending_ = false; | 241 swap_buffers_pending_ = false; |
| 230 if (result == gfx::SwapResult::SWAP_FAILED) { | 242 if (result == gfx::SwapResult::SWAP_FAILED) { |
| 231 last_swap_buffers_result_ = false; | 243 last_swap_buffers_result_ = false; |
| 232 return; | 244 return; |
| 233 } | 245 } |
| 234 | 246 |
| 235 SubmitFrame(); | 247 SubmitFrame(); |
| 236 } | 248 } |
| 237 | 249 |
| 250 bool GbmSurfaceless::IsUniversalDisplayLinkDevice() { |
| 251 return planes_.empty() ? false : planes_[0].buffer->RequiresGlFinish(); |
| 252 } |
| 253 |
| 238 } // namespace ui | 254 } // namespace ui |
| OLD | NEW |