| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/compositor/compositor.h" | 5 #include "ui/gfx/compositor/compositor.h" |
| 6 | 6 |
| 7 #include <GL/gl.h> | 7 #include <GL/gl.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "third_party/skia/include/core/SkMatrix.h" | 14 #include "third_party/skia/include/core/SkMatrix.h" |
| 15 #include "third_party/skia/include/core/SkScalar.h" | 15 #include "third_party/skia/include/core/SkScalar.h" |
| 16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
| 18 #include "ui/gfx/gl/gl_bindings.h" | 18 #include "ui/gfx/gl/gl_bindings.h" |
| 19 #include "ui/gfx/gl/gl_context.h" | 19 #include "ui/gfx/gl/gl_context.h" |
| 20 #include "ui/gfx/gl/gl_implementation.h" | 20 #include "ui/gfx/gl/gl_implementation.h" |
| 21 #include "ui/gfx/gl/gl_surface.h" | 21 #include "ui/gfx/gl/gl_surface.h" |
| 22 #include "ui/gfx/gl/gl_surface_glx.h" | 22 #include "ui/gfx/gl/gl_surface_glx.h" |
| 23 | 23 |
| 24 namespace ui { | 24 namespace ui { |
| 25 | 25 |
| 26 #if defined COMPOSITOR_2 | |
| 27 namespace glHidden { | 26 namespace glHidden { |
| 28 | 27 |
| 29 class CompositorGL; | 28 class CompositorGL; |
| 30 | 29 |
| 31 class TextureGL : public Texture { | 30 class TextureGL : public Texture { |
| 32 public: | 31 public: |
| 33 TextureGL(CompositorGL* compositor); | 32 TextureGL(CompositorGL* compositor); |
| 34 virtual ~TextureGL(); | 33 virtual ~TextureGL(); |
| 35 | 34 |
| 36 virtual void SetBitmap(const SkBitmap& bitmap, | 35 virtual void SetBitmap(const SkBitmap& bitmap, |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 354 |
| 356 } // namespace | 355 } // namespace |
| 357 | 356 |
| 358 // static | 357 // static |
| 359 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 358 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
| 360 gfx::GLSurface::InitializeOneOff(); | 359 gfx::GLSurface::InitializeOneOff(); |
| 361 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) | 360 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) |
| 362 return new glHidden::CompositorGL(widget); | 361 return new glHidden::CompositorGL(widget); |
| 363 return NULL; | 362 return NULL; |
| 364 } | 363 } |
| 365 #else | |
| 366 class CompositorGL : public Compositor { | |
| 367 public: | |
| 368 explicit CompositorGL(gfx::AcceleratedWidget widget); | |
| 369 | |
| 370 private: | |
| 371 // Overridden from Compositor. | |
| 372 void NotifyStart() OVERRIDE; | |
| 373 void NotifyEnd() OVERRIDE; | |
| 374 void DrawTextureWithTransform(TextureID txt, | |
| 375 const ui::Transform& transform) OVERRIDE; | |
| 376 void SaveTransform() OVERRIDE; | |
| 377 void RestoreTransform() OVERRIDE; | |
| 378 | |
| 379 // The GL context used for compositing. | |
| 380 scoped_refptr<gfx::GLSurface> gl_surface_; | |
| 381 scoped_refptr<gfx::GLContext> gl_context_; | |
| 382 | |
| 383 // Keep track of whether compositing has started or not. | |
| 384 bool started_; | |
| 385 | |
| 386 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | |
| 387 }; | |
| 388 | |
| 389 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) | |
| 390 : started_(false) { | |
| 391 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(widget); | |
| 392 gl_context_ = gfx::GLContext::CreateGLContext(NULL, gl_surface_.get()); | |
| 393 } | |
| 394 | |
| 395 void CompositorGL::NotifyStart() { | |
| 396 started_ = true; | |
| 397 gl_context_->MakeCurrent(gl_surface_.get()); | |
| 398 } | |
| 399 | |
| 400 void CompositorGL::NotifyEnd() { | |
| 401 DCHECK(started_); | |
| 402 gl_surface_->SwapBuffers(); | |
| 403 started_ = false; | |
| 404 } | |
| 405 | |
| 406 void CompositorGL::DrawTextureWithTransform(TextureID txt, | |
| 407 const ui::Transform& transform) { | |
| 408 DCHECK(started_); | |
| 409 | |
| 410 // TODO(wjmaclean): | |
| 411 NOTIMPLEMENTED(); | |
| 412 } | |
| 413 | |
| 414 void CompositorGL::SaveTransform() { | |
| 415 // TODO(sadrul): | |
| 416 NOTIMPLEMENTED(); | |
| 417 } | |
| 418 | |
| 419 void CompositorGL::RestoreTransform() { | |
| 420 // TODO(sadrul): | |
| 421 NOTIMPLEMENTED(); | |
| 422 } | |
| 423 | |
| 424 // static | |
| 425 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | |
| 426 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) | |
| 427 return new CompositorGL(widget); | |
| 428 return NULL; | |
| 429 } | |
| 430 #endif | |
| 431 | 364 |
| 432 } // namespace ui | 365 } // namespace ui |
| OLD | NEW |