| 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 "chromecast/ozone/surface_factory_cast.h" | 5 #include "chromecast/ozone/surface_factory_cast.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "chromecast/ozone/cast_egl_platform.h" | |
| 9 #include "chromecast/ozone/surface_ozone_egl_cast.h" | 8 #include "chromecast/ozone/surface_ozone_egl_cast.h" |
| 9 #include "chromecast/public/cast_egl_platform.h" |
| 10 | 10 |
| 11 namespace chromecast { | 11 namespace chromecast { |
| 12 namespace ozone { | 12 namespace ozone { |
| 13 namespace { |
| 14 CastEglPlatform::Size FromGfxSize(const gfx::Size& size) { |
| 15 return CastEglPlatform::Size(size.width(), size.height()); |
| 16 } |
| 17 gfx::Size ToGfxSize(const CastEglPlatform::Size& size) { |
| 18 return gfx::Size(size.width_, size.height_); |
| 19 } |
| 20 } |
| 13 | 21 |
| 14 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform) | 22 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform) |
| 15 : state_(kUninitialized), | 23 : state_(kUninitialized), |
| 16 destroy_window_pending_state_(kNoDestroyPending), | 24 destroy_window_pending_state_(kNoDestroyPending), |
| 17 display_type_(0), | 25 display_type_(0), |
| 18 window_(0), | 26 window_(0), |
| 19 default_display_size_(egl_platform->GetDefaultDisplaySize()), | 27 default_display_size_(ToGfxSize(egl_platform->GetDefaultDisplaySize())), |
| 20 display_size_(default_display_size_), | 28 display_size_(default_display_size_), |
| 21 new_display_size_(default_display_size_), | 29 new_display_size_(default_display_size_), |
| 22 egl_platform_(egl_platform.Pass()) { | 30 egl_platform_(egl_platform.Pass()) { |
| 23 } | 31 } |
| 24 | 32 |
| 25 SurfaceFactoryCast::~SurfaceFactoryCast() { | 33 SurfaceFactoryCast::~SurfaceFactoryCast() { |
| 26 DestroyDisplayTypeAndWindow(); | 34 DestroyDisplayTypeAndWindow(); |
| 27 } | 35 } |
| 28 | 36 |
| 29 void SurfaceFactoryCast::InitializeHardware() { | 37 void SurfaceFactoryCast::InitializeHardware() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 56 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { | 64 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { |
| 57 if (state_ == kUninitialized) { | 65 if (state_ == kUninitialized) { |
| 58 InitializeHardware(); | 66 InitializeHardware(); |
| 59 } | 67 } |
| 60 if (new_display_size_ != display_size_) { | 68 if (new_display_size_ != display_size_) { |
| 61 DestroyDisplayTypeAndWindow(); | 69 DestroyDisplayTypeAndWindow(); |
| 62 display_size_ = new_display_size_; | 70 display_size_ = new_display_size_; |
| 63 } | 71 } |
| 64 DCHECK_EQ(state_, kInitialized); | 72 DCHECK_EQ(state_, kInitialized); |
| 65 if (!display_type_) { | 73 if (!display_type_) { |
| 66 display_type_ = egl_platform_->CreateDisplayType(display_size_); | 74 CastEglPlatform::Size create_size = FromGfxSize(display_size_); |
| 75 display_type_ = egl_platform_->CreateDisplayType(create_size); |
| 67 if (display_type_) { | 76 if (display_type_) { |
| 68 window_ = egl_platform_->CreateWindow(display_type_, display_size_); | 77 window_ = egl_platform_->CreateWindow(display_type_, create_size); |
| 69 if (!window_) { | 78 if (!window_) { |
| 70 DestroyDisplayTypeAndWindow(); | 79 DestroyDisplayTypeAndWindow(); |
| 71 state_ = kFailed; | 80 state_ = kFailed; |
| 72 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() | 81 LOG(FATAL) << "Create EGLNativeWindowType(" << display_size_.ToString() |
| 73 << ") failed."; | 82 << ") failed."; |
| 74 } | 83 } |
| 75 } else { | 84 } else { |
| 76 state_ = kFailed; | 85 state_ = kFailed; |
| 77 LOG(FATAL) << "Create EGLNativeDisplayType(" << display_size_.ToString() | 86 LOG(FATAL) << "Create EGLNativeDisplayType(" << display_size_.ToString() |
| 78 << ") failed."; | 87 << ") failed."; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 bool SurfaceFactoryCast::LoadEGLGLES2Bindings( | 170 bool SurfaceFactoryCast::LoadEGLGLES2Bindings( |
| 162 AddGLLibraryCallback add_gl_library, | 171 AddGLLibraryCallback add_gl_library, |
| 163 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 172 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 164 if (state_ != kInitialized) { | 173 if (state_ != kInitialized) { |
| 165 InitializeHardware(); | 174 InitializeHardware(); |
| 166 if (state_ != kInitialized) { | 175 if (state_ != kInitialized) { |
| 167 return false; | 176 return false; |
| 168 } | 177 } |
| 169 } | 178 } |
| 170 | 179 |
| 171 return egl_platform_->LoadEGLGLES2Bindings(add_gl_library, | 180 void* lib_egl = egl_platform_->GetEglLibrary(); |
| 172 set_gl_get_proc_address); | 181 void* lib_gles2 = egl_platform_->GetGles2Library(); |
| 182 GLGetProcAddressProc gl_proc = egl_platform_->GetGLProcAddressProc(); |
| 183 if (!lib_egl || !lib_gles2 || !gl_proc) { |
| 184 return false; |
| 185 } |
| 186 |
| 187 set_gl_get_proc_address.Run(gl_proc); |
| 188 add_gl_library.Run(lib_egl); |
| 189 add_gl_library.Run(lib_gles2); |
| 190 return true; |
| 173 } | 191 } |
| 174 | 192 |
| 175 } // namespace ozone | 193 } // namespace ozone |
| 176 } // namespace chromecast | 194 } // namespace chromecast |
| OLD | NEW |