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 CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ | 5 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ |
6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ | 6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "ipc/ipc_listener.h" | 20 #include "ipc/ipc_listener.h" |
21 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
22 #include "ui/events/latency_info.h" | 22 #include "ui/events/latency_info.h" |
23 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
24 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
25 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
26 #include "ui/gfx/swap_result.h" | 26 #include "ui/gfx/swap_result.h" |
27 #include "ui/gl/gl_surface.h" | 27 #include "ui/gl/gl_surface.h" |
28 | 28 |
| 29 #if defined(OS_MACOSX) |
| 30 struct AcceleratedSurfaceMsg_BufferPresented_Params; |
| 31 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; |
| 32 #endif |
29 | 33 |
30 namespace gfx { | 34 namespace gfx { |
31 class GLSurface; | 35 class GLSurface; |
32 } | 36 } |
33 | 37 |
34 namespace gpu { | 38 namespace gpu { |
35 class PreemptionFlag; | 39 class PreemptionFlag; |
36 namespace gles2 { | 40 namespace gles2 { |
37 class GLES2Decoder; | 41 class GLES2Decoder; |
38 } | 42 } |
39 } | 43 } |
40 | 44 |
41 namespace content { | 45 namespace content { |
42 class GpuChannelManager; | 46 class GpuChannelManager; |
43 class GpuCommandBufferStub; | 47 class GpuCommandBufferStub; |
44 #if defined(OS_MACOSX) | |
45 struct BufferPresentedParams; | |
46 struct AcceleratedSurfaceBuffersSwappedParams; | |
47 #endif | |
48 | 48 |
49 // The GPU process is agnostic as to how it displays results. On some platforms | 49 // The GPU process is agnostic as to how it displays results. On some platforms |
50 // it renders directly to window. On others it renders offscreen and transports | 50 // it renders directly to window. On others it renders offscreen and transports |
51 // the results to the browser process to display. This file provides a simple | 51 // the results to the browser process to display. This file provides a simple |
52 // framework for making the offscreen path seem more like the onscreen path. | 52 // framework for making the offscreen path seem more like the onscreen path. |
53 // | 53 // |
54 // The ImageTransportSurface class defines an simple interface for events that | 54 // The ImageTransportSurface class defines an simple interface for events that |
55 // should be responded to. The factory returns an offscreen surface that looks | 55 // should be responded to. The factory returns an offscreen surface that looks |
56 // a lot like an onscreen surface to the GPU process. | 56 // a lot like an onscreen surface to the GPU process. |
57 // | 57 // |
58 // The ImageTransportSurfaceHelper provides some glue to the outside world: | 58 // The ImageTransportSurfaceHelper provides some glue to the outside world: |
59 // making sure outside events reach the ImageTransportSurface and | 59 // making sure outside events reach the ImageTransportSurface and |
60 // allowing the ImageTransportSurface to send events to the outside world. | 60 // allowing the ImageTransportSurface to send events to the outside world. |
61 | 61 |
62 class ImageTransportSurface { | 62 class ImageTransportSurface { |
63 public: | 63 public: |
64 ImageTransportSurface(); | 64 ImageTransportSurface(); |
65 | 65 |
66 #if defined(OS_MACOSX) | 66 #if defined(OS_MACOSX) |
67 virtual void BufferPresented(const BufferPresentedParams& params) = 0; | 67 virtual void OnBufferPresented( |
| 68 const AcceleratedSurfaceMsg_BufferPresented_Params& params) = 0; |
68 #endif | 69 #endif |
69 virtual void SetLatencyInfo( | 70 virtual void SetLatencyInfo( |
70 const std::vector<ui::LatencyInfo>& latency_info) = 0; | 71 const std::vector<ui::LatencyInfo>& latency_info) = 0; |
71 | 72 |
72 // Creates a surface with the given attributes. | 73 // Creates a surface with the given attributes. |
73 static scoped_refptr<gfx::GLSurface> CreateSurface( | 74 static scoped_refptr<gfx::GLSurface> CreateSurface( |
74 GpuChannelManager* manager, | 75 GpuChannelManager* manager, |
75 GpuCommandBufferStub* stub, | 76 GpuCommandBufferStub* stub, |
76 const gfx::GLSurfaceHandle& handle, | 77 const gfx::GLSurfaceHandle& handle, |
77 gfx::GLSurface::Format format); | 78 gfx::GLSurface::Format format); |
(...skipping 18 matching lines...) Expand all Loading... |
96 static scoped_refptr<gfx::GLSurface> CreateNativeSurface( | 97 static scoped_refptr<gfx::GLSurface> CreateNativeSurface( |
97 GpuChannelManager* manager, | 98 GpuChannelManager* manager, |
98 GpuCommandBufferStub* stub, | 99 GpuCommandBufferStub* stub, |
99 const gfx::GLSurfaceHandle& handle, | 100 const gfx::GLSurfaceHandle& handle, |
100 gfx::GLSurface::Format format); | 101 gfx::GLSurface::Format format); |
101 | 102 |
102 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface); | 103 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface); |
103 }; | 104 }; |
104 | 105 |
105 class ImageTransportHelper | 106 class ImageTransportHelper |
106 : public base::SupportsWeakPtr<ImageTransportHelper> { | 107 : public IPC::Listener, |
| 108 public base::SupportsWeakPtr<ImageTransportHelper> { |
107 public: | 109 public: |
108 // Takes weak pointers to objects that outlive the helper. | 110 // Takes weak pointers to objects that outlive the helper. |
109 ImageTransportHelper(ImageTransportSurface* surface, | 111 ImageTransportHelper(ImageTransportSurface* surface, |
110 GpuChannelManager* manager, | 112 GpuChannelManager* manager, |
111 GpuCommandBufferStub* stub, | 113 GpuCommandBufferStub* stub, |
112 gfx::PluginWindowHandle handle); | 114 gfx::PluginWindowHandle handle); |
113 ~ImageTransportHelper(); | 115 ~ImageTransportHelper() override; |
114 | 116 |
115 bool Initialize(gfx::GLSurface::Format format); | 117 bool Initialize(gfx::GLSurface::Format format); |
116 | 118 |
| 119 // IPC::Listener implementation: |
| 120 bool OnMessageReceived(const IPC::Message& message) override; |
| 121 |
117 // Helper send functions. Caller fills in the surface specific params | 122 // Helper send functions. Caller fills in the surface specific params |
118 // like size and surface id. The helper fills in the rest. | 123 // like size and surface id. The helper fills in the rest. |
119 #if defined(OS_MACOSX) | 124 #if defined(OS_MACOSX) |
120 void BufferPresented(const BufferPresentedParams& params); | |
121 void SendAcceleratedSurfaceBuffersSwapped( | 125 void SendAcceleratedSurfaceBuffersSwapped( |
122 AcceleratedSurfaceBuffersSwappedParams params); | 126 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params); |
123 #endif | 127 #endif |
124 | 128 |
125 // Make the surface's context current. | 129 // Make the surface's context current. |
126 bool MakeCurrent(); | 130 bool MakeCurrent(); |
127 | 131 |
128 // Set the default swap interval on the surface. | 132 // Set the default swap interval on the surface. |
129 static void SetSwapInterval(gfx::GLContext* context); | 133 static void SetSwapInterval(gfx::GLContext* context); |
130 | 134 |
131 GpuChannelManager* manager() const { return manager_; } | 135 GpuChannelManager* manager() const { return manager_; } |
132 GpuCommandBufferStub* stub() const { return stub_.get(); } | 136 GpuCommandBufferStub* stub() const { return stub_.get(); } |
133 | 137 |
134 private: | 138 private: |
135 gpu::gles2::GLES2Decoder* Decoder(); | 139 gpu::gles2::GLES2Decoder* Decoder(); |
136 | 140 |
| 141 // IPC::Message handlers. |
| 142 #if defined(OS_MACOSX) |
| 143 void OnBufferPresented( |
| 144 const AcceleratedSurfaceMsg_BufferPresented_Params& params); |
| 145 #endif |
| 146 |
137 // Backbuffer resize callback. | 147 // Backbuffer resize callback. |
138 void Resize(gfx::Size size, float scale_factor); | 148 void Resize(gfx::Size size, float scale_factor); |
139 | 149 |
140 void SetLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info); | 150 void SetLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info); |
141 | 151 |
142 // Weak pointers that point to objects that outlive this helper. | 152 // Weak pointers that point to objects that outlive this helper. |
143 ImageTransportSurface* surface_; | 153 ImageTransportSurface* surface_; |
144 GpuChannelManager* manager_; | 154 GpuChannelManager* manager_; |
145 | 155 |
146 base::WeakPtr<GpuCommandBufferStub> stub_; | 156 base::WeakPtr<GpuCommandBufferStub> stub_; |
(...skipping 24 matching lines...) Expand all Loading... |
171 int width, | 181 int width, |
172 int height, | 182 int height, |
173 const SwapCompletionCallback& callback) override; | 183 const SwapCompletionCallback& callback) override; |
174 gfx::SwapResult CommitOverlayPlanes() override; | 184 gfx::SwapResult CommitOverlayPlanes() override; |
175 void CommitOverlayPlanesAsync( | 185 void CommitOverlayPlanesAsync( |
176 const SwapCompletionCallback& callback) override; | 186 const SwapCompletionCallback& callback) override; |
177 bool OnMakeCurrent(gfx::GLContext* context) override; | 187 bool OnMakeCurrent(gfx::GLContext* context) override; |
178 | 188 |
179 // ImageTransportSurface implementation. | 189 // ImageTransportSurface implementation. |
180 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
181 void BufferPresented(const BufferPresentedParams& params) override; | 191 void OnBufferPresented( |
| 192 const AcceleratedSurfaceMsg_BufferPresented_Params& params) override; |
182 #endif | 193 #endif |
183 gfx::Size GetSize() override; | 194 gfx::Size GetSize() override; |
184 void SetLatencyInfo( | 195 void SetLatencyInfo( |
185 const std::vector<ui::LatencyInfo>& latency_info) override; | 196 const std::vector<ui::LatencyInfo>& latency_info) override; |
186 | 197 |
187 protected: | 198 protected: |
188 ~PassThroughImageTransportSurface() override; | 199 ~PassThroughImageTransportSurface() override; |
189 | 200 |
190 // If updated vsync parameters can be determined, send this information to | 201 // If updated vsync parameters can be determined, send this information to |
191 // the browser. | 202 // the browser. |
(...skipping 14 matching lines...) Expand all Loading... |
206 bool did_set_swap_interval_; | 217 bool did_set_swap_interval_; |
207 std::vector<ui::LatencyInfo> latency_info_; | 218 std::vector<ui::LatencyInfo> latency_info_; |
208 base::WeakPtrFactory<PassThroughImageTransportSurface> weak_ptr_factory_; | 219 base::WeakPtrFactory<PassThroughImageTransportSurface> weak_ptr_factory_; |
209 | 220 |
210 DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface); | 221 DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface); |
211 }; | 222 }; |
212 | 223 |
213 } // namespace content | 224 } // namespace content |
214 | 225 |
215 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ | 226 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ |
OLD | NEW |