Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/aura/bench/bench_main.cc

Issue 21026005: aura: Remove CreateOffscreenContext from ui::ContextFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: offscreencontext: clang-format Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/bench/DEPS ('k') | ui/compositor/compositor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/i18n/icu_util.h" 8 #include "base/i18n/icu_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "cc/output/context_provider.h"
13 #include "third_party/khronos/GLES2/gl2.h" 14 #include "third_party/khronos/GLES2/gl2.h"
14 #include "third_party/skia/include/core/SkXfermode.h" 15 #include "third_party/skia/include/core/SkXfermode.h"
15 #include "ui/aura/client/default_capture_client.h" 16 #include "ui/aura/client/default_capture_client.h"
16 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
17 #include "ui/aura/focus_manager.h" 18 #include "ui/aura/focus_manager.h"
18 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
19 #include "ui/aura/test/test_screen.h" 20 #include "ui/aura/test/test_screen.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
22 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 }; 175 };
175 176
176 // A benchmark that adds a texture layer that is updated every frame. 177 // A benchmark that adds a texture layer that is updated every frame.
177 class WebGLBench : public BenchCompositorObserver { 178 class WebGLBench : public BenchCompositorObserver {
178 public: 179 public:
179 WebGLBench(Layer* parent, Compositor* compositor, int max_frames) 180 WebGLBench(Layer* parent, Compositor* compositor, int max_frames)
180 : BenchCompositorObserver(max_frames), 181 : BenchCompositorObserver(max_frames),
181 parent_(parent), 182 parent_(parent),
182 webgl_(ui::LAYER_TEXTURED), 183 webgl_(ui::LAYER_TEXTURED),
183 compositor_(compositor), 184 compositor_(compositor),
184 context_(), 185 context_provider_(),
185 texture_(), 186 texture_(),
186 fbo_(0), 187 fbo_(0),
187 do_draw_(true) { 188 do_draw_(true) {
188 CommandLine* command_line = CommandLine::ForCurrentProcess(); 189 CommandLine* command_line = CommandLine::ForCurrentProcess();
189 do_draw_ = !command_line->HasSwitch("disable-draw"); 190 do_draw_ = !command_line->HasSwitch("disable-draw");
190 191
191 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size"); 192 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size");
192 int width = 0; 193 int width = 0;
193 int height = 0; 194 int height = 0;
194 if (!webgl_size.empty()) { 195 if (!webgl_size.empty()) {
195 std::vector<std::string> split_size; 196 std::vector<std::string> split_size;
196 base::SplitString(webgl_size, 'x', &split_size); 197 base::SplitString(webgl_size, 'x', &split_size);
197 if (split_size.size() == 2) { 198 if (split_size.size() == 2) {
198 width = atoi(split_size[0].c_str()); 199 width = atoi(split_size[0].c_str());
199 height = atoi(split_size[1].c_str()); 200 height = atoi(split_size[1].c_str());
200 } 201 }
201 } 202 }
202 if (!width || !height) { 203 if (!width || !height) {
203 width = 800; 204 width = 800;
204 height = 600; 205 height = 600;
205 } 206 }
206 gfx::Rect bounds(width, height); 207 gfx::Rect bounds(width, height);
207 webgl_.SetBounds(bounds); 208 webgl_.SetBounds(bounds);
208 parent_->Add(&webgl_); 209 parent_->Add(&webgl_);
209 210
210 context_ = ui::ContextFactory::GetInstance()->CreateOffscreenContext(); 211 context_provider_ = ui::ContextFactory::GetInstance()
211 context_->makeContextCurrent(); 212 ->OffscreenContextProviderForMainThread();
212 texture_ = new WebGLTexture(context_.get(), bounds.size()); 213 WebKit::WebGraphicsContext3D* context = context_provider_->Context3d();
213 fbo_ = context_->createFramebuffer(); 214 context->makeContextCurrent();
215 texture_ = new WebGLTexture(context, bounds.size());
216 fbo_ = context->createFramebuffer();
214 compositor->AddObserver(this); 217 compositor->AddObserver(this);
215 webgl_.SetExternalTexture(texture_.get()); 218 webgl_.SetExternalTexture(texture_.get());
216 context_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); 219 context->bindFramebuffer(GL_FRAMEBUFFER, fbo_);
217 context_->framebufferTexture2D( 220 context->framebufferTexture2D(
218 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 221 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
219 GL_TEXTURE_2D, texture_->PrepareTexture(), 0); 222 GL_TEXTURE_2D, texture_->PrepareTexture(), 0);
220 context_->clearColor(0.f, 1.f, 0.f, 1.f); 223 context->clearColor(0.f, 1.f, 0.f, 1.f);
221 context_->clear(GL_COLOR_BUFFER_BIT); 224 context->clear(GL_COLOR_BUFFER_BIT);
222 context_->flush(); 225 context->flush();
223 } 226 }
224 227
225 virtual ~WebGLBench() { 228 virtual ~WebGLBench() {
226 context_->makeContextCurrent(); 229 context_provider_->Context3d()->makeContextCurrent();
227 context_->deleteFramebuffer(fbo_); 230 context_provider_->Context3d()->deleteFramebuffer(fbo_);
228 webgl_.SetExternalTexture(NULL); 231 webgl_.SetExternalTexture(NULL);
229 texture_ = NULL; 232 texture_ = NULL;
230 compositor_->RemoveObserver(this); 233 compositor_->RemoveObserver(this);
231 } 234 }
232 235
233 virtual void Draw() OVERRIDE { 236 virtual void Draw() OVERRIDE {
234 if (do_draw_) { 237 if (do_draw_) {
235 context_->makeContextCurrent(); 238 WebKit::WebGraphicsContext3D* context = context_provider_->Context3d();
236 context_->clearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); 239 context->makeContextCurrent();
237 context_->clear(GL_COLOR_BUFFER_BIT); 240 context->clearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f);
238 context_->flush(); 241 context->clear(GL_COLOR_BUFFER_BIT);
242 context->flush();
239 } 243 }
240 webgl_.SetExternalTexture(texture_.get()); 244 webgl_.SetExternalTexture(texture_.get());
241 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); 245 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size()));
242 compositor_->ScheduleDraw(); 246 compositor_->ScheduleDraw();
243 } 247 }
244 248
245 private: 249 private:
246 Layer* parent_; 250 Layer* parent_;
247 Layer webgl_; 251 Layer webgl_;
248 Compositor* compositor_; 252 Compositor* compositor_;
249 scoped_ptr<WebGraphicsContext3D> context_; 253 scoped_refptr<cc::ContextProvider> context_provider_;
250 scoped_refptr<WebGLTexture> texture_; 254 scoped_refptr<WebGLTexture> texture_;
251 255
252 // The FBO that is used to render to the texture. 256 // The FBO that is used to render to the texture.
253 unsigned int fbo_; 257 unsigned int fbo_;
254 258
255 // Whether or not to draw to the texture every frame. 259 // Whether or not to draw to the texture every frame.
256 bool do_draw_; 260 bool do_draw_;
257 261
258 DISALLOW_COPY_AND_ASSIGN(WebGLBench); 262 DISALLOW_COPY_AND_ASSIGN(WebGLBench);
259 }; 263 };
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 ui::PrintLayerHierarchy(root_window->layer(), gfx::Point(100, 100)); 358 ui::PrintLayerHierarchy(root_window->layer(), gfx::Point(100, 100));
355 #endif 359 #endif
356 360
357 root_window->ShowRootWindow(); 361 root_window->ShowRootWindow();
358 base::MessageLoopForUI::current()->Run(); 362 base::MessageLoopForUI::current()->Run();
359 focus_client.reset(); 363 focus_client.reset();
360 root_window.reset(); 364 root_window.reset();
361 365
362 return 0; 366 return 0;
363 } 367 }
OLDNEW
« no previous file with comments | « ui/aura/bench/DEPS ('k') | ui/compositor/compositor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698