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 | |
33 | 29 |
34 namespace gfx { | 30 namespace gfx { |
35 class GLSurface; | 31 class GLSurface; |
36 } | 32 } |
37 | 33 |
38 namespace gpu { | 34 namespace gpu { |
39 class PreemptionFlag; | 35 class PreemptionFlag; |
40 namespace gles2 { | 36 namespace gles2 { |
41 class GLES2Decoder; | 37 class GLES2Decoder; |
42 } | 38 } |
43 } | 39 } |
44 | 40 |
45 namespace content { | 41 namespace content { |
46 class GpuChannelManager; | 42 class GpuChannelManager; |
47 class GpuCommandBufferStub; | 43 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 OnBufferPresented( | 67 virtual void BufferPresented(const BufferPresentedParams& params) = 0; |
68 const AcceleratedSurfaceMsg_BufferPresented_Params& params) = 0; | |
69 #endif | 68 #endif |
70 virtual void SetLatencyInfo( | 69 virtual void SetLatencyInfo( |
71 const std::vector<ui::LatencyInfo>& latency_info) = 0; | 70 const std::vector<ui::LatencyInfo>& latency_info) = 0; |
72 | 71 |
73 // Creates a surface with the given attributes. | 72 // Creates a surface with the given attributes. |
74 static scoped_refptr<gfx::GLSurface> CreateSurface( | 73 static scoped_refptr<gfx::GLSurface> CreateSurface( |
75 GpuChannelManager* manager, | 74 GpuChannelManager* manager, |
76 GpuCommandBufferStub* stub, | 75 GpuCommandBufferStub* stub, |
77 const gfx::GLSurfaceHandle& handle, | 76 const gfx::GLSurfaceHandle& handle, |
78 gfx::GLSurface::Format format); | 77 gfx::GLSurface::Format format); |
(...skipping 18 matching lines...) Expand all Loading... |
97 static scoped_refptr<gfx::GLSurface> CreateNativeSurface( | 96 static scoped_refptr<gfx::GLSurface> CreateNativeSurface( |
98 GpuChannelManager* manager, | 97 GpuChannelManager* manager, |
99 GpuCommandBufferStub* stub, | 98 GpuCommandBufferStub* stub, |
100 const gfx::GLSurfaceHandle& handle, | 99 const gfx::GLSurfaceHandle& handle, |
101 gfx::GLSurface::Format format); | 100 gfx::GLSurface::Format format); |
102 | 101 |
103 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface); | 102 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface); |
104 }; | 103 }; |
105 | 104 |
106 class ImageTransportHelper | 105 class ImageTransportHelper |
107 : public IPC::Listener, | 106 : public base::SupportsWeakPtr<ImageTransportHelper> { |
108 public base::SupportsWeakPtr<ImageTransportHelper> { | |
109 public: | 107 public: |
110 // Takes weak pointers to objects that outlive the helper. | 108 // Takes weak pointers to objects that outlive the helper. |
111 ImageTransportHelper(ImageTransportSurface* surface, | 109 ImageTransportHelper(ImageTransportSurface* surface, |
112 GpuChannelManager* manager, | 110 GpuChannelManager* manager, |
113 GpuCommandBufferStub* stub, | 111 GpuCommandBufferStub* stub, |
114 gfx::PluginWindowHandle handle); | 112 gfx::PluginWindowHandle handle); |
115 ~ImageTransportHelper() override; | 113 ~ImageTransportHelper(); |
116 | 114 |
117 bool Initialize(gfx::GLSurface::Format format); | 115 bool Initialize(gfx::GLSurface::Format format); |
118 | 116 |
119 // IPC::Listener implementation: | |
120 bool OnMessageReceived(const IPC::Message& message) override; | |
121 | |
122 // Helper send functions. Caller fills in the surface specific params | 117 // Helper send functions. Caller fills in the surface specific params |
123 // like size and surface id. The helper fills in the rest. | 118 // like size and surface id. The helper fills in the rest. |
124 #if defined(OS_MACOSX) | 119 #if defined(OS_MACOSX) |
| 120 void BufferPresented(const BufferPresentedParams& params); |
125 void SendAcceleratedSurfaceBuffersSwapped( | 121 void SendAcceleratedSurfaceBuffersSwapped( |
126 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params); | 122 AcceleratedSurfaceBuffersSwappedParams params); |
127 #endif | 123 #endif |
128 | 124 |
129 // Make the surface's context current. | 125 // Make the surface's context current. |
130 bool MakeCurrent(); | 126 bool MakeCurrent(); |
131 | 127 |
132 // Set the default swap interval on the surface. | 128 // Set the default swap interval on the surface. |
133 static void SetSwapInterval(gfx::GLContext* context); | 129 static void SetSwapInterval(gfx::GLContext* context); |
134 | 130 |
135 GpuChannelManager* manager() const { return manager_; } | 131 GpuChannelManager* manager() const { return manager_; } |
136 GpuCommandBufferStub* stub() const { return stub_.get(); } | 132 GpuCommandBufferStub* stub() const { return stub_.get(); } |
137 | 133 |
138 private: | 134 private: |
139 gpu::gles2::GLES2Decoder* Decoder(); | 135 gpu::gles2::GLES2Decoder* Decoder(); |
140 | 136 |
141 // IPC::Message handlers. | |
142 #if defined(OS_MACOSX) | |
143 void OnBufferPresented( | |
144 const AcceleratedSurfaceMsg_BufferPresented_Params& params); | |
145 #endif | |
146 | |
147 // Backbuffer resize callback. | 137 // Backbuffer resize callback. |
148 void Resize(gfx::Size size, float scale_factor); | 138 void Resize(gfx::Size size, float scale_factor); |
149 | 139 |
150 void SetLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info); | 140 void SetLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info); |
151 | 141 |
152 // Weak pointers that point to objects that outlive this helper. | 142 // Weak pointers that point to objects that outlive this helper. |
153 ImageTransportSurface* surface_; | 143 ImageTransportSurface* surface_; |
154 GpuChannelManager* manager_; | 144 GpuChannelManager* manager_; |
155 | 145 |
156 base::WeakPtr<GpuCommandBufferStub> stub_; | 146 base::WeakPtr<GpuCommandBufferStub> stub_; |
(...skipping 24 matching lines...) Expand all Loading... |
181 int width, | 171 int width, |
182 int height, | 172 int height, |
183 const SwapCompletionCallback& callback) override; | 173 const SwapCompletionCallback& callback) override; |
184 gfx::SwapResult CommitOverlayPlanes() override; | 174 gfx::SwapResult CommitOverlayPlanes() override; |
185 void CommitOverlayPlanesAsync( | 175 void CommitOverlayPlanesAsync( |
186 const SwapCompletionCallback& callback) override; | 176 const SwapCompletionCallback& callback) override; |
187 bool OnMakeCurrent(gfx::GLContext* context) override; | 177 bool OnMakeCurrent(gfx::GLContext* context) override; |
188 | 178 |
189 // ImageTransportSurface implementation. | 179 // ImageTransportSurface implementation. |
190 #if defined(OS_MACOSX) | 180 #if defined(OS_MACOSX) |
191 void OnBufferPresented( | 181 void BufferPresented(const BufferPresentedParams& params) override; |
192 const AcceleratedSurfaceMsg_BufferPresented_Params& params) override; | |
193 #endif | 182 #endif |
194 gfx::Size GetSize() override; | 183 gfx::Size GetSize() override; |
195 void SetLatencyInfo( | 184 void SetLatencyInfo( |
196 const std::vector<ui::LatencyInfo>& latency_info) override; | 185 const std::vector<ui::LatencyInfo>& latency_info) override; |
197 | 186 |
198 protected: | 187 protected: |
199 ~PassThroughImageTransportSurface() override; | 188 ~PassThroughImageTransportSurface() override; |
200 | 189 |
201 // If updated vsync parameters can be determined, send this information to | 190 // If updated vsync parameters can be determined, send this information to |
202 // the browser. | 191 // the browser. |
(...skipping 14 matching lines...) Expand all Loading... |
217 bool did_set_swap_interval_; | 206 bool did_set_swap_interval_; |
218 std::vector<ui::LatencyInfo> latency_info_; | 207 std::vector<ui::LatencyInfo> latency_info_; |
219 base::WeakPtrFactory<PassThroughImageTransportSurface> weak_ptr_factory_; | 208 base::WeakPtrFactory<PassThroughImageTransportSurface> weak_ptr_factory_; |
220 | 209 |
221 DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface); | 210 DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface); |
222 }; | 211 }; |
223 | 212 |
224 } // namespace content | 213 } // namespace content |
225 | 214 |
226 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ | 215 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ |
OLD | NEW |