| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" | 5 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } // namespace | 134 } // namespace |
| 135 | 135 |
| 136 namespace vr_shell { | 136 namespace vr_shell { |
| 137 | 137 |
| 138 MailboxToSurfaceBridge::MailboxToSurfaceBridge() : weak_ptr_factory_(this) {} | 138 MailboxToSurfaceBridge::MailboxToSurfaceBridge() : weak_ptr_factory_(this) {} |
| 139 | 139 |
| 140 MailboxToSurfaceBridge::~MailboxToSurfaceBridge() { | 140 MailboxToSurfaceBridge::~MailboxToSurfaceBridge() { |
| 141 if (surface_handle_) { | 141 if (surface_handle_) { |
| 142 // Unregister from the surface tracker to avoid a resource leak. | 142 // Unregister from the surface tracker to avoid a resource leak. |
| 143 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); | 143 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); |
| 144 tracker->UnregisterViewSurface(surface_handle_); | 144 tracker->RemoveSurface(surface_handle_); |
| 145 } | 145 } |
| 146 DestroyContext(); | 146 DestroyContext(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void MailboxToSurfaceBridge::OnContextAvailable( | 149 void MailboxToSurfaceBridge::OnContextAvailable( |
| 150 scoped_refptr<cc::ContextProvider> provider) { | 150 scoped_refptr<cc::ContextProvider> provider) { |
| 151 // Must save a reference to the ContextProvider to keep it alive, | 151 // Must save a reference to the ContextProvider to keep it alive, |
| 152 // otherwise the GL context created from it becomes invalid. | 152 // otherwise the GL context created from it becomes invalid. |
| 153 context_provider_ = std::move(provider); | 153 context_provider_ = std::move(provider); |
| 154 | 154 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 165 } | 165 } |
| 166 InitializeRenderer(); | 166 InitializeRenderer(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void MailboxToSurfaceBridge::CreateSurface( | 169 void MailboxToSurfaceBridge::CreateSurface( |
| 170 gl::SurfaceTexture* surface_texture) { | 170 gl::SurfaceTexture* surface_texture) { |
| 171 ANativeWindow* window = surface_texture->CreateSurface(); | 171 ANativeWindow* window = surface_texture->CreateSurface(); |
| 172 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); | 172 gpu::GpuSurfaceTracker* tracker = gpu::GpuSurfaceTracker::Get(); |
| 173 ANativeWindow_acquire(window); | 173 ANativeWindow_acquire(window); |
| 174 // Skip ANativeWindow_setBuffersGeometry, the default size appears to work. | 174 // Skip ANativeWindow_setBuffersGeometry, the default size appears to work. |
| 175 surface_handle_ = tracker->AddSurfaceForNativeWidget(window); | |
| 176 | |
| 177 auto surface = base::MakeUnique<gl::ScopedJavaSurface>(surface_texture); | 175 auto surface = base::MakeUnique<gl::ScopedJavaSurface>(surface_texture); |
| 178 tracker->RegisterViewSurface(surface_handle_, surface->j_surface().obj()); | 176 surface_handle_ = |
| 177 tracker->AddSurfaceForNativeWidget(gpu::GpuSurfaceTracker::SurfaceRecord( |
| 178 window, surface->j_surface().obj())); |
| 179 // Unregistering happens in the destructor. | 179 // Unregistering happens in the destructor. |
| 180 ANativeWindow_release(window); | 180 ANativeWindow_release(window); |
| 181 | 181 |
| 182 // Our attributes must be compatible with the shared offscreen | 182 // Our attributes must be compatible with the shared offscreen |
| 183 // surface used by virtualized contexts, otherwise mailbox | 183 // surface used by virtualized contexts, otherwise mailbox |
| 184 // synchronization doesn't work properly - it assumes a shared | 184 // synchronization doesn't work properly - it assumes a shared |
| 185 // underlying GL context. See GetCompositorContextAttributes | 185 // underlying GL context. See GetCompositorContextAttributes |
| 186 // in content/browser/renderer_host/compositor_impl_android.cc | 186 // in content/browser/renderer_host/compositor_impl_android.cc |
| 187 // and crbug.com/699330. | 187 // and crbug.com/699330. |
| 188 | 188 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // GL_NEAREST. | 337 // GL_NEAREST. |
| 338 gl_->BindTexture(GL_TEXTURE_2D, texture_handle); | 338 gl_->BindTexture(GL_TEXTURE_2D, texture_handle); |
| 339 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 339 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 340 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 340 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 341 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 341 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 342 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 342 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 343 gl_->DrawArrays(GL_TRIANGLE_FAN, 0, 4); | 343 gl_->DrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 344 } | 344 } |
| 345 | 345 |
| 346 } // namespace vr_shell | 346 } // namespace vr_shell |
| OLD | NEW |