| 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_factory.h" | 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
| 6 | 6 |
| 7 #include <gbm.h> | 7 #include <gbm.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "third_party/khronos/EGL/egl.h" | 11 #include "third_party/khronos/EGL/egl.h" |
| 11 #include "ui/ozone/platform/dri/gbm_buffer.h" | 12 #include "ui/ozone/platform/dri/gbm_buffer.h" |
| 12 #include "ui/ozone/platform/dri/gbm_surface.h" | 13 #include "ui/ozone/platform/dri/gbm_surface.h" |
| 13 #include "ui/ozone/platform/dri/gbm_surfaceless.h" | 14 #include "ui/ozone/platform/dri/gbm_surfaceless.h" |
| 14 #include "ui/ozone/platform/dri/screen_manager.h" | 15 #include "ui/ozone/platform/dri/screen_manager.h" |
| 15 #include "ui/ozone/public/native_pixmap.h" | 16 #include "ui/ozone/public/native_pixmap.h" |
| 17 #include "ui/ozone/public/overlay_candidates_ozone.h" |
| 18 #include "ui/ozone/public/ozone_switches.h" |
| 16 #include "ui/ozone/public/surface_ozone_egl.h" | 19 #include "ui/ozone/public/surface_ozone_egl.h" |
| 17 | 20 |
| 18 namespace ui { | 21 namespace ui { |
| 22 namespace { |
| 23 |
| 24 class SingleOverlay : public OverlayCandidatesOzone { |
| 25 public: |
| 26 SingleOverlay() {} |
| 27 virtual ~SingleOverlay() {} |
| 28 |
| 29 virtual void CheckOverlaySupport(OverlaySurfaceCandidateList* candidates) { |
| 30 if (candidates->size() == 2) { |
| 31 OverlayCandidatesOzone::OverlaySurfaceCandidate* first = |
| 32 &(*candidates)[0]; |
| 33 OverlayCandidatesOzone::OverlaySurfaceCandidate* second = |
| 34 &(*candidates)[1]; |
| 35 OverlayCandidatesOzone::OverlaySurfaceCandidate* overlay; |
| 36 if (first->plane_z_order == 0) { |
| 37 overlay = second; |
| 38 } else if (second->plane_z_order == 0) { |
| 39 overlay = first; |
| 40 } else { |
| 41 NOTREACHED(); |
| 42 return; |
| 43 } |
| 44 if (overlay->plane_z_order > 0 && |
| 45 IsTransformSupported(overlay->transform)) { |
| 46 overlay->overlay_handled = true; |
| 47 } |
| 48 } |
| 49 } |
| 50 |
| 51 private: |
| 52 bool IsTransformSupported(gfx::OverlayTransform transform) { |
| 53 switch (transform) { |
| 54 case gfx::OVERLAY_TRANSFORM_NONE: |
| 55 return true; |
| 56 default: |
| 57 return false; |
| 58 } |
| 59 } |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); |
| 62 }; |
| 63 |
| 64 } // namespace |
| 19 | 65 |
| 20 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 66 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
| 21 : DriSurfaceFactory(NULL, NULL), | 67 : DriSurfaceFactory(NULL, NULL), |
| 22 device_(NULL), | 68 device_(NULL), |
| 23 allow_surfaceless_(allow_surfaceless) { | 69 allow_surfaceless_(allow_surfaceless) { |
| 24 } | 70 } |
| 25 | 71 |
| 26 GbmSurfaceFactory::~GbmSurfaceFactory() {} | 72 GbmSurfaceFactory::~GbmSurfaceFactory() {} |
| 27 | 73 |
| 28 void GbmSurfaceFactory::InitializeGpu( | 74 void GbmSurfaceFactory::InitializeGpu( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 gfx::Size size, | 164 gfx::Size size, |
| 119 BufferFormat format) { | 165 BufferFormat format) { |
| 120 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( | 166 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( |
| 121 drm_, device_, format, size, true); | 167 drm_, device_, format, size, true); |
| 122 if (!buffer) | 168 if (!buffer) |
| 123 return NULL; | 169 return NULL; |
| 124 | 170 |
| 125 return scoped_refptr<GbmPixmap>(new GbmPixmap(buffer)); | 171 return scoped_refptr<GbmPixmap>(new GbmPixmap(buffer)); |
| 126 } | 172 } |
| 127 | 173 |
| 174 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( |
| 175 gfx::AcceleratedWidget w) { |
| 176 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 177 switches::kOzoneTestSingleOverlaySupport)) |
| 178 return new SingleOverlay(); |
| 179 return NULL; |
| 180 } |
| 181 |
| 128 bool GbmSurfaceFactory::ScheduleOverlayPlane( | 182 bool GbmSurfaceFactory::ScheduleOverlayPlane( |
| 129 gfx::AcceleratedWidget widget, | 183 gfx::AcceleratedWidget widget, |
| 130 int plane_z_order, | 184 int plane_z_order, |
| 131 gfx::OverlayTransform plane_transform, | 185 gfx::OverlayTransform plane_transform, |
| 132 scoped_refptr<NativePixmap> buffer, | 186 scoped_refptr<NativePixmap> buffer, |
| 133 const gfx::Rect& display_bounds, | 187 const gfx::Rect& display_bounds, |
| 134 const gfx::RectF& crop_rect) { | 188 const gfx::RectF& crop_rect) { |
| 135 scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get()); | 189 scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get()); |
| 136 if (!pixmap) { | 190 if (!pixmap) { |
| 137 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer."; | 191 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer."; |
| 138 return false; | 192 return false; |
| 139 } | 193 } |
| 140 base::WeakPtr<HardwareDisplayController> hdc = | 194 base::WeakPtr<HardwareDisplayController> hdc = |
| 141 screen_manager_->GetDisplayController(widget); | 195 screen_manager_->GetDisplayController(widget); |
| 142 if (!hdc) | 196 if (!hdc) |
| 143 return true; | 197 return true; |
| 144 hdc->QueueOverlayPlane(OverlayPlane(pixmap->buffer(), | 198 hdc->QueueOverlayPlane(OverlayPlane(pixmap->buffer(), |
| 145 plane_z_order, | 199 plane_z_order, |
| 146 plane_transform, | 200 plane_transform, |
| 147 display_bounds, | 201 display_bounds, |
| 148 crop_rect)); | 202 crop_rect)); |
| 149 return true; | 203 return true; |
| 150 } | 204 } |
| 151 | 205 |
| 152 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { | 206 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { |
| 153 return allow_surfaceless_; | 207 return allow_surfaceless_; |
| 154 } | 208 } |
| 155 | 209 |
| 156 } // namespace ui | 210 } // namespace ui |
| OLD | NEW |