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/bind.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" |
9 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
10 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
11 #include "ui/gl/gl_image.h" | 13 #include "ui/gl/gl_image.h" |
12 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_surface_egl.h" | 15 #include "ui/gl/gl_surface_egl.h" |
14 #include "ui/gl/gl_surface_osmesa.h" | 16 #include "ui/gl/gl_surface_osmesa.h" |
15 #include "ui/gl/gl_surface_stub.h" | 17 #include "ui/gl/gl_surface_stub.h" |
16 #include "ui/gl/scoped_make_current.h" | 18 #include "ui/gl/scoped_make_current.h" |
17 #include "ui/ozone/public/surface_factory_ozone.h" | 19 #include "ui/ozone/public/surface_factory_ozone.h" |
18 #include "ui/ozone/public/surface_ozone_egl.h" | 20 #include "ui/ozone/public/surface_ozone_egl.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return true; | 94 return true; |
93 } | 95 } |
94 | 96 |
95 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 97 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
96 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 98 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
97 AcceleratedWidget widget_; | 99 AcceleratedWidget widget_; |
98 | 100 |
99 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); | 101 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
100 }; | 102 }; |
101 | 103 |
102 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { | 104 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL, |
| 105 public base::SupportsWeakPtr<GLSurfaceOzoneSurfaceless> { |
103 public: | 106 public: |
104 GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 107 GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
105 AcceleratedWidget widget) | 108 AcceleratedWidget widget) |
106 : SurfacelessEGL(gfx::Size()), | 109 : SurfacelessEGL(gfx::Size()), |
107 ozone_surface_(ozone_surface.Pass()), | 110 ozone_surface_(ozone_surface.Pass()), |
108 widget_(widget) {} | 111 widget_(widget) { |
| 112 ozone_surface_->SetPageFlipCompletionCallback( |
| 113 base::Bind(&GLSurfaceOzoneSurfaceless::PageFlipCompleted, |
| 114 this->AsWeakPtr())); |
| 115 } |
109 | 116 |
110 virtual bool Initialize() override { | 117 virtual bool Initialize() override { |
111 if (!SurfacelessEGL::Initialize()) | 118 if (!SurfacelessEGL::Initialize()) |
112 return false; | 119 return false; |
113 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); | 120 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); |
114 if (!vsync_provider_) | 121 if (!vsync_provider_) |
115 return false; | 122 return false; |
116 return true; | 123 return true; |
117 } | 124 } |
118 virtual bool Resize(const gfx::Size& size) override { | 125 virtual bool Resize(const gfx::Size& size) override { |
(...skipping 19 matching lines...) Expand all Loading... |
138 virtual VSyncProvider* GetVSyncProvider() override { | 145 virtual VSyncProvider* GetVSyncProvider() override { |
139 return vsync_provider_.get(); | 146 return vsync_provider_.get(); |
140 } | 147 } |
141 virtual bool SupportsPostSubBuffer() override { return true; } | 148 virtual bool SupportsPostSubBuffer() override { return true; } |
142 virtual bool PostSubBuffer(int x, int y, int width, int height) override { | 149 virtual bool PostSubBuffer(int x, int y, int width, int height) override { |
143 // The actual sub buffer handling is handled at higher layers. | 150 // The actual sub buffer handling is handled at higher layers. |
144 SwapBuffers(); | 151 SwapBuffers(); |
145 return true; | 152 return true; |
146 } | 153 } |
147 | 154 |
| 155 void SetPageFlipCompletionCallback( |
| 156 const PageFlipCompletionCallback& callback) override { |
| 157 page_flip_completion_callback_ = callback; |
| 158 } |
| 159 |
| 160 void PageFlipCompleted() { |
| 161 DCHECK(!page_flip_completion_callback_.is_null()); |
| 162 page_flip_completion_callback_.Run(); |
| 163 } |
| 164 |
148 private: | 165 private: |
149 virtual ~GLSurfaceOzoneSurfaceless() { | 166 virtual ~GLSurfaceOzoneSurfaceless() { |
150 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 167 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
151 } | 168 } |
152 | 169 |
153 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 170 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
154 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 171 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
155 AcceleratedWidget widget_; | 172 AcceleratedWidget widget_; |
156 scoped_ptr<VSyncProvider> vsync_provider_; | 173 scoped_ptr<VSyncProvider> vsync_provider_; |
| 174 PageFlipCompletionCallback page_flip_completion_callback_; |
157 | 175 |
158 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); | 176 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); |
159 }; | 177 }; |
160 | 178 |
161 } // namespace | 179 } // namespace |
162 | 180 |
163 // static | 181 // static |
164 bool GLSurface::InitializeOneOffInternal() { | 182 bool GLSurface::InitializeOneOffInternal() { |
165 switch (GetGLImplementation()) { | 183 switch (GetGLImplementation()) { |
166 case kGLImplementationEGLGLES2: | 184 case kGLImplementationEGLGLES2: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 NOTREACHED(); | 265 NOTREACHED(); |
248 return NULL; | 266 return NULL; |
249 } | 267 } |
250 } | 268 } |
251 | 269 |
252 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 270 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
253 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 271 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
254 } | 272 } |
255 | 273 |
256 } // namespace gfx | 274 } // namespace gfx |
OLD | NEW |