| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ | 5 #ifndef GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ |
| 6 #define GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ | 6 #define GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "gpu/gpu_export.h" | 15 #include "gpu/gpu_export.h" |
| 16 #include "gpu/ipc/common/gpu_surface_lookup.h" | 16 #include "gpu/ipc/common/gpu_surface_lookup.h" |
| 17 #include "gpu/ipc/common/surface_handle.h" | 17 #include "gpu/ipc/common/surface_handle.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 19 | 19 |
| 20 namespace gpu { | 20 namespace gpu { |
| 21 | 21 |
| 22 // This class is used on Android and Mac, and is responsible for tracking native | 22 // This class is used on Android and Mac, and is responsible for tracking native |
| 23 // window surfaces exposed to the GPU process. Every surface gets registered to | 23 // window surfaces exposed to the GPU process. Every surface gets registered to |
| 24 // this class, and gets a handle. The handle can be passed to | 24 // this class, and gets a handle. The handle can be passed to |
| 25 // CommandBufferProxyImpl::Create or to | 25 // CommandBufferProxyImpl::Create or to |
| 26 // GpuMemoryBufferManager::CreateGpuMemoryBuffer. | 26 // GpuMemoryBufferManager::CreateGpuMemoryBuffer. |
| 27 // On Android, the handle is used in the GPU process to get a reference to the | 27 // On Android, the handle is used in the GPU process to get a reference to the |
| 28 // ANativeWindow, using GpuSurfaceLookup (implemented by | 28 // ANativeWindow, using GpuSurfaceLookup (implemented by |
| 29 // ChildProcessSurfaceManager). | 29 // ChildProcessSurfaceManager). We require that an Android Surface is provided |
| 30 // with the ANativeWindow, so one must provide an explicit GpuSurfaceTracker:: |
| 31 // SurfaceRecord when adding it. |
| 30 // On Mac, the handle just passes through the GPU process, and is sent back via | 32 // On Mac, the handle just passes through the GPU process, and is sent back via |
| 31 // GpuCommandBufferMsg_SwapBuffersCompleted to reference the surface. | 33 // GpuCommandBufferMsg_SwapBuffersCompleted to reference the surface. |
| 32 // This class is thread safe. | 34 // This class is thread safe. |
| 33 class GPU_EXPORT GpuSurfaceTracker : public gpu::GpuSurfaceLookup { | 35 class GPU_EXPORT GpuSurfaceTracker : public gpu::GpuSurfaceLookup { |
| 34 public: | 36 public: |
| 37 struct SurfaceRecord { |
| 38 #if defined(OS_ANDROID) |
| 39 SurfaceRecord(gfx::AcceleratedWidget widget, jobject j_surface); |
| 40 #else // defined(OS_ANDROID) |
| 41 explicit SurfaceRecord(gfx::AcceleratedWidget widget); |
| 42 #endif // !defined(OS_ANDROID) |
| 43 |
| 44 SurfaceRecord(SurfaceRecord&&); |
| 45 SurfaceRecord(const SurfaceRecord&) = delete; |
| 46 |
| 47 gfx::AcceleratedWidget widget; |
| 48 #if defined(OS_ANDROID) |
| 49 gl::ScopedJavaSurface surface; |
| 50 #endif |
| 51 }; |
| 52 |
| 35 // GpuSurfaceLookup implementation: | 53 // GpuSurfaceLookup implementation: |
| 36 // Returns the native widget associated with a given surface_handle. | 54 // Returns the native widget associated with a given surface_handle. |
| 37 // On Android, this adds a reference on the ANativeWindow. | 55 // On Android, this adds a reference on the ANativeWindow. |
| 38 gfx::AcceleratedWidget AcquireNativeWidget( | 56 gfx::AcceleratedWidget AcquireNativeWidget( |
| 39 gpu::SurfaceHandle surface_handle) override; | 57 gpu::SurfaceHandle surface_handle) override; |
| 40 | 58 |
| 41 #if defined(OS_ANDROID) | 59 #if defined(OS_ANDROID) |
| 42 void RegisterViewSurface(int surface_id, jobject j_surface); | 60 gl::ScopedJavaSurface AcquireJavaSurface( |
| 43 void UnregisterViewSurface(int surface_id); | 61 gpu::SurfaceHandle surface_handle) override; |
| 44 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override; | |
| 45 #endif | 62 #endif |
| 46 | 63 |
| 47 // Gets the global instance of the surface tracker. | 64 // Gets the global instance of the surface tracker. |
| 48 static GpuSurfaceTracker* Get() { return GetInstance(); } | 65 static GpuSurfaceTracker* Get() { return GetInstance(); } |
| 49 | 66 |
| 50 // Adds a surface for a native widget. Returns the surface ID. | 67 // Adds a surface for a native widget. Returns the surface ID. |
| 51 int AddSurfaceForNativeWidget(gfx::AcceleratedWidget widget); | 68 int AddSurfaceForNativeWidget(SurfaceRecord record); |
| 52 | 69 |
| 53 // Return true if the surface handle is registered with the tracker. | 70 // Return true if the surface handle is registered with the tracker. |
| 54 bool IsValidSurfaceHandle(gpu::SurfaceHandle surface_handle) const; | 71 bool IsValidSurfaceHandle(gpu::SurfaceHandle surface_handle) const; |
| 55 | 72 |
| 56 // Removes a given existing surface. | 73 // Removes a given existing surface. |
| 57 void RemoveSurface(gpu::SurfaceHandle surface_handle); | 74 void RemoveSurface(gpu::SurfaceHandle surface_handle); |
| 58 | 75 |
| 59 // Returns the number of surfaces currently registered with the tracker. | 76 // Returns the number of surfaces currently registered with the tracker. |
| 60 std::size_t GetSurfaceCount(); | 77 std::size_t GetSurfaceCount(); |
| 61 | 78 |
| 62 // Gets the global instance of the surface tracker. Identical to Get(), but | 79 // Gets the global instance of the surface tracker. Identical to Get(), but |
| 63 // named that way for the implementation of Singleton. | 80 // named that way for the implementation of Singleton. |
| 64 static GpuSurfaceTracker* GetInstance(); | 81 static GpuSurfaceTracker* GetInstance(); |
| 65 | 82 |
| 66 private: | 83 private: |
| 67 typedef std::map<gpu::SurfaceHandle, gfx::AcceleratedWidget> SurfaceMap; | 84 using SurfaceMap = std::map<gpu::SurfaceHandle, SurfaceRecord>; |
| 68 | 85 |
| 69 friend struct base::DefaultSingletonTraits<GpuSurfaceTracker>; | 86 friend struct base::DefaultSingletonTraits<GpuSurfaceTracker>; |
| 70 | 87 |
| 71 GpuSurfaceTracker(); | 88 GpuSurfaceTracker(); |
| 72 ~GpuSurfaceTracker() override; | 89 ~GpuSurfaceTracker() override; |
| 73 | 90 |
| 74 mutable base::Lock surface_map_lock_; | 91 mutable base::Lock surface_map_lock_; |
| 75 SurfaceMap surface_map_; | 92 SurfaceMap surface_map_; |
| 76 int next_surface_handle_; | 93 int next_surface_handle_; |
| 77 | 94 |
| 78 #if defined(OS_ANDROID) | |
| 79 base::Lock surface_view_map_lock_; | |
| 80 typedef std::map<gpu::SurfaceHandle, gl::ScopedJavaSurface> SurfaceViewMap; | |
| 81 SurfaceViewMap surface_view_map_; | |
| 82 #endif | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker); | 95 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker); |
| 85 }; | 96 }; |
| 86 | 97 |
| 87 } // namespace ui | 98 } // namespace ui |
| 88 | 99 |
| 89 #endif // GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ | 100 #endif // GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ |
| 90 | 101 |
| OLD | NEW |