|
OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #if defined(ENABLE_GPU) | |
6 | |
7 #include "content/common/gpu/image_transport_surface.h" | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/compiler_specific.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/win/windows_version.h" | |
14 #include "content/common/gpu/gpu_messages.h" | |
15 #include "ui/gfx/gl/gl_bindings.h" | |
16 #include "ui/gfx/gl/gl_context.h" | |
17 #include "ui/gfx/gl/gl_implementation.h" | |
18 #include "ui/gfx/gl/gl_surface_egl.h" | |
19 #include "ui/gfx/native_widget_types.h" | |
20 | |
21 namespace { | |
22 | |
23 // We are backed by an Pbuffer offscreen surface through which ANGLE provides | |
24 // a handle to the corresponding render target texture through an extension. | |
25 class PbufferImageTransportSurface | |
26 : public gfx::GLSurfaceAdapter, | |
jonathan.backer
2011/11/03 23:09:07
Why use this? Why not subclass the appropriate sur
apatrick_chromium
2011/11/07 20:40:04
See comment in image_transport_surface.cc
| |
27 public ImageTransportSurface, | |
28 public base::SupportsWeakPtr<PbufferImageTransportSurface> { | |
29 public: | |
30 PbufferImageTransportSurface(GpuChannelManager* manager, | |
31 int32 render_view_id, | |
32 int32 renderer_id, | |
33 int32 command_buffer_id); | |
34 | |
35 // GLSurface implementation | |
36 virtual bool Initialize(); | |
37 virtual void Destroy(); | |
38 virtual bool IsOffscreen(); | |
39 virtual bool SwapBuffers(); | |
40 | |
41 protected: | |
42 // ImageTransportSurface implementation | |
43 virtual void OnNewSurfaceACK(uint64 surface_id, | |
44 TransportDIB::Handle shm_handle) OVERRIDE; | |
45 virtual void OnBuffersSwappedACK() OVERRIDE; | |
46 virtual void OnResizeViewACK() OVERRIDE; | |
47 virtual void OnResize(gfx::Size size) OVERRIDE; | |
48 | |
49 private: | |
50 virtual ~PbufferImageTransportSurface(); | |
51 void SendBuffersSwapped(); | |
52 | |
53 scoped_ptr<ImageTransportHelper> helper_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); | |
56 }; | |
57 | |
58 PbufferImageTransportSurface::PbufferImageTransportSurface( | |
59 GpuChannelManager* manager, | |
60 int32 render_view_id, | |
61 int32 renderer_id, | |
62 int32 command_buffer_id) | |
63 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, | |
64 gfx::Size(1, 1))) { | |
65 helper_.reset(new ImageTransportHelper(this, | |
66 manager, | |
67 render_view_id, | |
68 renderer_id, | |
69 command_buffer_id, | |
70 gfx::kNullPluginWindow)); | |
71 } | |
72 | |
73 PbufferImageTransportSurface::~PbufferImageTransportSurface() { | |
74 Destroy(); | |
75 } | |
76 | |
77 bool PbufferImageTransportSurface::Initialize() { | |
78 // Only support this path if the GL implementation is ANGLE. | |
79 // IO surfaces will not work with, for example, OSMesa software renderer | |
80 // GL contexts. | |
81 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) | |
82 return false; | |
83 | |
84 if (!helper_->Initialize()) | |
85 return false; | |
86 | |
87 return GLSurfaceAdapter::Initialize(); | |
88 } | |
89 | |
90 void PbufferImageTransportSurface::Destroy() { | |
91 helper_->Destroy(); | |
92 GLSurfaceAdapter::Destroy(); | |
93 } | |
94 | |
95 bool PbufferImageTransportSurface::IsOffscreen() { | |
96 return false; | |
97 } | |
98 | |
99 bool PbufferImageTransportSurface::SwapBuffers() { | |
100 HANDLE surface_handle = GetShareHandle(); | |
101 if (!surface_handle) | |
102 return false; | |
103 | |
104 helper_->DeferToFence(base::Bind( | |
105 &PbufferImageTransportSurface::SendBuffersSwapped, | |
106 AsWeakPtr())); | |
107 | |
108 return true; | |
109 } | |
110 | |
111 void PbufferImageTransportSurface::SendBuffersSwapped() { | |
112 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
113 params.surface_id = reinterpret_cast<int64>(GetShareHandle()); | |
114 params.size = GetSize(); | |
115 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
116 | |
117 helper_->SetScheduled(false); | |
118 } | |
119 | |
120 void PbufferImageTransportSurface::OnBuffersSwappedACK() { | |
121 helper_->SetScheduled(true); | |
122 } | |
123 | |
124 void PbufferImageTransportSurface::OnNewSurfaceACK( | |
125 uint64 surface_id, | |
126 TransportDIB::Handle shm_handle) { | |
jonathan.backer
2011/11/03 23:09:07
NOTIMPLEMENTED?
| |
127 } | |
128 | |
129 void PbufferImageTransportSurface::OnResizeViewACK() { | |
jonathan.backer
2011/11/03 23:09:07
NOTIMPLEMENTED()?
| |
130 } | |
131 | |
132 void PbufferImageTransportSurface::OnResize(gfx::Size size) { | |
133 Resize(size); | |
134 } | |
135 | |
136 } // namespace anonymous | |
137 | |
138 // static | |
139 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | |
140 GpuChannelManager* manager, | |
141 int32 render_view_id, | |
142 int32 renderer_id, | |
143 int32 command_buffer_id, | |
144 gfx::PluginWindowHandle handle) { | |
145 scoped_refptr<gfx::GLSurface> surface; | |
146 | |
147 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | |
148 | |
149 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && | |
150 os_info->version() >= base::win::VERSION_VISTA) { | |
151 surface = new PbufferImageTransportSurface(manager, | |
152 render_view_id, | |
153 renderer_id, | |
154 command_buffer_id); | |
155 } else { | |
156 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | |
157 if (!surface.get()) | |
158 return NULL; | |
159 | |
160 surface = new PassThroughImageTransportSurface(manager, | |
161 render_view_id, | |
162 renderer_id, | |
163 command_buffer_id, | |
164 surface.get()); | |
165 } | |
166 | |
167 if (surface->Initialize()) | |
168 return surface; | |
169 else | |
170 return NULL; | |
171 } | |
172 | |
173 #endif // ENABLE_GPU | |
OLD | NEW |