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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 bool is_lost) { | 141 bool is_lost) { |
142 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL(); | 142 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL(); |
143 gl->WaitSyncPointCHROMIUM(sync_point); | 143 gl->WaitSyncPointCHROMIUM(sync_point); |
144 gl->DeleteTextures(1, &texture); | 144 gl->DeleteTextures(1, &texture); |
145 gl->ShallowFlushCHROMIUM(); | 145 gl->ShallowFlushCHROMIUM(); |
146 } | 146 } |
147 | 147 |
148 // A benchmark that adds a texture layer that is updated every frame. | 148 // A benchmark that adds a texture layer that is updated every frame. |
149 class WebGLBench : public BenchCompositorObserver { | 149 class WebGLBench : public BenchCompositorObserver { |
150 public: | 150 public: |
151 WebGLBench(Layer* parent, Compositor* compositor, int max_frames) | 151 WebGLBench(ui::ContextFactory* context_factory, |
| 152 Layer* parent, |
| 153 Compositor* compositor, |
| 154 int max_frames) |
152 : BenchCompositorObserver(max_frames), | 155 : BenchCompositorObserver(max_frames), |
153 parent_(parent), | 156 parent_(parent), |
154 webgl_(ui::LAYER_TEXTURED), | 157 webgl_(ui::LAYER_TEXTURED), |
155 compositor_(compositor), | 158 compositor_(compositor), |
156 fbo_(0), | 159 fbo_(0), |
157 do_draw_(true) { | 160 do_draw_(true) { |
158 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 161 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
159 do_draw_ = !command_line->HasSwitch("disable-draw"); | 162 do_draw_ = !command_line->HasSwitch("disable-draw"); |
160 | 163 |
161 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size"); | 164 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size"); |
162 int width = 0; | 165 int width = 0; |
163 int height = 0; | 166 int height = 0; |
164 if (!webgl_size.empty()) { | 167 if (!webgl_size.empty()) { |
165 std::vector<std::string> split_size; | 168 std::vector<std::string> split_size; |
166 base::SplitString(webgl_size, 'x', &split_size); | 169 base::SplitString(webgl_size, 'x', &split_size); |
167 if (split_size.size() == 2) { | 170 if (split_size.size() == 2) { |
168 width = atoi(split_size[0].c_str()); | 171 width = atoi(split_size[0].c_str()); |
169 height = atoi(split_size[1].c_str()); | 172 height = atoi(split_size[1].c_str()); |
170 } | 173 } |
171 } | 174 } |
172 if (!width || !height) { | 175 if (!width || !height) { |
173 width = 800; | 176 width = 800; |
174 height = 600; | 177 height = 600; |
175 } | 178 } |
176 gfx::Rect bounds(width, height); | 179 gfx::Rect bounds(width, height); |
177 webgl_.SetBounds(bounds); | 180 webgl_.SetBounds(bounds); |
178 parent_->Add(&webgl_); | 181 parent_->Add(&webgl_); |
179 | 182 |
180 context_provider_ = | 183 context_provider_ = context_factory->SharedMainThreadContextProvider(); |
181 ui::ContextFactory::GetInstance()->SharedMainThreadContextProvider(); | |
182 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | 184 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
183 GLuint texture = 0; | 185 GLuint texture = 0; |
184 gl->GenTextures(1, &texture); | 186 gl->GenTextures(1, &texture); |
185 gl->BindTexture(GL_TEXTURE_2D, texture); | 187 gl->BindTexture(GL_TEXTURE_2D, texture); |
186 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 188 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
187 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 189 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
188 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 190 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
189 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 191 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
190 gl->TexImage2D(GL_TEXTURE_2D, | 192 gl->TexImage2D(GL_TEXTURE_2D, |
191 0, | 193 0, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 content_layer.Add(&page_background); | 344 content_layer.Add(&page_background); |
343 | 345 |
344 int frames = atoi(command_line->GetSwitchValueASCII("frames").c_str()); | 346 int frames = atoi(command_line->GetSwitchValueASCII("frames").c_str()); |
345 scoped_ptr<BenchCompositorObserver> bench; | 347 scoped_ptr<BenchCompositorObserver> bench; |
346 | 348 |
347 if (command_line->HasSwitch("bench-software-scroll")) { | 349 if (command_line->HasSwitch("bench-software-scroll")) { |
348 bench.reset(new SoftwareScrollBench(&page_background, | 350 bench.reset(new SoftwareScrollBench(&page_background, |
349 host->compositor(), | 351 host->compositor(), |
350 frames)); | 352 frames)); |
351 } else { | 353 } else { |
352 bench.reset(new WebGLBench(&page_background, | 354 bench.reset(new WebGLBench(context_factory.get(), |
| 355 &page_background, |
353 host->compositor(), | 356 host->compositor(), |
354 frames)); | 357 frames)); |
355 } | 358 } |
356 | 359 |
357 #ifndef NDEBUG | 360 #ifndef NDEBUG |
358 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); | 361 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); |
359 #endif | 362 #endif |
360 | 363 |
361 host->Show(); | 364 host->Show(); |
362 base::MessageLoopForUI::current()->Run(); | 365 base::MessageLoopForUI::current()->Run(); |
363 focus_client.reset(); | 366 focus_client.reset(); |
364 host.reset(); | 367 host.reset(); |
365 | 368 |
366 return 0; | 369 return 0; |
367 } | 370 } |
OLD | NEW |