| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cast/surface_factory_cast.h" | 5 #include "ui/ozone/platform/cast/surface_factory_cast.h" |
| 6 | 6 |
| 7 #include <EGL/egl.h> |
| 7 #include <dlfcn.h> | 8 #include <dlfcn.h> |
| 8 #include <EGL/egl.h> | 9 |
| 9 #include <utility> | 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
| 13 #include "chromecast/public/cast_egl_platform.h" | 15 #include "chromecast/public/cast_egl_platform.h" |
| 14 #include "chromecast/public/graphics_types.h" | 16 #include "chromecast/public/graphics_types.h" |
| 15 #include "third_party/skia/include/core/SkSurface.h" | 17 #include "third_party/skia/include/core/SkSurface.h" |
| 16 #include "ui/gfx/geometry/quad_f.h" | 18 #include "ui/gfx/geometry/quad_f.h" |
| 17 #include "ui/gfx/vsync_provider.h" | 19 #include "ui/gfx/vsync_provider.h" |
| 18 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" | 20 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" |
| 19 #include "ui/ozone/public/native_pixmap.h" | 21 #include "ui/ozone/public/native_pixmap.h" |
| 20 #include "ui/ozone/public/surface_ozone_canvas.h" | 22 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 21 | 23 |
| 22 using chromecast::CastEglPlatform; | 24 using chromecast::CastEglPlatform; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 50 // SurfaceOzoneCanvas implementation: | 52 // SurfaceOzoneCanvas implementation: |
| 51 sk_sp<SkSurface> GetSurface() override { return surface_; } | 53 sk_sp<SkSurface> GetSurface() override { return surface_; } |
| 52 | 54 |
| 53 void ResizeCanvas(const gfx::Size& viewport_size) override { | 55 void ResizeCanvas(const gfx::Size& viewport_size) override { |
| 54 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( | 56 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( |
| 55 viewport_size.width(), viewport_size.height())); | 57 viewport_size.width(), viewport_size.height())); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void PresentCanvas(const gfx::Rect& damage) override {} | 60 void PresentCanvas(const gfx::Rect& damage) override {} |
| 59 | 61 |
| 60 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { | 62 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { |
| 61 return nullptr; | 63 return nullptr; |
| 62 } | 64 } |
| 63 | 65 |
| 64 private: | 66 private: |
| 65 sk_sp<SkSurface> surface_; | 67 sk_sp<SkSurface> surface_; |
| 66 | 68 |
| 67 DISALLOW_COPY_AND_ASSIGN(DummySurface); | 69 DISALLOW_COPY_AND_ASSIGN(DummySurface); |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 } // namespace | 72 } // namespace |
| 71 | 73 |
| 72 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {} | 74 SurfaceFactoryCast::SurfaceFactoryCast() : SurfaceFactoryCast(nullptr) {} |
| 73 | 75 |
| 74 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform) | 76 SurfaceFactoryCast::SurfaceFactoryCast( |
| 77 std::unique_ptr<CastEglPlatform> egl_platform) |
| 75 : state_(kUninitialized), | 78 : state_(kUninitialized), |
| 76 display_type_(0), | 79 display_type_(0), |
| 77 have_display_type_(false), | 80 have_display_type_(false), |
| 78 window_(0), | 81 window_(0), |
| 79 display_size_(GetInitialDisplaySize()), | 82 display_size_(GetInitialDisplaySize()), |
| 80 new_display_size_(GetInitialDisplaySize()), | 83 new_display_size_(GetInitialDisplaySize()), |
| 81 egl_platform_(std::move(egl_platform)), | 84 egl_platform_(std::move(egl_platform)), |
| 82 overlay_count_(0), | 85 overlay_count_(0), |
| 83 previous_frame_overlay_count_(0) {} | 86 previous_frame_overlay_count_(0) {} |
| 84 | 87 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 previous_frame_overlay_count_ = overlay_count_; | 151 previous_frame_overlay_count_ = overlay_count_; |
| 149 previous_frame_overlay_bounds_ = overlay_bounds_; | 152 previous_frame_overlay_bounds_ = overlay_bounds_; |
| 150 overlay_count_ = 0; | 153 overlay_count_ = 0; |
| 151 } | 154 } |
| 152 | 155 |
| 153 void SurfaceFactoryCast::OnOverlayScheduled(const gfx::Rect& display_bounds) { | 156 void SurfaceFactoryCast::OnOverlayScheduled(const gfx::Rect& display_bounds) { |
| 154 ++overlay_count_; | 157 ++overlay_count_; |
| 155 overlay_bounds_ = display_bounds; | 158 overlay_bounds_ = display_bounds; |
| 156 } | 159 } |
| 157 | 160 |
| 158 scoped_ptr<SurfaceOzoneCanvas> SurfaceFactoryCast::CreateCanvasForWidget( | 161 std::unique_ptr<SurfaceOzoneCanvas> SurfaceFactoryCast::CreateCanvasForWidget( |
| 159 gfx::AcceleratedWidget widget) { | 162 gfx::AcceleratedWidget widget) { |
| 160 // Software canvas support only in headless mode | 163 // Software canvas support only in headless mode |
| 161 if (egl_platform_) | 164 if (egl_platform_) |
| 162 return nullptr; | 165 return nullptr; |
| 163 return make_scoped_ptr<SurfaceOzoneCanvas>(new DummySurface()); | 166 return base::WrapUnique<SurfaceOzoneCanvas>(new DummySurface()); |
| 164 } | 167 } |
| 165 | 168 |
| 166 intptr_t SurfaceFactoryCast::GetNativeDisplay() { | 169 intptr_t SurfaceFactoryCast::GetNativeDisplay() { |
| 167 CreateDisplayTypeAndWindowIfNeeded(); | 170 CreateDisplayTypeAndWindowIfNeeded(); |
| 168 return reinterpret_cast<intptr_t>(display_type_); | 171 return reinterpret_cast<intptr_t>(display_type_); |
| 169 } | 172 } |
| 170 | 173 |
| 171 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { | 174 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { |
| 172 if (state_ == kUninitialized) { | 175 if (state_ == kUninitialized) { |
| 173 InitializeHardware(); | 176 InitializeHardware(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 221 |
| 219 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { | 222 void SurfaceFactoryCast::DestroyDisplayTypeAndWindow() { |
| 220 DestroyWindow(); | 223 DestroyWindow(); |
| 221 if (have_display_type_) { | 224 if (have_display_type_) { |
| 222 egl_platform_->DestroyDisplayType(display_type_); | 225 egl_platform_->DestroyDisplayType(display_type_); |
| 223 display_type_ = 0; | 226 display_type_ = 0; |
| 224 have_display_type_ = false; | 227 have_display_type_ = false; |
| 225 } | 228 } |
| 226 } | 229 } |
| 227 | 230 |
| 228 scoped_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( | 231 std::unique_ptr<SurfaceOzoneEGL> SurfaceFactoryCast::CreateEGLSurfaceForWidget( |
| 229 gfx::AcceleratedWidget widget) { | 232 gfx::AcceleratedWidget widget) { |
| 230 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); | 233 new_display_size_ = gfx::Size(widget >> 16, widget & 0xFFFF); |
| 231 new_display_size_.SetToMax(GetMinDisplaySize()); | 234 new_display_size_.SetToMax(GetMinDisplaySize()); |
| 232 return make_scoped_ptr<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); | 235 return base::WrapUnique<SurfaceOzoneEGL>(new SurfaceOzoneEglCast(this)); |
| 233 } | 236 } |
| 234 | 237 |
| 235 void SurfaceFactoryCast::ChildDestroyed() { | 238 void SurfaceFactoryCast::ChildDestroyed() { |
| 236 if (egl_platform_->MultipleSurfaceUnsupported()) | 239 if (egl_platform_->MultipleSurfaceUnsupported()) |
| 237 DestroyWindow(); | 240 DestroyWindow(); |
| 238 } | 241 } |
| 239 | 242 |
| 240 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap( | 243 scoped_refptr<NativePixmap> SurfaceFactoryCast::CreateNativePixmap( |
| 241 gfx::AcceleratedWidget widget, | 244 gfx::AcceleratedWidget widget, |
| 242 gfx::Size size, | 245 gfx::Size size, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return false; | 301 return false; |
| 299 } | 302 } |
| 300 | 303 |
| 301 set_gl_get_proc_address.Run(gl_proc); | 304 set_gl_get_proc_address.Run(gl_proc); |
| 302 add_gl_library.Run(lib_egl); | 305 add_gl_library.Run(lib_egl); |
| 303 add_gl_library.Run(lib_gles2); | 306 add_gl_library.Run(lib_gles2); |
| 304 return true; | 307 return true; |
| 305 } | 308 } |
| 306 | 309 |
| 307 } // namespace ui | 310 } // namespace ui |
| OLD | NEW |