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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "content/common/gpu/image_transport_surface.h" | 7 #include "content/common/gpu/image_transport_surface.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 PbufferImageTransportSurface(GpuChannelManager* manager, | 33 PbufferImageTransportSurface(GpuChannelManager* manager, |
34 GpuCommandBufferStub* stub); | 34 GpuCommandBufferStub* stub); |
35 | 35 |
36 // gfx::GLSurface implementation | 36 // gfx::GLSurface implementation |
37 virtual bool Initialize() OVERRIDE; | 37 virtual bool Initialize() OVERRIDE; |
38 virtual void Destroy() OVERRIDE; | 38 virtual void Destroy() OVERRIDE; |
39 virtual bool IsOffscreen() OVERRIDE; | 39 virtual bool IsOffscreen() OVERRIDE; |
40 virtual bool SwapBuffers() OVERRIDE; | 40 virtual bool SwapBuffers() OVERRIDE; |
41 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 41 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
42 virtual std::string GetExtensions() OVERRIDE; | 42 virtual std::string GetExtensions() OVERRIDE; |
43 virtual void SetBufferAllocation(BufferAllocationState state) OVERRIDE; | 43 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 44 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
44 | 45 |
45 protected: | 46 protected: |
46 // ImageTransportSurface implementation | 47 // ImageTransportSurface implementation |
47 virtual void OnNewSurfaceACK(uint64 surface_handle, | 48 virtual void OnNewSurfaceACK(uint64 surface_handle, |
48 TransportDIB::Handle shm_handle) OVERRIDE; | 49 TransportDIB::Handle shm_handle) OVERRIDE; |
49 virtual void OnBuffersSwappedACK() OVERRIDE; | 50 virtual void OnBuffersSwappedACK() OVERRIDE; |
50 virtual void OnPostSubBufferACK() OVERRIDE; | 51 virtual void OnPostSubBufferACK() OVERRIDE; |
51 virtual void OnResizeViewACK() OVERRIDE; | 52 virtual void OnResizeViewACK() OVERRIDE; |
52 virtual void OnResize(gfx::Size size) OVERRIDE; | 53 virtual void OnResize(gfx::Size size) OVERRIDE; |
53 | 54 |
54 private: | 55 private: |
55 virtual ~PbufferImageTransportSurface(); | 56 virtual ~PbufferImageTransportSurface(); |
56 void SendBuffersSwapped(); | 57 void SendBuffersSwapped(); |
57 void DestroySurface(); | 58 void DestroySurface(); |
58 | 59 |
59 // Tracks the current buffer allocation state. | 60 // Tracks the current buffer allocation state. |
60 BufferAllocationState buffer_allocation_state_; | 61 bool backbuffer_suggested_allocation_; |
| 62 bool frontbuffer_suggested_allocation_; |
61 | 63 |
62 // Size to resize to when the surface becomes visible. | 64 // Size to resize to when the surface becomes visible. |
63 gfx::Size visible_size_; | 65 gfx::Size visible_size_; |
64 | 66 |
65 scoped_ptr<ImageTransportHelper> helper_; | 67 scoped_ptr<ImageTransportHelper> helper_; |
66 | 68 |
67 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); | 69 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); |
68 }; | 70 }; |
69 | 71 |
70 PbufferImageTransportSurface::PbufferImageTransportSurface( | 72 PbufferImageTransportSurface::PbufferImageTransportSurface( |
71 GpuChannelManager* manager, | 73 GpuChannelManager* manager, |
72 GpuCommandBufferStub* stub) | 74 GpuCommandBufferStub* stub) |
73 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1))), | 75 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1))), |
74 buffer_allocation_state_(BUFFER_ALLOCATION_FRONT_AND_BACK) { | 76 backbuffer_suggested_allocation_(true), |
| 77 frontbuffer_suggested_allocation_(true) { |
75 helper_.reset(new ImageTransportHelper(this, | 78 helper_.reset(new ImageTransportHelper(this, |
76 manager, | 79 manager, |
77 stub, | 80 stub, |
78 gfx::kNullPluginWindow)); | 81 gfx::kNullPluginWindow)); |
79 } | 82 } |
80 | 83 |
81 PbufferImageTransportSurface::~PbufferImageTransportSurface() { | 84 PbufferImageTransportSurface::~PbufferImageTransportSurface() { |
82 Destroy(); | 85 Destroy(); |
83 } | 86 } |
84 | 87 |
(...skipping 13 matching lines...) Expand all Loading... |
98 void PbufferImageTransportSurface::Destroy() { | 101 void PbufferImageTransportSurface::Destroy() { |
99 helper_->Destroy(); | 102 helper_->Destroy(); |
100 GLSurfaceAdapter::Destroy(); | 103 GLSurfaceAdapter::Destroy(); |
101 } | 104 } |
102 | 105 |
103 bool PbufferImageTransportSurface::IsOffscreen() { | 106 bool PbufferImageTransportSurface::IsOffscreen() { |
104 return false; | 107 return false; |
105 } | 108 } |
106 | 109 |
107 bool PbufferImageTransportSurface::SwapBuffers() { | 110 bool PbufferImageTransportSurface::SwapBuffers() { |
| 111 DCHECK(backbuffer_suggested_allocation_); |
| 112 if (!frontbuffer_suggested_allocation_) |
| 113 return true; |
| 114 |
108 HANDLE surface_handle = GetShareHandle(); | 115 HANDLE surface_handle = GetShareHandle(); |
109 if (!surface_handle) | 116 if (!surface_handle) |
110 return false; | 117 return false; |
111 | 118 |
112 helper_->DeferToFence(base::Bind( | 119 helper_->DeferToFence(base::Bind( |
113 &PbufferImageTransportSurface::SendBuffersSwapped, | 120 &PbufferImageTransportSurface::SendBuffersSwapped, |
114 AsWeakPtr())); | 121 AsWeakPtr())); |
115 | 122 |
116 return true; | 123 return true; |
117 } | 124 } |
118 | 125 |
119 bool PbufferImageTransportSurface::PostSubBuffer( | 126 bool PbufferImageTransportSurface::PostSubBuffer( |
120 int x, int y, int width, int height) { | 127 int x, int y, int width, int height) { |
121 NOTREACHED(); | 128 NOTREACHED(); |
122 return false; | 129 return false; |
123 } | 130 } |
124 | 131 |
125 void PbufferImageTransportSurface::SetBufferAllocation( | 132 void PbufferImageTransportSurface::SetBackbufferAllocation(bool allocation) { |
126 BufferAllocationState state) { | 133 if (backbuffer_suggested_allocation_ == allocation) |
127 if (buffer_allocation_state_ == state) | |
128 return; | 134 return; |
129 buffer_allocation_state_ = state; | 135 backbuffer_suggested_allocation_ = allocation; |
130 | 136 |
131 switch (state) { | 137 if (backbuffer_suggested_allocation_) |
132 case BUFFER_ALLOCATION_FRONT_AND_BACK: | 138 Resize(visible_size_); |
133 Resize(visible_size_); | 139 else |
134 break; | 140 Resize(gfx::Size(1, 1)); |
135 | |
136 case BUFFER_ALLOCATION_FRONT_ONLY: | |
137 Resize(gfx::Size(1, 1)); | |
138 break; | |
139 | |
140 case BUFFER_ALLOCATION_NONE: | |
141 Resize(gfx::Size(1, 1)); | |
142 helper_->Suspend(); | |
143 break; | |
144 | |
145 default: | |
146 NOTREACHED(); | |
147 } | |
148 DestroySurface(); | 141 DestroySurface(); |
149 } | 142 } |
150 | 143 |
| 144 void PbufferImageTransportSurface::SetFrontbufferAllocation(bool allocation) { |
| 145 if (frontbuffer_suggested_allocation_ == allocation) |
| 146 return; |
| 147 frontbuffer_suggested_allocation_ = allocation; |
| 148 |
| 149 // We recreate frontbuffer by recreating backbuffer and swapping. |
| 150 // But we release frontbuffer by telling UI to release its handle on it. |
| 151 if (!frontbuffer_suggested_allocation_) |
| 152 helper_->Suspend(); |
| 153 } |
| 154 |
151 void PbufferImageTransportSurface::DestroySurface() { | 155 void PbufferImageTransportSurface::DestroySurface() { |
152 GpuHostMsg_AcceleratedSurfaceRelease_Params params; | 156 GpuHostMsg_AcceleratedSurfaceRelease_Params params; |
153 helper_->SendAcceleratedSurfaceRelease(params); | 157 helper_->SendAcceleratedSurfaceRelease(params); |
154 } | 158 } |
155 | 159 |
156 std::string PbufferImageTransportSurface::GetExtensions() { | 160 std::string PbufferImageTransportSurface::GetExtensions() { |
157 std::string extensions = gfx::GLSurface::GetExtensions(); | 161 std::string extensions = gfx::GLSurface::GetExtensions(); |
158 extensions += extensions.empty() ? "" : " "; | 162 extensions += extensions.empty() ? "" : " "; |
159 extensions += "GL_CHROMIUM_front_buffer_cached"; | 163 extensions += "GL_CHROMIUM_front_buffer_cached"; |
160 return extensions; | 164 return extensions; |
(...skipping 20 matching lines...) Expand all Loading... |
181 uint64 surface_handle, | 185 uint64 surface_handle, |
182 TransportDIB::Handle shm_handle) { | 186 TransportDIB::Handle shm_handle) { |
183 NOTREACHED(); | 187 NOTREACHED(); |
184 } | 188 } |
185 | 189 |
186 void PbufferImageTransportSurface::OnResizeViewACK() { | 190 void PbufferImageTransportSurface::OnResizeViewACK() { |
187 NOTREACHED(); | 191 NOTREACHED(); |
188 } | 192 } |
189 | 193 |
190 void PbufferImageTransportSurface::OnResize(gfx::Size size) { | 194 void PbufferImageTransportSurface::OnResize(gfx::Size size) { |
191 if (buffer_allocation_state_ == BUFFER_ALLOCATION_FRONT_AND_BACK) | 195 DCHECK(backbuffer_suggested_allocation_); |
192 Resize(size); | 196 DCHECK(frontbuffer_suggested_allocation_); |
| 197 Resize(size); |
193 | 198 |
194 DestroySurface(); | 199 DestroySurface(); |
195 | 200 |
196 visible_size_ = size; | 201 visible_size_ = size; |
197 } | 202 } |
198 | 203 |
199 } // namespace anonymous | 204 } // namespace anonymous |
200 | 205 |
201 // static | 206 // static |
202 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 207 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
(...skipping 25 matching lines...) Expand all Loading... |
228 handle.transport); | 233 handle.transport); |
229 } | 234 } |
230 | 235 |
231 if (surface->Initialize()) | 236 if (surface->Initialize()) |
232 return surface; | 237 return surface; |
233 else | 238 else |
234 return NULL; | 239 return NULL; |
235 } | 240 } |
236 | 241 |
237 #endif // ENABLE_GPU | 242 #endif // ENABLE_GPU |
OLD | NEW |