Chromium Code Reviews| 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 #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 Loading... | |
| 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_ = |
| 211 context_->makeContextCurrent(); | 212 ui::ContextFactory::GetInstance()-> |
| 212 texture_ = new WebGLTexture(context_.get(), bounds.size()); | 213 OffscreenContextProviderForMainThread(); |
|
sadrul
2013/08/13 01:18:17
I assume this follows any special indentation rule
danakj
2013/08/13 01:21:09
I clang-formatted it now just in case.
| |
| 213 fbo_ = context_->createFramebuffer(); | 214 WebKit::WebGraphicsContext3D* context = context_provider_->Context3d(); |
| 215 context->makeContextCurrent(); | |
| 216 texture_ = new WebGLTexture(context, bounds.size()); | |
| 217 fbo_ = context->createFramebuffer(); | |
| 214 compositor->AddObserver(this); | 218 compositor->AddObserver(this); |
| 215 webgl_.SetExternalTexture(texture_.get()); | 219 webgl_.SetExternalTexture(texture_.get()); |
| 216 context_->bindFramebuffer(GL_FRAMEBUFFER, fbo_); | 220 context->bindFramebuffer(GL_FRAMEBUFFER, fbo_); |
| 217 context_->framebufferTexture2D( | 221 context->framebufferTexture2D( |
| 218 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 222 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 219 GL_TEXTURE_2D, texture_->PrepareTexture(), 0); | 223 GL_TEXTURE_2D, texture_->PrepareTexture(), 0); |
| 220 context_->clearColor(0.f, 1.f, 0.f, 1.f); | 224 context->clearColor(0.f, 1.f, 0.f, 1.f); |
| 221 context_->clear(GL_COLOR_BUFFER_BIT); | 225 context->clear(GL_COLOR_BUFFER_BIT); |
| 222 context_->flush(); | 226 context->flush(); |
| 223 } | 227 } |
| 224 | 228 |
| 225 virtual ~WebGLBench() { | 229 virtual ~WebGLBench() { |
| 226 context_->makeContextCurrent(); | 230 context_provider_->Context3d()->makeContextCurrent(); |
| 227 context_->deleteFramebuffer(fbo_); | 231 context_provider_->Context3d()->deleteFramebuffer(fbo_); |
| 228 webgl_.SetExternalTexture(NULL); | 232 webgl_.SetExternalTexture(NULL); |
| 229 texture_ = NULL; | 233 texture_ = NULL; |
| 230 compositor_->RemoveObserver(this); | 234 compositor_->RemoveObserver(this); |
| 231 } | 235 } |
| 232 | 236 |
| 233 virtual void Draw() OVERRIDE { | 237 virtual void Draw() OVERRIDE { |
| 234 if (do_draw_) { | 238 if (do_draw_) { |
| 235 context_->makeContextCurrent(); | 239 WebKit::WebGraphicsContext3D* context = context_provider_->Context3d(); |
| 236 context_->clearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); | 240 context->makeContextCurrent(); |
| 237 context_->clear(GL_COLOR_BUFFER_BIT); | 241 context->clearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); |
| 238 context_->flush(); | 242 context->clear(GL_COLOR_BUFFER_BIT); |
| 243 context->flush(); | |
| 239 } | 244 } |
| 240 webgl_.SetExternalTexture(texture_.get()); | 245 webgl_.SetExternalTexture(texture_.get()); |
| 241 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); | 246 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); |
| 242 compositor_->ScheduleDraw(); | 247 compositor_->ScheduleDraw(); |
| 243 } | 248 } |
| 244 | 249 |
| 245 private: | 250 private: |
| 246 Layer* parent_; | 251 Layer* parent_; |
| 247 Layer webgl_; | 252 Layer webgl_; |
| 248 Compositor* compositor_; | 253 Compositor* compositor_; |
| 249 scoped_ptr<WebGraphicsContext3D> context_; | 254 scoped_refptr<cc::ContextProvider> context_provider_; |
| 250 scoped_refptr<WebGLTexture> texture_; | 255 scoped_refptr<WebGLTexture> texture_; |
| 251 | 256 |
| 252 // The FBO that is used to render to the texture. | 257 // The FBO that is used to render to the texture. |
| 253 unsigned int fbo_; | 258 unsigned int fbo_; |
| 254 | 259 |
| 255 // Whether or not to draw to the texture every frame. | 260 // Whether or not to draw to the texture every frame. |
| 256 bool do_draw_; | 261 bool do_draw_; |
| 257 | 262 |
| 258 DISALLOW_COPY_AND_ASSIGN(WebGLBench); | 263 DISALLOW_COPY_AND_ASSIGN(WebGLBench); |
| 259 }; | 264 }; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 ui::PrintLayerHierarchy(root_window->layer(), gfx::Point(100, 100)); | 359 ui::PrintLayerHierarchy(root_window->layer(), gfx::Point(100, 100)); |
| 355 #endif | 360 #endif |
| 356 | 361 |
| 357 root_window->ShowRootWindow(); | 362 root_window->ShowRootWindow(); |
| 358 base::MessageLoopForUI::current()->Run(); | 363 base::MessageLoopForUI::current()->Run(); |
| 359 focus_client.reset(); | 364 focus_client.reset(); |
| 360 root_window.reset(); | 365 root_window.reset(); |
| 361 | 366 |
| 362 return 0; | 367 return 0; |
| 363 } | 368 } |
| OLD | NEW |