summaryrefslogtreecommitdiffstats
path: root/media/tools/shader_bench/window_linux.cc
blob: 0063a8d9d33dcf7a41a36868a77bf9c79082e9e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/tools/shader_bench/window.h"

#include "base/task.h"
#include "media/tools/shader_bench/painter.h"

#include <gdk/gdkx.h>
#include <gtk/gtk.h>

namespace media {

static gboolean OnDelete(GtkWidget* widget, GdkEventExpose* event) {
  gtk_main_quit();
  return FALSE;
}

static gboolean OnExpose(GtkWidget* widget,
                         GdkEventExpose* event,
                         gpointer data) {
  Window* window = reinterpret_cast<Window*>(data);
  if (window)
    window->OnPaint();
  return FALSE;
}

gfx::NativeWindow Window::CreateNativeWindow(int width, int height) {
  GtkWidget* hwnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_window_set_default_size(GTK_WINDOW(hwnd), width, height);
  gtk_widget_set_double_buffered(hwnd, FALSE);
  gtk_widget_set_app_paintable(hwnd, TRUE);
  gtk_widget_show(hwnd);

  return GTK_WINDOW(hwnd);
}

gfx::PluginWindowHandle Window::PluginWindow() {
  return GDK_WINDOW_XWINDOW(GTK_WIDGET(window_handle_)->window);
}

void Window::Start(int limit, Task* done_task, Painter* painter) {
  running_ = true;
  count_ = 0;
  limit_ = limit;
  done_task_ = done_task;
  painter_ = painter;

  gtk_signal_connect(GTK_OBJECT(window_handle_),
                     "delete_event",
                     reinterpret_cast<GtkSignalFunc>(OnDelete),
                     NULL);

  gtk_signal_connect(GTK_OBJECT(window_handle_),
                     "expose_event",
                     reinterpret_cast<GtkSignalFunc>(OnExpose),
                     this);

  gtk_widget_queue_draw(GTK_WIDGET(window_handle_));
  MainLoop();
}

void Window::OnPaint() {
  if (!running_)
    return;

  if (count_ < limit_) {
    painter_->OnPaint();
    count_++;
    gtk_widget_queue_draw(GTK_WIDGET(window_handle_));
  } else {
    running_ = false;
    if (done_task_) {
      done_task_->Run();
      delete done_task_;
    }
    gtk_main_quit();
  }
}

void Window::MainLoop() {
  gtk_main();
}

}  // namespace media