[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/gl/gl_surface.h" |
| 6 | |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 7 | #include "base/bind.h" |
alexst | 165be97 | 2015-03-11 15:37:09 | [diff] [blame] | 8 | #include "base/callback.h" |
| 9 | #include "base/location.h" |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 10 | #include "base/logging.h" |
| 11 | #include "base/memory/ref_counted.h" |
achaulk | 77f08ab | 2015-04-07 16:22:34 | [diff] [blame] | 12 | #include "base/memory/scoped_vector.h" |
alexst | 165be97 | 2015-03-11 15:37:09 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
| 14 | #include "base/threading/worker_pool.h" |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 15 | #include "ui/gfx/native_widget_types.h" |
[email protected] | aab13e2f | 2014-07-29 03:01:45 | [diff] [blame] | 16 | #include "ui/gl/gl_context.h" |
[email protected] | f46c2bd | 2014-08-16 07:47:09 | [diff] [blame] | 17 | #include "ui/gl/gl_image.h" |
dongseong.hwang | 161c7a2 | 2015-07-29 18:28:17 | [diff] [blame] | 18 | #include "ui/gl/gl_image_ozone_native_pixmap.h" |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 19 | #include "ui/gl/gl_implementation.h" |
| 20 | #include "ui/gl/gl_surface_egl.h" |
| 21 | #include "ui/gl/gl_surface_osmesa.h" |
| 22 | #include "ui/gl/gl_surface_stub.h" |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 23 | #include "ui/gl/scoped_binders.h" |
[email protected] | aab13e2f | 2014-07-29 03:01:45 | [diff] [blame] | 24 | #include "ui/gl/scoped_make_current.h" |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 25 | #include "ui/ozone/public/native_pixmap.h" |
dongseong.hwang | 9162b5fa | 2015-06-05 16:52:30 | [diff] [blame] | 26 | #include "ui/ozone/public/ozone_platform.h" |
[email protected] | 0e37fc20 | 2014-06-20 13:24:02 | [diff] [blame] | 27 | #include "ui/ozone/public/surface_factory_ozone.h" |
| 28 | #include "ui/ozone/public/surface_ozone_egl.h" |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 29 | |
tfarina | df856e02 | 2015-10-29 12:50:45 | [diff] [blame] | 30 | using gl::GLImage; |
| 31 | |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 32 | namespace gfx { |
| 33 | |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 34 | namespace { |
| 35 | |
alexst | 165be97 | 2015-03-11 15:37:09 | [diff] [blame] | 36 | void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { |
| 37 | eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, |
| 38 | EGL_FOREVER_KHR); |
| 39 | } |
| 40 | |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 41 | // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow. |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 42 | class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 43 | public: |
[email protected] | aab13e2f | 2014-07-29 03:01:45 | [diff] [blame] | 44 | GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 45 | AcceleratedWidget widget); |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 46 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 47 | // GLSurface: |
| 48 | bool Initialize() override; |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 49 | bool Resize(const gfx::Size& size, float scale_factor) override; |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 50 | gfx::SwapResult SwapBuffers() override; |
alexst | fa14b671 | 2015-01-05 19:29:48 | [diff] [blame] | 51 | bool ScheduleOverlayPlane(int z_order, |
| 52 | OverlayTransform transform, |
| 53 | GLImage* image, |
| 54 | const Rect& bounds_rect, |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 55 | const RectF& crop_rect) override; |
[email protected] | 5780da09 | 2014-04-08 12:04:41 | [diff] [blame] | 56 | |
[email protected] | b8211e3 | 2014-04-01 22:58:45 | [diff] [blame] | 57 | private: |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 58 | using NativeViewGLSurfaceEGL::Initialize; |
| 59 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 60 | ~GLSurfaceOzoneEGL() override; |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 61 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 62 | bool ReinitializeNativeSurface(); |
[email protected] | aab13e2f | 2014-07-29 03:01:45 | [diff] [blame] | 63 | |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 64 | // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
[email protected] | 0e37fc20 | 2014-06-20 13:24:02 | [diff] [blame] | 65 | scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
[email protected] | aab13e2f | 2014-07-29 03:01:45 | [diff] [blame] | 66 | AcceleratedWidget widget_; |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
| 69 | }; |
| 70 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 71 | GLSurfaceOzoneEGL::GLSurfaceOzoneEGL( |
| 72 | scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 73 | AcceleratedWidget widget) |
| 74 | : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
| 75 | ozone_surface_(ozone_surface.Pass()), |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 76 | widget_(widget) {} |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 77 | |
| 78 | bool GLSurfaceOzoneEGL::Initialize() { |
| 79 | return Initialize(ozone_surface_->CreateVSyncProvider()); |
| 80 | } |
| 81 | |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 82 | bool GLSurfaceOzoneEGL::Resize(const gfx::Size& size, float scale_factor) { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 83 | if (!ozone_surface_->ResizeNativeWindow(size)) { |
| 84 | if (!ReinitializeNativeSurface() || |
| 85 | !ozone_surface_->ResizeNativeWindow(size)) |
| 86 | return false; |
| 87 | } |
| 88 | |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 89 | return NativeViewGLSurfaceEGL::Resize(size, scale_factor); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 90 | } |
| 91 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 92 | gfx::SwapResult GLSurfaceOzoneEGL::SwapBuffers() { |
| 93 | gfx::SwapResult result = NativeViewGLSurfaceEGL::SwapBuffers(); |
| 94 | if (result != gfx::SwapResult::SWAP_ACK) |
| 95 | return result; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 96 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 97 | return ozone_surface_->OnSwapBuffers() ? gfx::SwapResult::SWAP_ACK |
| 98 | : gfx::SwapResult::SWAP_FAILED; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | bool GLSurfaceOzoneEGL::ScheduleOverlayPlane(int z_order, |
| 102 | OverlayTransform transform, |
| 103 | GLImage* image, |
| 104 | const Rect& bounds_rect, |
| 105 | const RectF& crop_rect) { |
| 106 | return image->ScheduleOverlayPlane(widget_, z_order, transform, bounds_rect, |
| 107 | crop_rect); |
| 108 | } |
| 109 | |
| 110 | GLSurfaceOzoneEGL::~GLSurfaceOzoneEGL() { |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 111 | Destroy(); // The EGL surface must be destroyed before SurfaceOzone. |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | bool GLSurfaceOzoneEGL::ReinitializeNativeSurface() { |
| 115 | scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
| 116 | GLContext* current_context = GLContext::GetCurrent(); |
| 117 | bool was_current = current_context && current_context->IsCurrent(this); |
| 118 | if (was_current) { |
| 119 | scoped_make_current.reset(new ui::ScopedMakeCurrent(current_context, this)); |
| 120 | } |
| 121 | |
| 122 | Destroy(); |
dongseong.hwang | 9162b5fa | 2015-06-05 16:52:30 | [diff] [blame] | 123 | ozone_surface_ = ui::OzonePlatform::GetInstance() |
| 124 | ->GetSurfaceFactoryOzone() |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 125 | ->CreateEGLSurfaceForWidget(widget_); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 126 | if (!ozone_surface_) { |
| 127 | LOG(ERROR) << "Failed to create native surface."; |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | window_ = ozone_surface_->GetNativeWindow(); |
| 132 | if (!Initialize()) { |
| 133 | LOG(ERROR) << "Failed to initialize."; |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | return true; |
| 138 | } |
| 139 | |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 140 | class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { |
| 141 | public: |
| 142 | GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 143 | AcceleratedWidget widget); |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 144 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 145 | // GLSurface: |
| 146 | bool Initialize() override; |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 147 | bool Resize(const gfx::Size& size, float scale_factor) override; |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 148 | gfx::SwapResult SwapBuffers() override; |
alexst | fa14b671 | 2015-01-05 19:29:48 | [diff] [blame] | 149 | bool ScheduleOverlayPlane(int z_order, |
| 150 | OverlayTransform transform, |
| 151 | GLImage* image, |
| 152 | const Rect& bounds_rect, |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 153 | const RectF& crop_rect) override; |
| 154 | bool IsOffscreen() override; |
| 155 | VSyncProvider* GetVSyncProvider() override; |
| 156 | bool SupportsPostSubBuffer() override; |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 157 | gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 158 | bool SwapBuffersAsync(const SwapCompletionCallback& callback) override; |
alexst | 409e3e0 | 2015-01-05 22:20:24 | [diff] [blame] | 159 | bool PostSubBufferAsync(int x, |
| 160 | int y, |
| 161 | int width, |
| 162 | int height, |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 163 | const SwapCompletionCallback& callback) override; |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 164 | |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 165 | protected: |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 166 | struct Overlay { |
| 167 | Overlay(int z_order, |
| 168 | OverlayTransform transform, |
| 169 | GLImage* image, |
| 170 | const Rect& bounds_rect, |
| 171 | const RectF& crop_rect); |
| 172 | |
| 173 | bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget) const; |
| 174 | |
| 175 | int z_order; |
| 176 | OverlayTransform transform; |
| 177 | scoped_refptr<GLImage> image; |
| 178 | Rect bounds_rect; |
| 179 | RectF crop_rect; |
| 180 | }; |
| 181 | |
achaulk | 77f08ab | 2015-04-07 16:22:34 | [diff] [blame] | 182 | struct PendingFrame { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 183 | PendingFrame(); |
achaulk | 77f08ab | 2015-04-07 16:22:34 | [diff] [blame] | 184 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 185 | bool ScheduleOverlayPlanes(gfx::AcceleratedWidget widget); |
achaulk | 77f08ab | 2015-04-07 16:22:34 | [diff] [blame] | 186 | |
achaulk | 77f08ab | 2015-04-07 16:22:34 | [diff] [blame] | 187 | bool ready; |
| 188 | std::vector<Overlay> overlays; |
| 189 | SwapCompletionCallback callback; |
| 190 | }; |
| 191 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 192 | ~GLSurfaceOzoneSurfaceless() override; |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 193 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 194 | void SubmitFrame(); |
alexst | 9c97321 | 2015-04-24 14:28:45 | [diff] [blame] | 195 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 196 | EGLSyncKHR InsertFence(); |
| 197 | void FenceRetired(EGLSyncKHR fence, PendingFrame* frame); |
alexst | 9c97321 | 2015-04-24 14:28:45 | [diff] [blame] | 198 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 199 | void SwapCompleted(const SwapCompletionCallback& callback, |
| 200 | gfx::SwapResult result); |
dbehr | 5addbd5 | 2015-02-07 03:18:05 | [diff] [blame] | 201 | |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 202 | // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 203 | scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 204 | AcceleratedWidget widget_; |
| 205 | scoped_ptr<VSyncProvider> vsync_provider_; |
achaulk | 77f08ab | 2015-04-07 16:22:34 | [diff] [blame] | 206 | ScopedVector<PendingFrame> unsubmitted_frames_; |
dbehr | 5addbd5 | 2015-02-07 03:18:05 | [diff] [blame] | 207 | bool has_implicit_external_sync_; |
alexst | 165be97 | 2015-03-11 15:37:09 | [diff] [blame] | 208 | bool last_swap_buffers_result_; |
alexst | 9c97321 | 2015-04-24 14:28:45 | [diff] [blame] | 209 | bool swap_buffers_pending_; |
alexst | 165be97 | 2015-03-11 15:37:09 | [diff] [blame] | 210 | |
| 211 | base::WeakPtrFactory<GLSurfaceOzoneSurfaceless> weak_factory_; |
| 212 | |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 213 | DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); |
| 214 | }; |
| 215 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 216 | GLSurfaceOzoneSurfaceless::Overlay::Overlay(int z_order, |
| 217 | OverlayTransform transform, |
| 218 | GLImage* image, |
| 219 | const Rect& bounds_rect, |
| 220 | const RectF& crop_rect) |
| 221 | : z_order(z_order), |
| 222 | transform(transform), |
| 223 | image(image), |
| 224 | bounds_rect(bounds_rect), |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 225 | crop_rect(crop_rect) {} |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 226 | |
| 227 | bool GLSurfaceOzoneSurfaceless::Overlay::ScheduleOverlayPlane( |
| 228 | gfx::AcceleratedWidget widget) const { |
| 229 | return image->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
| 230 | crop_rect); |
| 231 | } |
| 232 | |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 233 | GLSurfaceOzoneSurfaceless::PendingFrame::PendingFrame() : ready(false) {} |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 234 | |
| 235 | bool GLSurfaceOzoneSurfaceless::PendingFrame::ScheduleOverlayPlanes( |
| 236 | gfx::AcceleratedWidget widget) { |
| 237 | for (const auto& overlay : overlays) |
| 238 | if (!overlay.ScheduleOverlayPlane(widget)) |
| 239 | return false; |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | GLSurfaceOzoneSurfaceless::GLSurfaceOzoneSurfaceless( |
| 244 | scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 245 | AcceleratedWidget widget) |
| 246 | : SurfacelessEGL(gfx::Size()), |
| 247 | ozone_surface_(ozone_surface.Pass()), |
| 248 | widget_(widget), |
| 249 | has_implicit_external_sync_( |
| 250 | HasEGLExtension("EGL_ARM_implicit_external_sync")), |
| 251 | last_swap_buffers_result_(true), |
| 252 | swap_buffers_pending_(false), |
| 253 | weak_factory_(this) { |
| 254 | unsubmitted_frames_.push_back(new PendingFrame()); |
| 255 | } |
| 256 | |
| 257 | bool GLSurfaceOzoneSurfaceless::Initialize() { |
| 258 | if (!SurfacelessEGL::Initialize()) |
| 259 | return false; |
| 260 | vsync_provider_ = ozone_surface_->CreateVSyncProvider(); |
| 261 | if (!vsync_provider_) |
| 262 | return false; |
| 263 | return true; |
| 264 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 265 | |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 266 | bool GLSurfaceOzoneSurfaceless::Resize(const gfx::Size& size, |
| 267 | float scale_factor) { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 268 | if (!ozone_surface_->ResizeNativeWindow(size)) |
| 269 | return false; |
| 270 | |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 271 | return SurfacelessEGL::Resize(size, scale_factor); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 272 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 273 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 274 | gfx::SwapResult GLSurfaceOzoneSurfaceless::SwapBuffers() { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 275 | glFlush(); |
| 276 | // TODO: the following should be replaced by a per surface flush as it gets |
| 277 | // implemented in GL drivers. |
| 278 | if (has_implicit_external_sync_) { |
| 279 | EGLSyncKHR fence = InsertFence(); |
| 280 | if (!fence) |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 281 | return SwapResult::SWAP_FAILED; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 282 | |
| 283 | EGLDisplay display = GetDisplay(); |
| 284 | WaitForFence(display, fence); |
| 285 | eglDestroySyncKHR(display, fence); |
| 286 | } else if (ozone_surface_->IsUniversalDisplayLinkDevice()) { |
| 287 | glFinish(); |
| 288 | } |
| 289 | |
| 290 | unsubmitted_frames_.back()->ScheduleOverlayPlanes(widget_); |
| 291 | unsubmitted_frames_.back()->overlays.clear(); |
| 292 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 293 | return ozone_surface_->OnSwapBuffers() ? gfx::SwapResult::SWAP_ACK |
| 294 | : gfx::SwapResult::SWAP_FAILED; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 295 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 296 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 297 | bool GLSurfaceOzoneSurfaceless::ScheduleOverlayPlane(int z_order, |
| 298 | OverlayTransform transform, |
| 299 | GLImage* image, |
| 300 | const Rect& bounds_rect, |
| 301 | const RectF& crop_rect) { |
| 302 | unsubmitted_frames_.back()->overlays.push_back( |
| 303 | Overlay(z_order, transform, image, bounds_rect, crop_rect)); |
| 304 | return true; |
| 305 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 306 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 307 | bool GLSurfaceOzoneSurfaceless::IsOffscreen() { |
| 308 | return false; |
| 309 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 310 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 311 | VSyncProvider* GLSurfaceOzoneSurfaceless::GetVSyncProvider() { |
| 312 | return vsync_provider_.get(); |
| 313 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 314 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 315 | bool GLSurfaceOzoneSurfaceless::SupportsPostSubBuffer() { |
| 316 | return true; |
| 317 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 318 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 319 | gfx::SwapResult GLSurfaceOzoneSurfaceless::PostSubBuffer(int x, |
| 320 | int y, |
| 321 | int width, |
| 322 | int height) { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 323 | // The actual sub buffer handling is handled at higher layers. |
| 324 | SwapBuffers(); |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 325 | return gfx::SwapResult::SWAP_ACK; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 326 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 327 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 328 | bool GLSurfaceOzoneSurfaceless::SwapBuffersAsync( |
| 329 | const SwapCompletionCallback& callback) { |
| 330 | // If last swap failed, don't try to schedule new ones. |
| 331 | if (!last_swap_buffers_result_) |
| 332 | return false; |
| 333 | |
| 334 | glFlush(); |
| 335 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 336 | SwapCompletionCallback surface_swap_callback = |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 337 | base::Bind(&GLSurfaceOzoneSurfaceless::SwapCompleted, |
| 338 | weak_factory_.GetWeakPtr(), callback); |
| 339 | |
| 340 | PendingFrame* frame = unsubmitted_frames_.back(); |
| 341 | frame->callback = surface_swap_callback; |
| 342 | unsubmitted_frames_.push_back(new PendingFrame()); |
| 343 | |
| 344 | // TODO: the following should be replaced by a per surface flush as it gets |
| 345 | // implemented in GL drivers. |
| 346 | if (has_implicit_external_sync_) { |
| 347 | EGLSyncKHR fence = InsertFence(); |
| 348 | if (!fence) |
| 349 | return false; |
| 350 | |
| 351 | base::Closure fence_wait_task = |
| 352 | base::Bind(&WaitForFence, GetDisplay(), fence); |
| 353 | |
| 354 | base::Closure fence_retired_callback = |
| 355 | base::Bind(&GLSurfaceOzoneSurfaceless::FenceRetired, |
| 356 | weak_factory_.GetWeakPtr(), fence, frame); |
| 357 | |
| 358 | base::WorkerPool::PostTaskAndReply(FROM_HERE, fence_wait_task, |
| 359 | fence_retired_callback, false); |
| 360 | return true; |
| 361 | } else if (ozone_surface_->IsUniversalDisplayLinkDevice()) { |
| 362 | glFinish(); |
| 363 | } |
| 364 | |
| 365 | frame->ready = true; |
| 366 | SubmitFrame(); |
| 367 | return last_swap_buffers_result_; |
| 368 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 369 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 370 | bool GLSurfaceOzoneSurfaceless::PostSubBufferAsync( |
| 371 | int x, |
| 372 | int y, |
| 373 | int width, |
| 374 | int height, |
| 375 | const SwapCompletionCallback& callback) { |
| 376 | return SwapBuffersAsync(callback); |
| 377 | } |
| 378 | |
| 379 | GLSurfaceOzoneSurfaceless::~GLSurfaceOzoneSurfaceless() { |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 380 | Destroy(); // The EGL surface must be destroyed before SurfaceOzone. |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void GLSurfaceOzoneSurfaceless::SubmitFrame() { |
| 384 | DCHECK(!unsubmitted_frames_.empty()); |
| 385 | |
| 386 | if (unsubmitted_frames_.front()->ready && !swap_buffers_pending_) { |
| 387 | scoped_ptr<PendingFrame> frame(unsubmitted_frames_.front()); |
| 388 | unsubmitted_frames_.weak_erase(unsubmitted_frames_.begin()); |
| 389 | swap_buffers_pending_ = true; |
| 390 | |
dnicoara | 02681f4 | 2015-11-12 15:34:38 | [diff] [blame] | 391 | if (!frame->ScheduleOverlayPlanes(widget_)) { |
| 392 | // |callback| is a wrapper for SwapCompleted(). Call it to properly |
| 393 | // propagate the failed state. |
| 394 | frame->callback.Run(gfx::SwapResult::SWAP_FAILED); |
| 395 | return; |
| 396 | } |
| 397 | |
| 398 | ozone_surface_->OnSwapBuffersAsync(frame->callback); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | EGLSyncKHR GLSurfaceOzoneSurfaceless::InsertFence() { |
| 403 | const EGLint attrib_list[] = {EGL_SYNC_CONDITION_KHR, |
| 404 | EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM, |
| 405 | EGL_NONE}; |
| 406 | return eglCreateSyncKHR(GetDisplay(), EGL_SYNC_FENCE_KHR, attrib_list); |
| 407 | } |
| 408 | |
| 409 | void GLSurfaceOzoneSurfaceless::FenceRetired(EGLSyncKHR fence, |
| 410 | PendingFrame* frame) { |
| 411 | eglDestroySyncKHR(GetDisplay(), fence); |
| 412 | frame->ready = true; |
| 413 | SubmitFrame(); |
| 414 | } |
| 415 | |
| 416 | void GLSurfaceOzoneSurfaceless::SwapCompleted( |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 417 | const SwapCompletionCallback& callback, |
| 418 | gfx::SwapResult result) { |
| 419 | callback.Run(result); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 420 | swap_buffers_pending_ = false; |
dnicoara | 02681f4 | 2015-11-12 15:34:38 | [diff] [blame] | 421 | if (result == gfx::SwapResult::SWAP_FAILED) { |
| 422 | last_swap_buffers_result_ = false; |
| 423 | return; |
| 424 | } |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 425 | |
| 426 | SubmitFrame(); |
| 427 | } |
| 428 | |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 429 | // This provides surface-like semantics implemented through surfaceless. |
| 430 | // A framebuffer is bound automatically. |
| 431 | class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl |
| 432 | : public GLSurfaceOzoneSurfaceless { |
| 433 | public: |
| 434 | GLSurfaceOzoneSurfacelessSurfaceImpl( |
| 435 | scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 436 | AcceleratedWidget widget); |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 437 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 438 | // GLSurface: |
| 439 | unsigned int GetBackingFrameBufferObject() override; |
| 440 | bool OnMakeCurrent(GLContext* context) override; |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 441 | bool Resize(const gfx::Size& size, float scale_factor) override; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 442 | bool SupportsPostSubBuffer() override; |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 443 | gfx::SwapResult SwapBuffers() override; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 444 | bool SwapBuffersAsync(const SwapCompletionCallback& callback) override; |
| 445 | void Destroy() override; |
spang | b55571ca | 2015-09-16 22:09:35 | [diff] [blame] | 446 | bool IsSurfaceless() const override; |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 447 | |
| 448 | private: |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 449 | ~GLSurfaceOzoneSurfacelessSurfaceImpl() override; |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 450 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 451 | void BindFramebuffer(); |
| 452 | bool CreatePixmaps(); |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 453 | |
achaulk | 8d645d29 | 2015-08-04 14:09:27 | [diff] [blame] | 454 | scoped_refptr<GLContext> context_; |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 455 | GLuint fbo_; |
| 456 | GLuint textures_[2]; |
| 457 | scoped_refptr<GLImage> images_[2]; |
| 458 | int current_surface_; |
| 459 | DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); |
| 460 | }; |
| 461 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 462 | GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( |
| 463 | scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 464 | AcceleratedWidget widget) |
| 465 | : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget), |
achaulk | 8d645d29 | 2015-08-04 14:09:27 | [diff] [blame] | 466 | context_(nullptr), |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 467 | fbo_(0), |
| 468 | current_surface_(0) { |
| 469 | for (auto& texture : textures_) |
| 470 | texture = 0; |
| 471 | } |
| 472 | |
| 473 | unsigned int |
| 474 | GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { |
| 475 | return fbo_; |
| 476 | } |
| 477 | |
| 478 | bool GLSurfaceOzoneSurfacelessSurfaceImpl::OnMakeCurrent(GLContext* context) { |
achaulk | 8d645d29 | 2015-08-04 14:09:27 | [diff] [blame] | 479 | DCHECK(!context_ || context == context_); |
| 480 | context_ = context; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 481 | if (!fbo_) { |
| 482 | glGenFramebuffersEXT(1, &fbo_); |
| 483 | if (!fbo_) |
| 484 | return false; |
| 485 | glGenTextures(arraysize(textures_), textures_); |
| 486 | if (!CreatePixmaps()) |
| 487 | return false; |
| 488 | } |
| 489 | BindFramebuffer(); |
| 490 | glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); |
| 491 | return SurfacelessEGL::OnMakeCurrent(context); |
| 492 | } |
| 493 | |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 494 | bool GLSurfaceOzoneSurfacelessSurfaceImpl::Resize(const gfx::Size& size, |
| 495 | float scale_factor) { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 496 | if (size == GetSize()) |
| 497 | return true; |
jbauman | ce45e11 | 2015-10-30 02:33:57 | [diff] [blame] | 498 | return GLSurfaceOzoneSurfaceless::Resize(size, scale_factor) && |
| 499 | CreatePixmaps(); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | bool GLSurfaceOzoneSurfacelessSurfaceImpl::SupportsPostSubBuffer() { |
| 503 | return false; |
| 504 | } |
| 505 | |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 506 | gfx::SwapResult GLSurfaceOzoneSurfacelessSurfaceImpl::SwapBuffers() { |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 507 | if (!images_[current_surface_]->ScheduleOverlayPlane( |
| 508 | widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, |
| 509 | gfx::Rect(GetSize()), gfx::RectF(1, 1))) |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 510 | return gfx::SwapResult::SWAP_FAILED; |
| 511 | gfx::SwapResult result = GLSurfaceOzoneSurfaceless::SwapBuffers(); |
| 512 | if (result != gfx::SwapResult::SWAP_ACK) |
| 513 | return result; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 514 | current_surface_ ^= 1; |
| 515 | BindFramebuffer(); |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 516 | return gfx::SwapResult::SWAP_ACK; |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | bool GLSurfaceOzoneSurfacelessSurfaceImpl::SwapBuffersAsync( |
| 520 | const SwapCompletionCallback& callback) { |
| 521 | if (!images_[current_surface_]->ScheduleOverlayPlane( |
| 522 | widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, |
| 523 | gfx::Rect(GetSize()), gfx::RectF(1, 1))) |
| 524 | return false; |
| 525 | if (!GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback)) |
| 526 | return false; |
| 527 | current_surface_ ^= 1; |
| 528 | BindFramebuffer(); |
| 529 | return true; |
| 530 | } |
| 531 | |
| 532 | void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { |
achaulk | 8d645d29 | 2015-08-04 14:09:27 | [diff] [blame] | 533 | if (!context_) |
| 534 | return; |
wuchengli | 20824f95 | 2015-10-22 05:05:27 | [diff] [blame] | 535 | scoped_refptr<gfx::GLContext> previous_context = gfx::GLContext::GetCurrent(); |
| 536 | scoped_refptr<gfx::GLSurface> previous_surface = gfx::GLSurface::GetCurrent(); |
| 537 | context_->MakeCurrent(this); |
| 538 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 539 | glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 540 | if (fbo_) { |
| 541 | glDeleteTextures(arraysize(textures_), textures_); |
| 542 | for (auto& texture : textures_) |
| 543 | texture = 0; |
| 544 | glDeleteFramebuffersEXT(1, &fbo_); |
| 545 | fbo_ = 0; |
| 546 | } |
| 547 | for (auto image : images_) { |
| 548 | if (image) |
| 549 | image->Destroy(true); |
| 550 | } |
wuchengli | 20824f95 | 2015-10-22 05:05:27 | [diff] [blame] | 551 | |
| 552 | if (previous_context.get()) { |
| 553 | previous_context->MakeCurrent(previous_surface.get()); |
| 554 | } else { |
| 555 | context_->ReleaseCurrent(this); |
| 556 | } |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 557 | } |
| 558 | |
spang | b55571ca | 2015-09-16 22:09:35 | [diff] [blame] | 559 | bool GLSurfaceOzoneSurfacelessSurfaceImpl::IsSurfaceless() const { |
| 560 | return false; |
| 561 | } |
| 562 | |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 563 | GLSurfaceOzoneSurfacelessSurfaceImpl::~GLSurfaceOzoneSurfacelessSurfaceImpl() { |
wuchengli | 20824f95 | 2015-10-22 05:05:27 | [diff] [blame] | 564 | Destroy(); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | void GLSurfaceOzoneSurfacelessSurfaceImpl::BindFramebuffer() { |
| 568 | ScopedFrameBufferBinder fb(fbo_); |
| 569 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 570 | textures_[current_surface_], 0); |
| 571 | } |
| 572 | |
| 573 | bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { |
| 574 | if (!fbo_) |
| 575 | return true; |
| 576 | for (size_t i = 0; i < arraysize(textures_); i++) { |
| 577 | scoped_refptr<ui::NativePixmap> pixmap = |
dongseong.hwang | 9162b5fa | 2015-06-05 16:52:30 | [diff] [blame] | 578 | ui::OzonePlatform::GetInstance() |
| 579 | ->GetSurfaceFactoryOzone() |
| 580 | ->CreateNativePixmap(widget_, GetSize(), |
spang | fcf5fab4 | 2015-08-04 19:25:35 | [diff] [blame] | 581 | gfx::BufferFormat::BGRA_8888, |
reveman | 1108e0b7 | 2015-10-30 17:05:44 | [diff] [blame] | 582 | gfx::BufferUsage::SCANOUT); |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 583 | if (!pixmap) |
| 584 | return false; |
dongseong.hwang | 161c7a2 | 2015-07-29 18:28:17 | [diff] [blame] | 585 | scoped_refptr<GLImageOzoneNativePixmap> image = |
| 586 | new GLImageOzoneNativePixmap(GetSize(), GL_BGRA_EXT); |
reveman | 0bb50d7 | 2015-11-16 18:04:52 | [diff] [blame^] | 587 | if (!image->Initialize(pixmap.get(), gfx::BufferFormat::BGRA_8888)) |
alexst | e3e4605 | 2015-05-04 19:40:56 | [diff] [blame] | 588 | return false; |
| 589 | images_[i] = image; |
| 590 | // Bind image to texture. |
| 591 | ScopedTextureBinder binder(GL_TEXTURE_2D, textures_[i]); |
| 592 | if (!images_[i]->BindTexImage(GL_TEXTURE_2D)) |
| 593 | return false; |
| 594 | } |
| 595 | return true; |
| 596 | } |
| 597 | |
spang | e82006b | 2015-09-16 18:07:29 | [diff] [blame] | 598 | scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( |
| 599 | gfx::AcceleratedWidget window) { |
| 600 | scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 601 | ui::OzonePlatform::GetInstance() |
| 602 | ->GetSurfaceFactoryOzone() |
| 603 | ->CreateEGLSurfaceForWidget(window); |
| 604 | if (!surface_ozone) |
| 605 | return nullptr; |
| 606 | scoped_refptr<GLSurface> surface = |
| 607 | new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); |
| 608 | if (!surface->Initialize()) |
| 609 | return nullptr; |
| 610 | return surface; |
| 611 | } |
| 612 | |
| 613 | scoped_refptr<GLSurface> CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl( |
| 614 | gfx::AcceleratedWidget window) { |
| 615 | scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 616 | ui::OzonePlatform::GetInstance() |
| 617 | ->GetSurfaceFactoryOzone() |
| 618 | ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 619 | if (!surface_ozone) |
| 620 | return nullptr; |
| 621 | scoped_refptr<GLSurface> surface = |
| 622 | new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(), window); |
| 623 | if (!surface->Initialize()) |
| 624 | return nullptr; |
| 625 | return surface; |
| 626 | } |
| 627 | |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 628 | } // namespace |
| 629 | |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 630 | // static |
| 631 | bool GLSurface::InitializeOneOffInternal() { |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 632 | switch (GetGLImplementation()) { |
| 633 | case kGLImplementationEGLGLES2: |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 634 | if (!GLSurfaceEGL::InitializeOneOff()) { |
| 635 | LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 636 | return false; |
| 637 | } |
[email protected] | 1fe75057 | 2014-03-29 01:22:34 | [diff] [blame] | 638 | |
| 639 | return true; |
| 640 | case kGLImplementationOSMesaGL: |
| 641 | case kGLImplementationMockGL: |
| 642 | return true; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 643 | default: |
[email protected] | 1fe75057 | 2014-03-29 01:22:34 | [diff] [blame] | 644 | return false; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 645 | } |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | // static |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 649 | scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( |
| 650 | gfx::AcceleratedWidget window) { |
| 651 | if (GetGLImplementation() == kGLImplementationEGLGLES2 && |
| 652 | window != kNullAcceleratedWidget && |
spang | e82006b | 2015-09-16 18:07:29 | [diff] [blame] | 653 | GLSurfaceEGL::IsEGLSurfacelessContextSupported()) { |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 654 | scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
dongseong.hwang | 9162b5fa | 2015-06-05 16:52:30 | [diff] [blame] | 655 | ui::OzonePlatform::GetInstance() |
| 656 | ->GetSurfaceFactoryOzone() |
achaulk | e86e411c | 2015-03-02 22:45:36 | [diff] [blame] | 657 | ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 658 | if (!surface_ozone) |
| 659 | return nullptr; |
| 660 | scoped_refptr<GLSurface> surface; |
| 661 | surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); |
| 662 | if (surface->Initialize()) |
| 663 | return surface; |
| 664 | } |
| 665 | |
| 666 | return nullptr; |
| 667 | } |
| 668 | |
| 669 | // static |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 670 | scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 671 | gfx::AcceleratedWidget window) { |
| 672 | if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 673 | scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 674 | if (!surface->Initialize()) |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 675 | return nullptr; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 676 | return surface; |
| 677 | } |
| 678 | DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 679 | if (window != kNullAcceleratedWidget) { |
achaulk | e79d5d85 | 2014-08-27 00:16:42 | [diff] [blame] | 680 | scoped_refptr<GLSurface> surface; |
spang | e82006b | 2015-09-16 18:07:29 | [diff] [blame] | 681 | if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) |
| 682 | surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); |
| 683 | if (!surface) |
| 684 | surface = CreateViewGLSurfaceOzone(window); |
[email protected] | 502371d | 2014-03-31 17:16:42 | [diff] [blame] | 685 | return surface; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 686 | } else { |
| 687 | scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| 688 | if (surface->Initialize()) |
| 689 | return surface; |
| 690 | } |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 691 | return nullptr; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | // static |
| 695 | scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| 696 | const gfx::Size& size) { |
| 697 | switch (GetGLImplementation()) { |
| 698 | case kGLImplementationOSMesaGL: { |
[email protected] | dab8662 | 2014-08-16 14:34:59 | [diff] [blame] | 699 | scoped_refptr<GLSurface> surface( |
| 700 | new GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, size)); |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 701 | if (!surface->Initialize()) |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 702 | return nullptr; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 703 | |
| 704 | return surface; |
| 705 | } |
| 706 | case kGLImplementationEGLGLES2: { |
| 707 | scoped_refptr<GLSurface> surface; |
| 708 | if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| 709 | (size.width() == 0 && size.height() == 0)) { |
| 710 | surface = new SurfacelessEGL(size); |
| 711 | } else |
| 712 | surface = new PbufferGLSurfaceEGL(size); |
| 713 | |
| 714 | if (!surface->Initialize()) |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 715 | return nullptr; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 716 | return surface; |
| 717 | } |
zmo | eecacfe | 2015-05-07 05:42:53 | [diff] [blame] | 718 | case kGLImplementationMockGL: |
| 719 | return new GLSurfaceStub; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 720 | default: |
| 721 | NOTREACHED(); |
spang | 0ac9fc3 | 2015-09-16 23:11:03 | [diff] [blame] | 722 | return nullptr; |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
| 726 | EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
dongseong.hwang | 9162b5fa | 2015-06-05 16:52:30 | [diff] [blame] | 727 | return ui::OzonePlatform::GetInstance() |
| 728 | ->GetSurfaceFactoryOzone() |
| 729 | ->GetNativeDisplay(); |
[email protected] | ffcdc963 | 2014-03-27 17:25:23 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | } // namespace gfx |