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(USE_X11) | 5 #if defined(USE_X11) |
6 #include <X11/Xlib.h> | 6 #include <X11/Xlib.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 int frames() const { return frames_; } | 131 int frames() const { return frames_; } |
132 | 132 |
133 private: | 133 private: |
134 TimeTicks start_time_; | 134 TimeTicks start_time_; |
135 int frames_; | 135 int frames_; |
136 int max_frames_; | 136 int max_frames_; |
137 | 137 |
138 DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver); | 138 DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver); |
139 }; | 139 }; |
140 | 140 |
141 class WebGLTexture : public ui::Texture { | 141 void ReturnMailbox(scoped_refptr<cc::ContextProvider> context_provider, |
142 public: | 142 GLuint texture, |
143 WebGLTexture(gpu::gles2::GLES2Interface* gl, const gfx::Size& size) | 143 GLuint sync_point, |
144 : ui::Texture(false, size, 1.0f), | 144 bool is_lost) { |
145 gl_(gl), | 145 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL(); |
146 texture_id_(0u) { | 146 gl->WaitSyncPointCHROMIUM(sync_point); |
147 gl->GenTextures(1, &texture_id_); | 147 gl->DeleteTextures(1, &texture); |
148 gl->BindTexture(GL_TEXTURE_2D, texture_id_); | 148 gl->ShallowFlushCHROMIUM(); |
149 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 149 } |
150 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
151 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
152 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
153 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), | |
154 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
155 } | |
156 | |
157 virtual unsigned int PrepareTexture() OVERRIDE { | |
158 return texture_id_; | |
159 } | |
160 | |
161 private: | |
162 virtual ~WebGLTexture() { | |
163 gl_->DeleteTextures(1, &texture_id_); | |
164 } | |
165 | |
166 gpu::gles2::GLES2Interface* gl_; | |
167 GLuint texture_id_; | |
168 | |
169 DISALLOW_COPY_AND_ASSIGN(WebGLTexture); | |
170 }; | |
171 | 150 |
172 // A benchmark that adds a texture layer that is updated every frame. | 151 // A benchmark that adds a texture layer that is updated every frame. |
173 class WebGLBench : public BenchCompositorObserver { | 152 class WebGLBench : public BenchCompositorObserver { |
174 public: | 153 public: |
175 WebGLBench(Layer* parent, Compositor* compositor, int max_frames) | 154 WebGLBench(Layer* parent, Compositor* compositor, int max_frames) |
176 : BenchCompositorObserver(max_frames), | 155 : BenchCompositorObserver(max_frames), |
177 parent_(parent), | 156 parent_(parent), |
178 webgl_(ui::LAYER_TEXTURED), | 157 webgl_(ui::LAYER_TEXTURED), |
179 compositor_(compositor), | 158 compositor_(compositor), |
180 texture_(), | |
181 fbo_(0), | 159 fbo_(0), |
182 do_draw_(true) { | 160 do_draw_(true) { |
183 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 161 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
184 do_draw_ = !command_line->HasSwitch("disable-draw"); | 162 do_draw_ = !command_line->HasSwitch("disable-draw"); |
185 | 163 |
186 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size"); | 164 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size"); |
187 int width = 0; | 165 int width = 0; |
188 int height = 0; | 166 int height = 0; |
189 if (!webgl_size.empty()) { | 167 if (!webgl_size.empty()) { |
190 std::vector<std::string> split_size; | 168 std::vector<std::string> split_size; |
191 base::SplitString(webgl_size, 'x', &split_size); | 169 base::SplitString(webgl_size, 'x', &split_size); |
192 if (split_size.size() == 2) { | 170 if (split_size.size() == 2) { |
193 width = atoi(split_size[0].c_str()); | 171 width = atoi(split_size[0].c_str()); |
194 height = atoi(split_size[1].c_str()); | 172 height = atoi(split_size[1].c_str()); |
195 } | 173 } |
196 } | 174 } |
197 if (!width || !height) { | 175 if (!width || !height) { |
198 width = 800; | 176 width = 800; |
199 height = 600; | 177 height = 600; |
200 } | 178 } |
201 gfx::Rect bounds(width, height); | 179 gfx::Rect bounds(width, height); |
202 webgl_.SetBounds(bounds); | 180 webgl_.SetBounds(bounds); |
203 parent_->Add(&webgl_); | 181 parent_->Add(&webgl_); |
204 | 182 |
205 context_provider_ = | 183 context_provider_ = |
206 ui::ContextFactory::GetInstance()->SharedMainThreadContextProvider(); | 184 ui::ContextFactory::GetInstance()->SharedMainThreadContextProvider(); |
207 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 185 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
208 texture_ = new WebGLTexture(gl, bounds.size()); | 186 GLuint texture = 0; |
| 187 gl->GenTextures(1, &texture); |
| 188 gl->BindTexture(GL_TEXTURE_2D, texture); |
| 189 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 190 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 191 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 192 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 193 gl->TexImage2D(GL_TEXTURE_2D, |
| 194 0, |
| 195 GL_RGBA, |
| 196 width, |
| 197 height, |
| 198 0, |
| 199 GL_RGBA, |
| 200 GL_UNSIGNED_BYTE, |
| 201 NULL); |
| 202 gpu::Mailbox mailbox; |
| 203 gl->GenMailboxCHROMIUM(mailbox.name); |
| 204 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 205 |
209 gl->GenFramebuffers(1, &fbo_); | 206 gl->GenFramebuffers(1, &fbo_); |
210 compositor->AddObserver(this); | |
211 webgl_.SetExternalTexture(texture_.get()); | |
212 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 207 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
213 gl->FramebufferTexture2D( | 208 gl->FramebufferTexture2D( |
214 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 209 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
215 GL_TEXTURE_2D, texture_->PrepareTexture(), 0); | |
216 gl->ClearColor(0.f, 1.f, 0.f, 1.f); | 210 gl->ClearColor(0.f, 1.f, 0.f, 1.f); |
217 gl->Clear(GL_COLOR_BUFFER_BIT); | 211 gl->Clear(GL_COLOR_BUFFER_BIT); |
218 gl->Flush(); | 212 gl->Flush(); |
| 213 |
| 214 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
| 215 webgl_.SetTextureMailbox( |
| 216 cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
| 217 cc::SingleReleaseCallback::Create( |
| 218 base::Bind(ReturnMailbox, context_provider_, texture)), |
| 219 bounds.size()); |
| 220 compositor->AddObserver(this); |
219 } | 221 } |
220 | 222 |
221 virtual ~WebGLBench() { | 223 virtual ~WebGLBench() { |
222 context_provider_->ContextGL()->DeleteFramebuffers(1, &fbo_); | |
223 webgl_.SetShowPaintedContent(); | 224 webgl_.SetShowPaintedContent(); |
224 texture_ = NULL; | 225 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
| 226 gl->DeleteFramebuffers(1, &fbo_); |
225 compositor_->RemoveObserver(this); | 227 compositor_->RemoveObserver(this); |
226 } | 228 } |
227 | 229 |
228 virtual void Draw() OVERRIDE { | 230 virtual void Draw() OVERRIDE { |
229 if (do_draw_) { | 231 if (do_draw_) { |
230 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 232 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
231 gl->ClearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); | 233 gl->ClearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); |
232 gl->Clear(GL_COLOR_BUFFER_BIT); | 234 gl->Clear(GL_COLOR_BUFFER_BIT); |
233 gl->Flush(); | 235 gl->Flush(); |
234 } | 236 } |
235 webgl_.SetExternalTexture(texture_.get()); | |
236 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); | 237 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); |
237 compositor_->ScheduleDraw(); | 238 compositor_->ScheduleDraw(); |
238 } | 239 } |
239 | 240 |
240 private: | 241 private: |
241 Layer* parent_; | 242 Layer* parent_; |
242 Layer webgl_; | 243 Layer webgl_; |
243 Compositor* compositor_; | 244 Compositor* compositor_; |
244 scoped_refptr<cc::ContextProvider> context_provider_; | 245 scoped_refptr<cc::ContextProvider> context_provider_; |
245 scoped_refptr<WebGLTexture> texture_; | |
246 | 246 |
247 // The FBO that is used to render to the texture. | 247 // The FBO that is used to render to the texture. |
248 unsigned int fbo_; | 248 unsigned int fbo_; |
249 | 249 |
250 // Whether or not to draw to the texture every frame. | 250 // Whether or not to draw to the texture every frame. |
251 bool do_draw_; | 251 bool do_draw_; |
252 | 252 |
253 DISALLOW_COPY_AND_ASSIGN(WebGLBench); | 253 DISALLOW_COPY_AND_ASSIGN(WebGLBench); |
254 }; | 254 }; |
255 | 255 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); | 361 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); |
362 #endif | 362 #endif |
363 | 363 |
364 host->Show(); | 364 host->Show(); |
365 base::MessageLoopForUI::current()->Run(); | 365 base::MessageLoopForUI::current()->Run(); |
366 focus_client.reset(); | 366 focus_client.reset(); |
367 host.reset(); | 367 host.reset(); |
368 | 368 |
369 return 0; | 369 return 0; |
370 } | 370 } |
OLD | NEW |