image_transport_surface_android.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "gpu/ipc/service/image_transport_surface.h"
  5. #include "base/feature_list.h"
  6. #include "base/logging.h"
  7. #include "base/threading/thread_task_runner_handle.h"
  8. #include "gpu/command_buffer/service/feature_info.h"
  9. #include "gpu/config/gpu_finch_features.h"
  10. #include "gpu/ipc/common/gpu_surface_lookup.h"
  11. #include "gpu/ipc/service/pass_through_image_transport_surface.h"
  12. #include "ui/gl/gl_surface_egl.h"
  13. #include "ui/gl/gl_surface_egl_surface_control.h"
  14. #include "ui/gl/gl_surface_stub.h"
  15. namespace gpu {
  16. // static
  17. scoped_refptr<gl::GLSurface> ImageTransportSurface::CreateNativeSurface(
  18. gl::GLDisplay* display,
  19. base::WeakPtr<ImageTransportSurfaceDelegate> delegate,
  20. SurfaceHandle surface_handle,
  21. gl::GLSurfaceFormat format) {
  22. if (gl::GetGLImplementation() == gl::kGLImplementationMockGL ||
  23. gl::GetGLImplementation() == gl::kGLImplementationStubGL)
  24. return new gl::GLSurfaceStub;
  25. DCHECK(GpuSurfaceLookup::GetInstance());
  26. DCHECK_NE(surface_handle, kNullSurfaceHandle);
  27. // On Android, the surface_handle is the id of the surface in the
  28. // GpuSurfaceTracker/GpuSurfaceLookup
  29. bool can_be_used_with_surface_control = false;
  30. ANativeWindow* window = GpuSurfaceLookup::GetInstance()->AcquireNativeWidget(
  31. surface_handle, &can_be_used_with_surface_control);
  32. if (!window) {
  33. LOG(WARNING) << "Failed to acquire native widget.";
  34. return nullptr;
  35. }
  36. scoped_refptr<gl::GLSurface> surface;
  37. if (delegate &&
  38. delegate->GetFeatureInfo()->feature_flags().android_surface_control &&
  39. can_be_used_with_surface_control) {
  40. surface = new gl::GLSurfaceEGLSurfaceControl(
  41. display->GetAs<gl::GLDisplayEGL>(), window,
  42. base::ThreadTaskRunnerHandle::Get());
  43. } else {
  44. surface = new gl::NativeViewGLSurfaceEGL(display->GetAs<gl::GLDisplayEGL>(),
  45. window, nullptr);
  46. }
  47. bool initialize_success = surface->Initialize(format);
  48. ANativeWindow_release(window);
  49. if (!initialize_success)
  50. return scoped_refptr<gl::GLSurface>();
  51. return scoped_refptr<gl::GLSurface>(
  52. new PassThroughImageTransportSurface(delegate, surface.get(), false));
  53. }
  54. } // namespace gpu