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/gl/gl_surface.h" | 5 #include "ui/gl/gl_surface.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
10 #include "ui/gl/gl_context.h" | 10 #include "ui/gl/gl_context.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow | 24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow |
25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
26 public: | 26 public: |
27 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 27 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
28 AcceleratedWidget widget) | 28 AcceleratedWidget widget) |
29 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), | 29 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
30 ozone_surface_(ozone_surface.Pass()), | 30 ozone_surface_(ozone_surface.Pass()), |
31 widget_(widget) {} | 31 widget_(widget) {} |
32 | 32 |
33 virtual bool Initialize() override { | 33 bool Initialize() override { |
34 return Initialize(ozone_surface_->CreateVSyncProvider()); | 34 return Initialize(ozone_surface_->CreateVSyncProvider()); |
35 } | 35 } |
36 virtual bool Resize(const gfx::Size& size) override { | 36 bool Resize(const gfx::Size& size) override { |
37 if (!ozone_surface_->ResizeNativeWindow(size)) { | 37 if (!ozone_surface_->ResizeNativeWindow(size)) { |
38 if (!ReinitializeNativeSurface() || | 38 if (!ReinitializeNativeSurface() || |
39 !ozone_surface_->ResizeNativeWindow(size)) | 39 !ozone_surface_->ResizeNativeWindow(size)) |
40 return false; | 40 return false; |
41 } | 41 } |
42 | 42 |
43 return NativeViewGLSurfaceEGL::Resize(size); | 43 return NativeViewGLSurfaceEGL::Resize(size); |
44 } | 44 } |
45 virtual bool SwapBuffers() override { | 45 bool SwapBuffers() override { |
46 if (!NativeViewGLSurfaceEGL::SwapBuffers()) | 46 if (!NativeViewGLSurfaceEGL::SwapBuffers()) |
47 return false; | 47 return false; |
48 | 48 |
49 return ozone_surface_->OnSwapBuffers(); | 49 return ozone_surface_->OnSwapBuffers(); |
50 } | 50 } |
51 virtual bool ScheduleOverlayPlane(int z_order, | 51 bool ScheduleOverlayPlane(int z_order, |
52 OverlayTransform transform, | 52 OverlayTransform transform, |
53 GLImage* image, | 53 GLImage* image, |
54 const Rect& bounds_rect, | 54 const Rect& bounds_rect, |
55 const RectF& crop_rect) override { | 55 const RectF& crop_rect) override { |
56 return image->ScheduleOverlayPlane( | 56 return image->ScheduleOverlayPlane( |
57 widget_, z_order, transform, bounds_rect, crop_rect); | 57 widget_, z_order, transform, bounds_rect, crop_rect); |
58 } | 58 } |
59 | 59 |
60 private: | 60 private: |
61 using NativeViewGLSurfaceEGL::Initialize; | 61 using NativeViewGLSurfaceEGL::Initialize; |
62 | 62 |
63 virtual ~GLSurfaceOzoneEGL() { | 63 ~GLSurfaceOzoneEGL() override { |
64 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 64 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
65 } | 65 } |
66 | 66 |
67 bool ReinitializeNativeSurface() { | 67 bool ReinitializeNativeSurface() { |
68 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 68 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
69 GLContext* current_context = GLContext::GetCurrent(); | 69 GLContext* current_context = GLContext::GetCurrent(); |
70 bool was_current = | 70 bool was_current = |
71 current_context && current_context->IsCurrent(this); | 71 current_context && current_context->IsCurrent(this); |
72 if (was_current) { | 72 if (was_current) { |
73 scoped_make_current.reset( | 73 scoped_make_current.reset( |
(...skipping 26 matching lines...) Expand all Loading... |
100 }; | 100 }; |
101 | 101 |
102 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { | 102 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { |
103 public: | 103 public: |
104 GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 104 GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
105 AcceleratedWidget widget) | 105 AcceleratedWidget widget) |
106 : SurfacelessEGL(gfx::Size()), | 106 : SurfacelessEGL(gfx::Size()), |
107 ozone_surface_(ozone_surface.Pass()), | 107 ozone_surface_(ozone_surface.Pass()), |
108 widget_(widget) {} | 108 widget_(widget) {} |
109 | 109 |
110 virtual bool Initialize() override { | 110 bool Initialize() override { |
111 if (!SurfacelessEGL::Initialize()) | 111 if (!SurfacelessEGL::Initialize()) |
112 return false; | 112 return false; |
113 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); | 113 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); |
114 if (!vsync_provider_) | 114 if (!vsync_provider_) |
115 return false; | 115 return false; |
116 return true; | 116 return true; |
117 } | 117 } |
118 virtual bool Resize(const gfx::Size& size) override { | 118 bool Resize(const gfx::Size& size) override { |
119 if (!ozone_surface_->ResizeNativeWindow(size)) | 119 if (!ozone_surface_->ResizeNativeWindow(size)) |
120 return false; | 120 return false; |
121 | 121 |
122 return SurfacelessEGL::Resize(size); | 122 return SurfacelessEGL::Resize(size); |
123 } | 123 } |
124 virtual bool SwapBuffers() override { | 124 bool SwapBuffers() override { |
125 // TODO: this should be replaced by a fence when supported by the driver. | 125 // TODO: this should be replaced by a fence when supported by the driver. |
126 glFlush(); | 126 glFlush(); |
127 return ozone_surface_->OnSwapBuffers(); | 127 return ozone_surface_->OnSwapBuffers(); |
128 } | 128 } |
129 virtual bool ScheduleOverlayPlane(int z_order, | 129 bool ScheduleOverlayPlane(int z_order, |
130 OverlayTransform transform, | 130 OverlayTransform transform, |
131 GLImage* image, | 131 GLImage* image, |
132 const Rect& bounds_rect, | 132 const Rect& bounds_rect, |
133 const RectF& crop_rect) override { | 133 const RectF& crop_rect) override { |
134 return image->ScheduleOverlayPlane( | 134 return image->ScheduleOverlayPlane( |
135 widget_, z_order, transform, bounds_rect, crop_rect); | 135 widget_, z_order, transform, bounds_rect, crop_rect); |
136 } | 136 } |
137 virtual bool IsOffscreen() override { return false; } | 137 bool IsOffscreen() override { return false; } |
138 virtual VSyncProvider* GetVSyncProvider() override { | 138 VSyncProvider* GetVSyncProvider() override { return vsync_provider_.get(); } |
139 return vsync_provider_.get(); | 139 bool SupportsPostSubBuffer() override { return true; } |
140 } | 140 bool PostSubBuffer(int x, int y, int width, int height) override { |
141 virtual bool SupportsPostSubBuffer() override { return true; } | |
142 virtual bool PostSubBuffer(int x, int y, int width, int height) override { | |
143 // The actual sub buffer handling is handled at higher layers. | 141 // The actual sub buffer handling is handled at higher layers. |
144 SwapBuffers(); | 142 SwapBuffers(); |
145 return true; | 143 return true; |
146 } | 144 } |
| 145 bool SwapBuffersAsync(const SwapCompletionCallback& callback) override { |
| 146 // TODO: this should be replaced by a fence when supported by the driver. |
| 147 glFlush(); |
| 148 return ozone_surface_->OnSwapBuffersAsync(callback); |
| 149 } |
| 150 bool PostSubBufferAsync(int x, |
| 151 int y, |
| 152 int width, |
| 153 int height, |
| 154 const SwapCompletionCallback& callback) override { |
| 155 return SwapBuffersAsync(callback); |
| 156 } |
147 | 157 |
148 private: | 158 private: |
149 virtual ~GLSurfaceOzoneSurfaceless() { | 159 ~GLSurfaceOzoneSurfaceless() override { |
150 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 160 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
151 } | 161 } |
152 | 162 |
153 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 163 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
154 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 164 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
155 AcceleratedWidget widget_; | 165 AcceleratedWidget widget_; |
156 scoped_ptr<VSyncProvider> vsync_provider_; | 166 scoped_ptr<VSyncProvider> vsync_provider_; |
157 | 167 |
158 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); | 168 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); |
159 }; | 169 }; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 NOTREACHED(); | 257 NOTREACHED(); |
248 return NULL; | 258 return NULL; |
249 } | 259 } |
250 } | 260 } |
251 | 261 |
252 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 262 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
253 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 263 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
254 } | 264 } |
255 | 265 |
256 } // namespace gfx | 266 } // namespace gfx |
OLD | NEW |