Chromium Code Reviews| 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 // Record 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 Record { | |
| 38 // Do not mark 'explicit', since most platforms can just provide a widget | |
| 39 // and we'll automatically construct a Record for it. | |
| 40 Record(gfx::AcceleratedWidget widget | |
| 41 #if defined(OS_ANDROID) | |
| 42 , | |
| 43 jobject j_surface | |
|
boliu
2017/04/10 22:50:46
maybe just write two versions of the constructor,
| |
| 44 #endif | |
| 45 ); | |
| 46 Record(Record&&); | |
| 47 Record(const Record&) = delete; | |
| 48 | |
| 49 gfx::AcceleratedWidget widget; | |
| 50 #if defined(OS_ANDROID) | |
| 51 gl::ScopedJavaSurface surface; | |
| 52 #endif | |
| 53 }; | |
| 54 | |
| 35 // GpuSurfaceLookup implementation: | 55 // GpuSurfaceLookup implementation: |
| 36 // Returns the native widget associated with a given surface_handle. | 56 // Returns the native widget associated with a given surface_handle. |
| 37 // On Android, this adds a reference on the ANativeWindow. | 57 // On Android, this adds a reference on the ANativeWindow. |
| 38 gfx::AcceleratedWidget AcquireNativeWidget( | 58 gfx::AcceleratedWidget AcquireNativeWidget( |
| 39 gpu::SurfaceHandle surface_handle) override; | 59 gpu::SurfaceHandle surface_handle) override; |
| 40 | 60 |
| 41 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
| 42 void RegisterViewSurface(int surface_id, jobject j_surface); | 62 gl::ScopedJavaSurface AcquireJavaSurface( |
| 43 void UnregisterViewSurface(int surface_id); | 63 gpu::SurfaceHandle surface_handle) override; |
| 44 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override; | |
| 45 #endif | 64 #endif |
| 46 | 65 |
| 47 // Gets the global instance of the surface tracker. | 66 // Gets the global instance of the surface tracker. |
| 48 static GpuSurfaceTracker* Get() { return GetInstance(); } | 67 static GpuSurfaceTracker* Get() { return GetInstance(); } |
| 49 | 68 |
| 50 // Adds a surface for a native widget. Returns the surface ID. | 69 // Adds a surface for a native widget. Returns the surface ID. |
| 51 int AddSurfaceForNativeWidget(gfx::AcceleratedWidget widget); | 70 int AddSurfaceForNativeWidget(Record record); |
| 52 | 71 |
| 53 // Return true if the surface handle is registered with the tracker. | 72 // Return true if the surface handle is registered with the tracker. |
| 54 bool IsValidSurfaceHandle(gpu::SurfaceHandle surface_handle) const; | 73 bool IsValidSurfaceHandle(gpu::SurfaceHandle surface_handle) const; |
| 55 | 74 |
| 56 // Removes a given existing surface. | 75 // Removes a given existing surface. |
| 57 void RemoveSurface(gpu::SurfaceHandle surface_handle); | 76 void RemoveSurface(gpu::SurfaceHandle surface_handle); |
| 58 | 77 |
| 59 // Returns the number of surfaces currently registered with the tracker. | 78 // Returns the number of surfaces currently registered with the tracker. |
| 60 std::size_t GetSurfaceCount(); | 79 std::size_t GetSurfaceCount(); |
| 61 | 80 |
| 62 // Gets the global instance of the surface tracker. Identical to Get(), but | 81 // Gets the global instance of the surface tracker. Identical to Get(), but |
| 63 // named that way for the implementation of Singleton. | 82 // named that way for the implementation of Singleton. |
| 64 static GpuSurfaceTracker* GetInstance(); | 83 static GpuSurfaceTracker* GetInstance(); |
| 65 | 84 |
| 66 private: | 85 private: |
| 67 typedef std::map<gpu::SurfaceHandle, gfx::AcceleratedWidget> SurfaceMap; | 86 typedef std::map<gpu::SurfaceHandle, Record> SurfaceMap; |
| 68 | 87 |
| 69 friend struct base::DefaultSingletonTraits<GpuSurfaceTracker>; | 88 friend struct base::DefaultSingletonTraits<GpuSurfaceTracker>; |
| 70 | 89 |
| 71 GpuSurfaceTracker(); | 90 GpuSurfaceTracker(); |
| 72 ~GpuSurfaceTracker() override; | 91 ~GpuSurfaceTracker() override; |
| 73 | 92 |
| 74 mutable base::Lock surface_map_lock_; | 93 mutable base::Lock surface_map_lock_; |
| 75 SurfaceMap surface_map_; | 94 SurfaceMap surface_map_; |
| 76 int next_surface_handle_; | 95 int next_surface_handle_; |
| 77 | 96 |
| 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); | 97 DISALLOW_COPY_AND_ASSIGN(GpuSurfaceTracker); |
| 85 }; | 98 }; |
| 86 | 99 |
| 87 } // namespace ui | 100 } // namespace ui |
| 88 | 101 |
| 89 #endif // GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ | 102 #endif // GPU_IPC_COMMON_GPU_SURFACE_TRACKER_H_ |
| 90 | 103 |
| OLD | NEW |