OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 delete cb_data; | 111 delete cb_data; |
112 return false; | 112 return false; |
113 } | 113 } |
114 | 114 |
115 gboolean Redraw(gpointer data) { | 115 gboolean Redraw(gpointer data) { |
116 GtkMainWnd* wnd = reinterpret_cast<GtkMainWnd*>(data); | 116 GtkMainWnd* wnd = reinterpret_cast<GtkMainWnd*>(data); |
117 wnd->OnRedraw(); | 117 wnd->OnRedraw(); |
118 return false; | 118 return false; |
119 } | 119 } |
120 | 120 |
| 121 gboolean Draw(GtkWidget* widget, cairo_t* cr, gpointer data) { |
| 122 GtkMainWnd* wnd = reinterpret_cast<GtkMainWnd*>(data); |
| 123 wnd->Draw(widget, cr); |
| 124 return false; |
| 125 } |
| 126 |
121 } // namespace | 127 } // namespace |
122 | 128 |
123 // | 129 // |
124 // GtkMainWnd implementation. | 130 // GtkMainWnd implementation. |
125 // | 131 // |
126 | 132 |
127 GtkMainWnd::GtkMainWnd(const char* server, int port, bool autoconnect, | 133 GtkMainWnd::GtkMainWnd(const char* server, int port, bool autoconnect, |
128 bool autocall) | 134 bool autocall) |
129 : window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL), | 135 : window_(NULL), draw_area_(NULL), vbox_(NULL), server_edit_(NULL), |
130 port_edit_(NULL), peer_list_(NULL), callback_(NULL), | 136 port_edit_(NULL), peer_list_(NULL), callback_(NULL), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ASSERT(IsWindow()); | 231 ASSERT(IsWindow()); |
226 ASSERT(vbox_ == NULL); | 232 ASSERT(vbox_ == NULL); |
227 | 233 |
228 gtk_container_set_border_width(GTK_CONTAINER(window_), 10); | 234 gtk_container_set_border_width(GTK_CONTAINER(window_), 10); |
229 | 235 |
230 if (peer_list_) { | 236 if (peer_list_) { |
231 gtk_widget_destroy(peer_list_); | 237 gtk_widget_destroy(peer_list_); |
232 peer_list_ = NULL; | 238 peer_list_ = NULL; |
233 } | 239 } |
234 | 240 |
| 241 #if GTK_MAJOR_VERSION == 2 |
235 vbox_ = gtk_vbox_new(FALSE, 5); | 242 vbox_ = gtk_vbox_new(FALSE, 5); |
| 243 #else |
| 244 vbox_ = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); |
| 245 #endif |
236 GtkWidget* valign = gtk_alignment_new(0, 1, 0, 0); | 246 GtkWidget* valign = gtk_alignment_new(0, 1, 0, 0); |
237 gtk_container_add(GTK_CONTAINER(vbox_), valign); | 247 gtk_container_add(GTK_CONTAINER(vbox_), valign); |
238 gtk_container_add(GTK_CONTAINER(window_), vbox_); | 248 gtk_container_add(GTK_CONTAINER(window_), vbox_); |
239 | 249 |
| 250 #if GTK_MAJOR_VERSION == 2 |
240 GtkWidget* hbox = gtk_hbox_new(FALSE, 5); | 251 GtkWidget* hbox = gtk_hbox_new(FALSE, 5); |
| 252 #else |
| 253 GtkWidget* hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); |
| 254 #endif |
241 | 255 |
242 GtkWidget* label = gtk_label_new("Server"); | 256 GtkWidget* label = gtk_label_new("Server"); |
243 gtk_container_add(GTK_CONTAINER(hbox), label); | 257 gtk_container_add(GTK_CONTAINER(hbox), label); |
244 | 258 |
245 server_edit_ = gtk_entry_new(); | 259 server_edit_ = gtk_entry_new(); |
246 gtk_entry_set_text(GTK_ENTRY(server_edit_), server_.c_str()); | 260 gtk_entry_set_text(GTK_ENTRY(server_edit_), server_.c_str()); |
247 gtk_widget_set_size_request(server_edit_, 400, 30); | 261 gtk_widget_set_size_request(server_edit_, 400, 30); |
248 gtk_container_add(GTK_CONTAINER(hbox), server_edit_); | 262 gtk_container_add(GTK_CONTAINER(hbox), server_edit_); |
249 | 263 |
250 port_edit_ = gtk_entry_new(); | 264 port_edit_ = gtk_entry_new(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 ASSERT(draw_area_ == NULL); | 324 ASSERT(draw_area_ == NULL); |
311 | 325 |
312 gtk_container_set_border_width(GTK_CONTAINER(window_), 0); | 326 gtk_container_set_border_width(GTK_CONTAINER(window_), 0); |
313 if (peer_list_) { | 327 if (peer_list_) { |
314 gtk_widget_destroy(peer_list_); | 328 gtk_widget_destroy(peer_list_); |
315 peer_list_ = NULL; | 329 peer_list_ = NULL; |
316 } | 330 } |
317 | 331 |
318 draw_area_ = gtk_drawing_area_new(); | 332 draw_area_ = gtk_drawing_area_new(); |
319 gtk_container_add(GTK_CONTAINER(window_), draw_area_); | 333 gtk_container_add(GTK_CONTAINER(window_), draw_area_); |
| 334 g_signal_connect(G_OBJECT(draw_area_), "draw", G_CALLBACK(&::Draw), this); |
320 | 335 |
321 gtk_widget_show_all(window_); | 336 gtk_widget_show_all(window_); |
322 } | 337 } |
323 | 338 |
324 void GtkMainWnd::OnDestroyed(GtkWidget* widget, GdkEvent* event) { | 339 void GtkMainWnd::OnDestroyed(GtkWidget* widget, GdkEvent* event) { |
325 callback_->Close(); | 340 callback_->Close(); |
326 window_ = NULL; | 341 window_ = NULL; |
327 draw_area_ = NULL; | 342 draw_area_ = NULL; |
328 vbox_ = NULL; | 343 vbox_ = NULL; |
329 server_edit_ = NULL; | 344 server_edit_ = NULL; |
330 port_edit_ = NULL; | 345 port_edit_ = NULL; |
331 peer_list_ = NULL; | 346 peer_list_ = NULL; |
332 } | 347 } |
333 | 348 |
334 void GtkMainWnd::OnClicked(GtkWidget* widget) { | 349 void GtkMainWnd::OnClicked(GtkWidget* widget) { |
335 // Make the connect button insensitive, so that it cannot be clicked more than | 350 // Make the connect button insensitive, so that it cannot be clicked more than |
336 // once. Now that the connection includes auto-retry, it should not be | 351 // once. Now that the connection includes auto-retry, it should not be |
337 // necessary to click it more than once. | 352 // necessary to click it more than once. |
338 gtk_widget_set_sensitive(widget, false); | 353 gtk_widget_set_sensitive(widget, false); |
339 server_ = gtk_entry_get_text(GTK_ENTRY(server_edit_)); | 354 server_ = gtk_entry_get_text(GTK_ENTRY(server_edit_)); |
340 port_ = gtk_entry_get_text(GTK_ENTRY(port_edit_)); | 355 port_ = gtk_entry_get_text(GTK_ENTRY(port_edit_)); |
341 int port = port_.length() ? atoi(port_.c_str()) : 0; | 356 int port = port_.length() ? atoi(port_.c_str()) : 0; |
342 callback_->StartLogin(server_, port); | 357 callback_->StartLogin(server_, port); |
343 } | 358 } |
344 | 359 |
345 void GtkMainWnd::OnKeyPress(GtkWidget* widget, GdkEventKey* key) { | 360 void GtkMainWnd::OnKeyPress(GtkWidget* widget, GdkEventKey* key) { |
346 if (key->type == GDK_KEY_PRESS) { | 361 if (key->type == GDK_KEY_PRESS) { |
347 switch (key->keyval) { | 362 switch (key->keyval) { |
348 case GDK_Escape: | 363 #if GTK_MAJOR_VERSION == 2 |
349 if (draw_area_) { | 364 case GDK_Escape: |
350 callback_->DisconnectFromCurrentPeer(); | 365 #else |
351 } else if (peer_list_) { | 366 case GDK_KEY_Escape: |
352 callback_->DisconnectFromServer(); | 367 #endif |
353 } | 368 if (draw_area_) { |
354 break; | 369 callback_->DisconnectFromCurrentPeer(); |
| 370 } else if (peer_list_) { |
| 371 callback_->DisconnectFromServer(); |
| 372 } |
| 373 break; |
355 | 374 |
356 case GDK_KP_Enter: | 375 #if GTK_MAJOR_VERSION == 2 |
357 case GDK_Return: | 376 case GDK_KP_Enter: |
358 if (vbox_) { | 377 case GDK_Return: |
359 OnClicked(NULL); | 378 #else |
360 } else if (peer_list_) { | 379 case GDK_KEY_KP_Enter: |
361 // OnRowActivated will be called automatically when the user | 380 case GDK_KEY_Return: |
362 // presses enter. | 381 #endif |
363 } | 382 if (vbox_) { |
364 break; | 383 OnClicked(NULL); |
| 384 } else if (peer_list_) { |
| 385 // OnRowActivated will be called automatically when the user |
| 386 // presses enter. |
| 387 } |
| 388 break; |
365 | 389 |
366 default: | 390 default: |
367 break; | 391 break; |
368 } | 392 } |
369 } | 393 } |
370 } | 394 } |
371 | 395 |
372 void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, | 396 void GtkMainWnd::OnRowActivated(GtkTreeView* tree_view, GtkTreePath* path, |
373 GtkTreeViewColumn* column) { | 397 GtkTreeViewColumn* column) { |
374 ASSERT(peer_list_ != NULL); | 398 ASSERT(peer_list_ != NULL); |
375 GtkTreeIter iter; | 399 GtkTreeIter iter; |
376 GtkTreeModel* model; | 400 GtkTreeModel* model; |
377 GtkTreeSelection* selection = | 401 GtkTreeSelection* selection = |
378 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | 402 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); |
379 if (gtk_tree_selection_get_selected(selection, &model, &iter)) { | 403 if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
380 char* text; | 404 char* text; |
381 int id = -1; | 405 int id = -1; |
382 gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1); | 406 gtk_tree_model_get(model, &iter, 0, &text, 1, &id, -1); |
383 if (id != -1) | 407 if (id != -1) |
384 callback_->ConnectToPeer(id); | 408 callback_->ConnectToPeer(id); |
385 g_free(text); | 409 g_free(text); |
386 } | 410 } |
387 } | 411 } |
388 | 412 |
389 void GtkMainWnd::OnRedraw() { | 413 void GtkMainWnd::OnRedraw() { |
390 gdk_threads_enter(); | 414 gdk_threads_enter(); |
391 | 415 |
392 VideoRenderer* remote_renderer = remote_renderer_.get(); | 416 VideoRenderer* remote_renderer = remote_renderer_.get(); |
393 if (remote_renderer && remote_renderer->image() != NULL && | 417 if (remote_renderer && remote_renderer->image() != NULL && |
394 draw_area_ != NULL) { | 418 draw_area_ != NULL) { |
395 int width = remote_renderer->width(); | 419 width_ = remote_renderer->width(); |
396 int height = remote_renderer->height(); | 420 height_ = remote_renderer->height(); |
397 | 421 |
398 if (!draw_buffer_.get()) { | 422 if (!draw_buffer_.get()) { |
399 draw_buffer_size_ = (width * height * 4) * 4; | 423 draw_buffer_size_ = (width_ * height_ * 4) * 4; |
400 draw_buffer_.reset(new uint8_t[draw_buffer_size_]); | 424 draw_buffer_.reset(new uint8_t[draw_buffer_size_]); |
401 gtk_widget_set_size_request(draw_area_, width * 2, height * 2); | 425 gtk_widget_set_size_request(draw_area_, width_ * 2, height_ * 2); |
402 } | 426 } |
403 | 427 |
404 const uint32_t* image = | 428 const uint32_t* image = |
405 reinterpret_cast<const uint32_t*>(remote_renderer->image()); | 429 reinterpret_cast<const uint32_t*>(remote_renderer->image()); |
406 uint32_t* scaled = reinterpret_cast<uint32_t*>(draw_buffer_.get()); | 430 uint32_t* scaled = reinterpret_cast<uint32_t*>(draw_buffer_.get()); |
407 for (int r = 0; r < height; ++r) { | 431 for (int r = 0; r < height_; ++r) { |
408 for (int c = 0; c < width; ++c) { | 432 for (int c = 0; c < width_; ++c) { |
409 int x = c * 2; | 433 int x = c * 2; |
410 scaled[x] = scaled[x + 1] = image[c]; | 434 scaled[x] = scaled[x + 1] = image[c]; |
411 } | 435 } |
412 | 436 |
413 uint32_t* prev_line = scaled; | 437 uint32_t* prev_line = scaled; |
414 scaled += width * 2; | 438 scaled += width_ * 2; |
415 memcpy(scaled, prev_line, (width * 2) * 4); | 439 memcpy(scaled, prev_line, (width_ * 2) * 4); |
416 | 440 |
417 image += width; | 441 image += width_; |
418 scaled += width * 2; | 442 scaled += width_ * 2; |
419 } | 443 } |
420 | 444 |
421 VideoRenderer* local_renderer = local_renderer_.get(); | 445 VideoRenderer* local_renderer = local_renderer_.get(); |
422 if (local_renderer && local_renderer->image()) { | 446 if (local_renderer && local_renderer->image()) { |
423 image = reinterpret_cast<const uint32_t*>(local_renderer->image()); | 447 image = reinterpret_cast<const uint32_t*>(local_renderer->image()); |
424 scaled = reinterpret_cast<uint32_t*>(draw_buffer_.get()); | 448 scaled = reinterpret_cast<uint32_t*>(draw_buffer_.get()); |
425 // Position the local preview on the right side. | 449 // Position the local preview on the right side. |
426 scaled += (width * 2) - (local_renderer->width() / 2); | 450 scaled += (width_ * 2) - (local_renderer->width() / 2); |
427 // right margin... | 451 // right margin... |
428 scaled -= 10; | 452 scaled -= 10; |
429 // ... towards the bottom. | 453 // ... towards the bottom. |
430 scaled += (height * width * 4) - | 454 scaled += (height_ * width_ * 4) - ((local_renderer->height() / 2) * |
431 ((local_renderer->height() / 2) * | 455 (local_renderer->width() / 2) * 4); |
432 (local_renderer->width() / 2) * 4); | |
433 // bottom margin... | 456 // bottom margin... |
434 scaled -= (width * 2) * 5; | 457 scaled -= (width_ * 2) * 5; |
435 for (int r = 0; r < local_renderer->height(); r += 2) { | 458 for (int r = 0; r < local_renderer->height(); r += 2) { |
436 for (int c = 0; c < local_renderer->width(); c += 2) { | 459 for (int c = 0; c < local_renderer->width(); c += 2) { |
437 scaled[c / 2] = image[c + r * local_renderer->width()]; | 460 scaled[c / 2] = image[c + r * local_renderer->width()]; |
438 } | 461 } |
439 scaled += width * 2; | 462 scaled += width_ * 2; |
440 } | 463 } |
441 } | 464 } |
442 | 465 |
| 466 #if GTK_MAJOR_VERSION == 2 |
443 gdk_draw_rgb_32_image(draw_area_->window, | 467 gdk_draw_rgb_32_image(draw_area_->window, |
444 draw_area_->style->fg_gc[GTK_STATE_NORMAL], | 468 draw_area_->style->fg_gc[GTK_STATE_NORMAL], 0, 0, |
445 0, | 469 width_ * 2, height_ * 2, GDK_RGB_DITHER_MAX, |
446 0, | 470 draw_buffer_.get(), (width_ * 2) * 4); |
447 width * 2, | 471 #else |
448 height * 2, | 472 gtk_widget_queue_draw(draw_area_); |
449 GDK_RGB_DITHER_MAX, | 473 #endif |
450 draw_buffer_.get(), | |
451 (width * 2) * 4); | |
452 } | 474 } |
453 | 475 |
454 gdk_threads_leave(); | 476 gdk_threads_leave(); |
455 } | 477 } |
456 | 478 |
| 479 void GtkMainWnd::Draw(GtkWidget* widget, cairo_t* cr) { |
| 480 #if GTK_MAJOR_VERSION != 2 |
| 481 cairo_format_t format = CAIRO_FORMAT_RGB24; |
| 482 cairo_surface_t* surface = cairo_image_surface_create_for_data( |
| 483 draw_buffer_.get(), format, width_ * 2, height_ * 2, |
| 484 cairo_format_stride_for_width(format, width_ * 2)); |
| 485 cairo_set_source_surface(cr, surface, 0, 0); |
| 486 cairo_rectangle(cr, 0, 0, width_ * 2, height_ * 2); |
| 487 cairo_fill(cr); |
| 488 cairo_surface_destroy(surface); |
| 489 #else |
| 490 RTC_NOTREACHED(); |
| 491 #endif |
| 492 } |
| 493 |
457 GtkMainWnd::VideoRenderer::VideoRenderer( | 494 GtkMainWnd::VideoRenderer::VideoRenderer( |
458 GtkMainWnd* main_wnd, | 495 GtkMainWnd* main_wnd, |
459 webrtc::VideoTrackInterface* track_to_render) | 496 webrtc::VideoTrackInterface* track_to_render) |
460 : width_(0), | 497 : width_(0), |
461 height_(0), | 498 height_(0), |
462 main_wnd_(main_wnd), | 499 main_wnd_(main_wnd), |
463 rendered_track_(track_to_render) { | 500 rendered_track_(track_to_render) { |
464 rendered_track_->AddOrUpdateSink(this, rtc::VideoSinkWants()); | 501 rendered_track_->AddOrUpdateSink(this, rtc::VideoSinkWants()); |
465 } | 502 } |
466 | 503 |
(...skipping 27 matching lines...) Expand all Loading... |
494 libyuv::I420ToRGBA(buffer->DataY(), buffer->StrideY(), | 531 libyuv::I420ToRGBA(buffer->DataY(), buffer->StrideY(), |
495 buffer->DataU(), buffer->StrideU(), | 532 buffer->DataU(), buffer->StrideU(), |
496 buffer->DataV(), buffer->StrideV(), | 533 buffer->DataV(), buffer->StrideV(), |
497 image_.get(), width_ * 4, | 534 image_.get(), width_ * 4, |
498 buffer->width(), buffer->height()); | 535 buffer->width(), buffer->height()); |
499 | 536 |
500 gdk_threads_leave(); | 537 gdk_threads_leave(); |
501 | 538 |
502 g_idle_add(Redraw, main_wnd_); | 539 g_idle_add(Redraw, main_wnd_); |
503 } | 540 } |
OLD | NEW |