Chromium Code Reviews| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 scoped_ptr<VSyncProvider> vsync_provider = | 82 scoped_ptr<VSyncProvider> vsync_provider = |
| 83 ozone_surface_->CreateVSyncProvider(); | 83 ozone_surface_->CreateVSyncProvider(); |
| 84 if (!Initialize(vsync_provider.Pass())) { | 84 if (!Initialize(vsync_provider.Pass())) { |
| 85 LOG(ERROR) << "Failed to initialize."; | 85 LOG(ERROR) << "Failed to initialize."; |
| 86 return false; | 86 return false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 | |
| 93 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 92 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 94 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 93 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 95 AcceleratedWidget widget_; | 94 AcceleratedWidget widget_; |
| 96 | 95 |
| 97 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); | 96 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
| 98 }; | 97 }; |
| 99 | 98 |
| 99 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { | |
|
dnicoara
2014/08/26 00:13:21
I'm wondering if you should also override IsOffscr
achaulk
2014/08/26 00:35:58
Hmm, might be a good idea yeah
| |
| 100 public: | |
| 101 GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | |
| 102 AcceleratedWidget widget, | |
| 103 const gfx::Size& size) | |
| 104 : SurfacelessEGL(size), | |
| 105 ozone_surface_(ozone_surface.Pass()), | |
| 106 widget_(widget) {} | |
| 107 | |
| 108 virtual bool Resize(const gfx::Size& size) OVERRIDE { | |
| 109 if (!ozone_surface_->ResizeNativeWindow(size)) { | |
| 110 if (!ReinitializeNativeSurface() || | |
|
dnicoara
2014/08/26 00:13:21
This is mostly a hack for the surface case. On sur
achaulk
2014/08/26 00:35:58
Sounds good. It was working without all of this, I
| |
| 111 !ozone_surface_->ResizeNativeWindow(size)) | |
| 112 return false; | |
| 113 } | |
| 114 | |
| 115 return SurfacelessEGL::Resize(size); | |
| 116 } | |
| 117 virtual bool SwapBuffers() OVERRIDE { | |
| 118 return ozone_surface_->OnSwapBuffers(); | |
| 119 } | |
| 120 virtual bool ScheduleOverlayPlane(int z_order, | |
| 121 OverlayTransform transform, | |
| 122 GLImage* image, | |
| 123 const Rect& bounds_rect, | |
| 124 const RectF& crop_rect) OVERRIDE { | |
| 125 return image->ScheduleOverlayPlane( | |
| 126 widget_, z_order, transform, bounds_rect, crop_rect); | |
| 127 } | |
| 128 | |
| 129 private: | |
| 130 bool ReinitializeNativeSurface() { | |
| 131 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | |
| 132 GLContext* current_context = GLContext::GetCurrent(); | |
| 133 bool was_current = current_context && current_context->IsCurrent(this); | |
| 134 if (was_current) { | |
| 135 scoped_make_current.reset( | |
| 136 new ui::ScopedMakeCurrent(current_context, this)); | |
| 137 } | |
| 138 | |
| 139 Destroy(); | |
| 140 ozone_surface_ = ui::SurfaceFactoryOzone::GetInstance() | |
| 141 ->CreateSurfacelessEGLSurfaceForWidget(widget_) | |
| 142 .Pass(); | |
| 143 if (!ozone_surface_) { | |
| 144 LOG(ERROR) << "Failed to create native surface."; | |
| 145 return false; | |
| 146 } | |
| 147 | |
| 148 if (!Initialize()) { | |
| 149 LOG(ERROR) << "Failed to initialize."; | |
| 150 return false; | |
| 151 } | |
| 152 | |
| 153 return true; | |
| 154 } | |
| 155 | |
| 156 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | |
| 157 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | |
| 158 AcceleratedWidget widget_; | |
| 159 | |
| 160 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); | |
| 161 }; | |
| 162 | |
| 100 } // namespace | 163 } // namespace |
| 101 | 164 |
| 102 // static | 165 // static |
| 103 bool GLSurface::InitializeOneOffInternal() { | 166 bool GLSurface::InitializeOneOffInternal() { |
| 104 switch (GetGLImplementation()) { | 167 switch (GetGLImplementation()) { |
| 105 case kGLImplementationEGLGLES2: | 168 case kGLImplementationEGLGLES2: |
| 106 if (!GLSurfaceEGL::InitializeOneOff()) { | 169 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 107 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 170 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 108 return false; | 171 return false; |
| 109 } | 172 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 121 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 184 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 122 gfx::AcceleratedWidget window) { | 185 gfx::AcceleratedWidget window) { |
| 123 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 186 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 124 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 187 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 125 if (!surface->Initialize()) | 188 if (!surface->Initialize()) |
| 126 return NULL; | 189 return NULL; |
| 127 return surface; | 190 return surface; |
| 128 } | 191 } |
| 129 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 192 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 130 if (window != kNullAcceleratedWidget) { | 193 if (window != kNullAcceleratedWidget) { |
| 194 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | |
| 195 ui::SurfaceFactoryOzone::GetInstance() | |
| 196 ->CanShowPrimaryPlaneAsOverlay()) { | |
| 197 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | |
| 198 ui::SurfaceFactoryOzone::GetInstance() | |
| 199 ->CreateSurfacelessEGLSurfaceForWidget(window); | |
| 200 if (!surface_ozone) | |
| 201 return NULL; | |
| 202 scoped_refptr<GLSurfaceOzoneSurfaceless> surface = | |
| 203 new GLSurfaceOzoneSurfaceless( | |
| 204 surface_ozone.Pass(), window, gfx::Size()); | |
| 205 if (!surface->Initialize()) | |
| 206 return NULL; | |
| 207 return surface; | |
| 208 } | |
| 131 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 209 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 132 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( | 210 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( |
| 133 window); | 211 window); |
| 134 if (!surface_ozone) | 212 if (!surface_ozone) |
| 135 return NULL; | 213 return NULL; |
| 136 | 214 |
| 137 scoped_ptr<VSyncProvider> vsync_provider = | 215 scoped_ptr<VSyncProvider> vsync_provider = |
| 138 surface_ozone->CreateVSyncProvider(); | 216 surface_ozone->CreateVSyncProvider(); |
| 139 scoped_refptr<GLSurfaceOzoneEGL> surface = | 217 scoped_refptr<GLSurfaceOzoneEGL> surface = |
| 140 new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); | 218 new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 NOTREACHED(); | 255 NOTREACHED(); |
| 178 return NULL; | 256 return NULL; |
| 179 } | 257 } |
| 180 } | 258 } |
| 181 | 259 |
| 182 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 260 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 183 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 261 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 184 } | 262 } |
| 185 | 263 |
| 186 } // namespace gfx | 264 } // namespace gfx |
| OLD | NEW |