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_gl.h" | 5 #include "ui/gfx/compositor/compositor_gl.h" |
6 | 6 |
| 7 // for CompositorGL::SchedulePaint |
| 8 #include <gtk/gtk.h> |
| 9 #include <gdk/gdkx.h> |
| 10 |
7 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 13 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
12 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
13 #include "third_party/skia/include/core/SkDevice.h" | 17 #include "third_party/skia/include/core/SkDevice.h" |
14 #include "third_party/skia/include/core/SkMatrix.h" | 18 #include "third_party/skia/include/core/SkMatrix.h" |
15 #include "third_party/skia/include/core/SkRect.h" | 19 #include "third_party/skia/include/core/SkRect.h" |
16 #include "third_party/skia/include/core/SkScalar.h" | 20 #include "third_party/skia/include/core/SkScalar.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 glEnableVertexAttribArray(program.a_tex_loc()); | 445 glEnableVertexAttribArray(program.a_tex_loc()); |
442 | 446 |
443 glUniformMatrix4fv(program.u_mat_loc(), 1, GL_FALSE, m); | 447 glUniformMatrix4fv(program.u_mat_loc(), 1, GL_FALSE, m); |
444 | 448 |
445 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 449 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
446 } | 450 } |
447 | 451 |
448 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget, | 452 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget, |
449 const gfx::Size& size) | 453 const gfx::Size& size) |
450 : Compositor(size), | 454 : Compositor(size), |
| 455 widget_(widget), |
451 started_(false) { | 456 started_(false) { |
452 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(false, widget); | 457 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(false, widget); |
453 gl_context_ = SharedResources::GetInstance()-> | 458 gl_context_ = SharedResources::GetInstance()-> |
454 CreateContext(gl_surface_.get()); | 459 CreateContext(gl_surface_.get()); |
455 gl_context_->MakeCurrent(gl_surface_.get()); | 460 gl_context_->MakeCurrent(gl_surface_.get()); |
456 glColorMask(true, true, true, true); | 461 glColorMask(true, true, true, true); |
457 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 462 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
458 } | 463 } |
459 | 464 |
460 CompositorGL::~CompositorGL() { | 465 CompositorGL::~CompositorGL() { |
(...skipping 30 matching lines...) Expand all Loading... |
491 DCHECK(started_); | 496 DCHECK(started_); |
492 gl_surface_->SwapBuffers(); | 497 gl_surface_->SwapBuffers(); |
493 started_ = false; | 498 started_ = false; |
494 } | 499 } |
495 | 500 |
496 void CompositorGL::Blur(const gfx::Rect& bounds) { | 501 void CompositorGL::Blur(const gfx::Rect& bounds) { |
497 NOTIMPLEMENTED(); | 502 NOTIMPLEMENTED(); |
498 } | 503 } |
499 | 504 |
500 void CompositorGL::SchedulePaint() { | 505 void CompositorGL::SchedulePaint() { |
501 // TODO: X doesn't provide coalescing of regions, its left to the toolkit. | 506 // TODO(vollick) Remove or ifdef the gdk/gtk code. |
502 NOTIMPLEMENTED(); | 507 GdkDisplay* display = gdk_display_get_default(); |
| 508 GdkWindow* window = gdk_window_lookup_for_display(display, widget_); |
| 509 if (window == NULL) |
| 510 return; |
| 511 gpointer data = NULL; |
| 512 gdk_window_get_user_data(window, &data); |
| 513 GtkWidget* widget = reinterpret_cast<GtkWidget*>(data); |
| 514 if (widget && GTK_IS_WIDGET(widget) && GTK_WIDGET_DRAWABLE(widget)) |
| 515 gtk_widget_queue_draw_area(widget, 0, 0, size().width(), size().height()); |
503 } | 516 } |
504 | 517 |
505 // static | 518 // static |
506 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, | 519 Compositor* Compositor::Create(gfx::AcceleratedWidget widget, |
507 const gfx::Size& size) { | 520 const gfx::Size& size) { |
508 if (SharedResources::GetInstance() == NULL) | 521 if (SharedResources::GetInstance() == NULL) |
509 return NULL; | 522 return NULL; |
510 else | 523 else |
511 return new CompositorGL(widget, size); | 524 return new CompositorGL(widget, size); |
512 } | 525 } |
513 | 526 |
514 } // namespace ui | 527 } // namespace ui |
OLD | NEW |