Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: chrome/renderer/render_widget.cc

Issue 1136006: Calling OpenGL from the renderer process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | gpu/command_buffer/build_gles2_cmd_buffer.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/renderer/render_widget.h" 5 #include "chrome/renderer/render_widget.h"
6 6
7 #include "app/surface/transport_dib.h" 7 #include "app/surface/transport_dib.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 #include "chrome/renderer/render_process.h" 15 #include "chrome/renderer/render_process.h"
16 #include "chrome/renderer/render_thread.h" 16 #include "chrome/renderer/render_thread.h"
17 #include "gfx/point.h" 17 #include "gfx/point.h"
18 #include "gfx/size.h" 18 #include "gfx/size.h"
19 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
20 #include "third_party/skia/include/core/SkShader.h" 20 #include "third_party/skia/include/core/SkShader.h"
21 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
22 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h" 22 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenu.h"
23 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h" 23 #include "third_party/WebKit/WebKit/chromium/public/WebPopupMenuInfo.h"
24 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" 24 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
25 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" 25 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
26 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" 26 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
27 #include "webkit/glue/webkit_glue.h" 27 #include "webkit/glue/webkit_glue.h"
28 28
29 // TODO(apatrick): begin hack. Will remove before checkin.
30 #if defined(OS_WIN) && defined(ENABLE_GPU)
31 #include "chrome/renderer/ggl/ggl.h"
32 #include "gpu/gles2/gl2.h"
33 #endif
34 // end hack
35
29 #if defined(OS_POSIX) 36 #if defined(OS_POSIX)
30 #include "ipc/ipc_channel_posix.h" 37 #include "ipc/ipc_channel_posix.h"
31 #include "third_party/skia/include/core/SkPixelRef.h" 38 #include "third_party/skia/include/core/SkPixelRef.h"
32 #include "third_party/skia/include/core/SkMallocPixelRef.h" 39 #include "third_party/skia/include/core/SkMallocPixelRef.h"
33 #endif // defined(OS_POSIX) 40 #endif // defined(OS_POSIX)
34 41
35 #include "third_party/WebKit/WebKit/chromium/public/WebWidget.h" 42 #include "third_party/WebKit/WebKit/chromium/public/WebWidget.h"
36 43
37 using WebKit::WebCompositionCommand; 44 using WebKit::WebCompositionCommand;
38 using WebKit::WebCursorInfo; 45 using WebKit::WebCursorInfo;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) 150 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
144 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck) 151 IPC_MESSAGE_HANDLER(ViewMsg_CreateVideo_ACK, OnCreateVideoAck)
145 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck) 152 IPC_MESSAGE_HANDLER(ViewMsg_UpdateVideo_ACK, OnUpdateVideoAck)
146 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) 153 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
147 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) 154 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
148 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) 155 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
149 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) 156 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode)
150 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) 157 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
151 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) 158 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint)
152 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) 159 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
153 IPC_MESSAGE_HANDLER(ViewMsg_GpuChannelEstablished, OnGpuChannelEstablished)
154 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) 160 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
155 IPC_MESSAGE_UNHANDLED_ERROR() 161 IPC_MESSAGE_UNHANDLED_ERROR()
156 IPC_END_MESSAGE_MAP() 162 IPC_END_MESSAGE_MAP()
157 163
158 bool RenderWidget::Send(IPC::Message* message) { 164 bool RenderWidget::Send(IPC::Message* message) {
159 // Don't send any messages after the browser has told us to close. 165 // Don't send any messages after the browser has told us to close.
160 if (closing_) { 166 if (closing_) {
161 delete message; 167 delete message;
162 return false; 168 return false;
163 } 169 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 392 }
387 393
388 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); 394 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
389 395
390 PaintDebugBorder(rect, canvas); 396 PaintDebugBorder(rect, canvas);
391 397
392 // Flush to underlying bitmap. TODO(darin): is this needed? 398 // Flush to underlying bitmap. TODO(darin): is this needed?
393 canvas->getTopPlatformDevice().accessBitmap(false); 399 canvas->getTopPlatformDevice().accessBitmap(false);
394 400
395 canvas->restore(); 401 canvas->restore();
402
403 // TODO(apatrick): begin hack. Will remove before checkin. This is an example of how to call OpenGL from a renderer process.
404 #if defined(OS_WIN) && defined(ENABLE_GPU)
405 //GpuChannelHost* channel = RenderThread::current()->GetGpuChannel();
406 //if (!channel) {
407 // RenderThread::current()->EstablishGpuChannel();
408 //} else {
409 // DebugBreak();
410 // ggl::Context* view_context = ggl::CreateViewContext(channel,
411 // host_window_);
412 // ggl::Context* offscreen_context = ggl::CreateOffscreenContext(channel, vie w_context, 256, 256);
413 // GLuint offscreen_texture_id = ggl::GetParentTextureId(offscreen_context);
414
415 // ggl::MakeCurrent(view_context);
416
417 // GLenum error = glGetError();
418 // glBindTexture(GL_TEXTURE_2D, offscreen_texture_id);
419 // error = glGetError();
420
421 // ggl::MakeCurrent(offscreen_context);
422 // glClearColor(1, 1, 0, 1);
423 // glClear(GL_COLOR_BUFFER_BIT);
424 // ggl::SwapBuffers();
425 // glFinish();
426
427 // ggl::MakeCurrent(view_context);
428 // glClearColor(1, 0, 1, 1);
429 // glClear(GL_COLOR_BUFFER_BIT);
430 // ggl::SwapBuffers();
431
432 // error = glGetError();
433 // glBindTexture(GL_TEXTURE_2D, offscreen_texture_id);
434 // error = glGetError();
435
436 // ggl::DestroyContext(offscreen_context);
437 // ggl::DestroyContext(view_context);
438 //}
439 #endif
396 } 440 }
397 441
398 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, 442 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
399 skia::PlatformCanvas* canvas) { 443 skia::PlatformCanvas* canvas) {
400 static bool kPaintBorder = 444 static bool kPaintBorder =
401 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); 445 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
402 if (!kPaintBorder) 446 if (!kPaintBorder)
403 return; 447 return;
404 448
405 // Cycle through these colors to help distinguish new paint rects. 449 // Cycle through these colors to help distinguish new paint rects.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); 769 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
726 didInvalidateRect(repaint_rect); 770 didInvalidateRect(repaint_rect);
727 } 771 }
728 772
729 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { 773 void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
730 if (!webwidget_) 774 if (!webwidget_)
731 return; 775 return;
732 webwidget_->setTextDirection(direction); 776 webwidget_->setTextDirection(direction);
733 } 777 }
734 778
735 void RenderWidget::OnGpuChannelEstablished(
736 const IPC::ChannelHandle& channel_handle) {
737 #if defined(OS_POSIX)
738 // If we received a ChannelHandle, register it now.
739 if (channel_handle.socket.fd >= 0)
740 IPC::AddChannelSocket(channel_handle.name, channel_handle.socket.fd);
741 #endif
742
743 if (channel_handle.name.size() != 0) {
744 // Connect to the GPU process if a channel name was received.
745 gpu_channel_->Connect(channel_handle.name);
746 } else {
747 // Otherwise cancel the connection.
748 gpu_channel_ = NULL;
749 }
750 }
751
752 void RenderWidget::SetHidden(bool hidden) { 779 void RenderWidget::SetHidden(bool hidden) {
753 if (is_hidden_ == hidden) 780 if (is_hidden_ == hidden)
754 return; 781 return;
755 782
756 // The status has changed. Tell the RenderThread about it. 783 // The status has changed. Tell the RenderThread about it.
757 is_hidden_ = hidden; 784 is_hidden_ = hidden;
758 if (is_hidden_) 785 if (is_hidden_)
759 render_thread_->WidgetHidden(); 786 render_thread_->WidgetHidden();
760 else 787 else
761 render_thread_->WidgetRestored(); 788 render_thread_->WidgetRestored();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { 912 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
886 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); 913 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
887 i != plugin_window_moves_.end(); ++i) { 914 i != plugin_window_moves_.end(); ++i) {
888 if (i->window == window) { 915 if (i->window == window) {
889 plugin_window_moves_.erase(i); 916 plugin_window_moves_.erase(i);
890 break; 917 break;
891 } 918 }
892 } 919 }
893 } 920 }
894 921
895 void RenderWidget::EstablishGpuChannel() {
896 if (gpu_channel_.get()) {
897 // Do nothing if we are already establishing GPU channel.
898 if (gpu_channel_->state() == GpuChannelHost::UNCONNECTED)
899 return;
900
901 // Recreate the channel if it has been lost.
902 if (gpu_channel_->state() == GpuChannelHost::LOST)
903 gpu_channel_ = NULL;
904 }
905
906 if (!gpu_channel_.get())
907 gpu_channel_ = new GpuChannelHost;
908
909 // Ask the browser for the channel name.
910 CHECK(Send(new ViewHostMsg_EstablishGpuChannel(routing_id_)));
911 }
912
913 GpuChannelHost* RenderWidget::GetGpuChannel() {
914 if (!gpu_channel_.get())
915 return NULL;
916
917 if (gpu_channel_->state() != GpuChannelHost::CONNECTED)
918 return NULL;
919
920 return gpu_channel_.get();
921 }
922
OLDNEW
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | gpu/command_buffer/build_gles2_cmd_buffer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698