OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #if defined(ENABLE_GPU) | 9 #if defined(ENABLE_GPU) |
10 | 10 |
| 11 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
12 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
13 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
| 16 #include "ui/gfx/gl/gl_surface.h" |
14 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
15 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
16 #include "ui/gfx/surface/transport_dib.h" | 19 #include "ui/gfx/surface/transport_dib.h" |
17 | 20 |
18 class GpuChannelManager; | 21 class GpuChannelManager; |
19 | 22 |
20 struct GpuHostMsg_AcceleratedSurfaceNew_Params; | 23 struct GpuHostMsg_AcceleratedSurfaceNew_Params; |
21 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; | 24 struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params; |
22 struct GpuHostMsg_AcceleratedSurfaceRelease_Params; | 25 struct GpuHostMsg_AcceleratedSurfaceRelease_Params; |
23 | 26 |
(...skipping 17 matching lines...) Expand all Loading... |
41 // The ImageTransportSurface class defines an simple interface for events that | 44 // The ImageTransportSurface class defines an simple interface for events that |
42 // should be responded to. The factory returns an offscreen surface that looks | 45 // should be responded to. The factory returns an offscreen surface that looks |
43 // a lot like an onscreen surface to the GPU process. | 46 // a lot like an onscreen surface to the GPU process. |
44 // | 47 // |
45 // The ImageTransportSurfaceHelper provides some glue to the outside world: | 48 // The ImageTransportSurfaceHelper provides some glue to the outside world: |
46 // making sure outside events reach the ImageTransportSurface and | 49 // making sure outside events reach the ImageTransportSurface and |
47 // allowing the ImageTransportSurface to send events to the outside world. | 50 // allowing the ImageTransportSurface to send events to the outside world. |
48 | 51 |
49 class ImageTransportSurface { | 52 class ImageTransportSurface { |
50 public: | 53 public: |
| 54 ImageTransportSurface(); |
| 55 virtual ~ImageTransportSurface(); |
| 56 |
51 virtual void OnNewSurfaceACK( | 57 virtual void OnNewSurfaceACK( |
52 uint64 surface_id, TransportDIB::Handle surface_handle) = 0; | 58 uint64 surface_id, TransportDIB::Handle surface_handle) = 0; |
53 virtual void OnBuffersSwappedACK() = 0; | 59 virtual void OnBuffersSwappedACK() = 0; |
| 60 virtual void OnResizeViewACK() = 0; |
54 virtual void OnResize(gfx::Size size) = 0; | 61 virtual void OnResize(gfx::Size size) = 0; |
55 | 62 |
56 // Creates the appropriate surface depending on the GL implementation. | 63 // Creates the appropriate surface depending on the GL implementation. |
57 static scoped_refptr<gfx::GLSurface> | 64 static scoped_refptr<gfx::GLSurface> |
58 CreateSurface(GpuChannelManager* manager, | 65 CreateSurface(GpuChannelManager* manager, |
59 int32 render_view_id, | 66 int32 render_view_id, |
60 int32 renderer_id, | 67 int32 renderer_id, |
61 int32 command_buffer_id, | 68 int32 command_buffer_id, |
62 gfx::PluginWindowHandle handle); | 69 gfx::PluginWindowHandle handle); |
| 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface); |
63 }; | 72 }; |
64 | 73 |
65 class ImageTransportHelper : public IPC::Channel::Listener { | 74 class ImageTransportHelper : public IPC::Channel::Listener { |
66 public: | 75 public: |
67 // Takes weak pointers to objects that outlive the helper. | 76 // Takes weak pointers to objects that outlive the helper. |
68 ImageTransportHelper(ImageTransportSurface* surface, | 77 ImageTransportHelper(ImageTransportSurface* surface, |
69 GpuChannelManager* manager, | 78 GpuChannelManager* manager, |
70 int32 render_view_id, | 79 int32 render_view_id, |
71 int32 renderer_id, | 80 int32 renderer_id, |
72 int32 command_buffer_id, | 81 int32 command_buffer_id, |
73 gfx::PluginWindowHandle handle); | 82 gfx::PluginWindowHandle handle); |
74 virtual ~ImageTransportHelper(); | 83 virtual ~ImageTransportHelper(); |
75 | 84 |
76 bool Initialize(); | 85 bool Initialize(); |
77 void Destroy(); | 86 void Destroy(); |
78 | 87 |
79 // IPC::Channel::Listener implementation: | 88 // IPC::Channel::Listener implementation: |
80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
81 | 90 |
82 // Helper send functions. Caller fills in the surface specific params | 91 // Helper send functions. Caller fills in the surface specific params |
83 // like size and surface id. The helper fills in the rest. | 92 // like size and surface id. The helper fills in the rest. |
84 void SendAcceleratedSurfaceNew( | 93 void SendAcceleratedSurfaceNew( |
85 GpuHostMsg_AcceleratedSurfaceNew_Params params); | 94 GpuHostMsg_AcceleratedSurfaceNew_Params params); |
86 void SendAcceleratedSurfaceBuffersSwapped( | 95 void SendAcceleratedSurfaceBuffersSwapped( |
87 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params); | 96 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params); |
88 void SendAcceleratedSurfaceRelease( | 97 void SendAcceleratedSurfaceRelease( |
89 GpuHostMsg_AcceleratedSurfaceRelease_Params params); | 98 GpuHostMsg_AcceleratedSurfaceRelease_Params params); |
| 99 void SendResizeView(const gfx::Size& size); |
90 | 100 |
91 // Whether or not we should execute more commands. | 101 // Whether or not we should execute more commands. |
92 void SetScheduled(bool is_scheduled); | 102 void SetScheduled(bool is_scheduled); |
93 | 103 |
| 104 void DeferToFence(base::Closure task); |
| 105 |
94 // Make the surface's context current. | 106 // Make the surface's context current. |
95 bool MakeCurrent(); | 107 bool MakeCurrent(); |
96 | 108 |
97 private: | 109 private: |
98 gpu::GpuScheduler* Scheduler(); | 110 gpu::GpuScheduler* Scheduler(); |
99 gpu::gles2::GLES2Decoder* Decoder(); | 111 gpu::gles2::GLES2Decoder* Decoder(); |
100 | 112 |
101 // IPC::Message handlers. | 113 // IPC::Message handlers. |
102 void OnNewSurfaceACK(uint64 surface_id, TransportDIB::Handle surface_handle); | 114 void OnNewSurfaceACK(uint64 surface_id, TransportDIB::Handle surface_handle); |
103 void OnBuffersSwappedACK(); | 115 void OnBuffersSwappedACK(); |
| 116 void OnResizeViewACK(); |
104 | 117 |
105 // Backbuffer resize callback. | 118 // Backbuffer resize callback. |
106 void Resize(gfx::Size size); | 119 void Resize(gfx::Size size); |
107 | 120 |
| 121 // Set the default swap interval on the surface. |
| 122 void SetSwapInterval(); |
| 123 |
108 // Weak pointers that point to objects that outlive this helper. | 124 // Weak pointers that point to objects that outlive this helper. |
109 ImageTransportSurface* surface_; | 125 ImageTransportSurface* surface_; |
110 GpuChannelManager* manager_; | 126 GpuChannelManager* manager_; |
111 | 127 |
112 int32 render_view_id_; | 128 int32 render_view_id_; |
113 int32 renderer_id_; | 129 int32 renderer_id_; |
114 int32 command_buffer_id_; | 130 int32 command_buffer_id_; |
115 int32 route_id_; | 131 int32 route_id_; |
116 gfx::PluginWindowHandle handle_; | 132 gfx::PluginWindowHandle handle_; |
117 | 133 |
118 DISALLOW_COPY_AND_ASSIGN(ImageTransportHelper); | 134 DISALLOW_COPY_AND_ASSIGN(ImageTransportHelper); |
119 }; | 135 }; |
120 | 136 |
| 137 // An implementation of ImageTransportSurface that implements GLSurface through |
| 138 // GLSurfaceAdapter, thereby forwarding GLSurface methods through to it. |
| 139 class PassThroughImageTransportSurface |
| 140 : public gfx::GLSurfaceAdapter, |
| 141 public ImageTransportSurface { |
| 142 public: |
| 143 PassThroughImageTransportSurface(GpuChannelManager* manager, |
| 144 int32 render_view_id, |
| 145 int32 renderer_id, |
| 146 int32 command_buffer_id, |
| 147 gfx::GLSurface* surface); |
| 148 virtual ~PassThroughImageTransportSurface(); |
| 149 |
| 150 // GLSurface implementation. |
| 151 virtual bool Initialize(); |
| 152 virtual void Destroy(); |
| 153 |
| 154 // ImageTransportSurface implementation. |
| 155 virtual void OnNewSurfaceACK( |
| 156 uint64 surface_id, TransportDIB::Handle surface_handle) OVERRIDE; |
| 157 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 158 virtual void OnResizeViewACK() OVERRIDE; |
| 159 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 160 |
| 161 private: |
| 162 scoped_ptr<ImageTransportHelper> helper_; |
| 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface); |
| 165 }; |
| 166 |
121 #endif // defined(ENABLE_GPU) | 167 #endif // defined(ENABLE_GPU) |
122 | 168 |
123 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ | 169 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_ |
OLD | NEW |