OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/gpu/gpu_view_x.h" | |
6 | |
7 #include "app/gfx/gl/gl_bindings.h" | |
8 #include "base/scoped_ptr.h" | |
9 #include "chrome/common/gpu_messages.h" | |
10 #include "chrome/gpu/gpu_backing_store_glx.h" | |
11 #include "chrome/gpu/gpu_backing_store_glx_context.h" | |
12 #include "chrome/gpu/gpu_thread.h" | |
13 #include "chrome/gpu/gpu_video_layer_glx.h" | |
14 | |
15 // X stuff must be last since it does "#define Status int" which messes up some | |
16 // of the header files we indirectly pull in. | |
17 #include <X11/Xutil.h> | |
18 | |
19 GpuViewX::GpuViewX(GpuThread* gpu_thread, | |
20 XID parent, | |
21 int32 routing_id) | |
22 : gpu_thread_(gpu_thread), | |
23 routing_id_(routing_id), | |
24 window_(parent) { | |
25 gpu_thread_->AddRoute(routing_id_, this); | |
26 } | |
27 | |
28 GpuViewX::~GpuViewX() { | |
29 gpu_thread_->RemoveRoute(routing_id_); | |
30 // TODO(brettw) may want to delete any dangling backing stores, or perhaps | |
31 // assert if one still exists. | |
32 } | |
33 | |
34 GLXContext GpuViewX::BindContext() { | |
35 GLXContext ctx = gpu_thread_->GetGLXContext()->BindContext(window_); | |
36 CHECK(ctx); | |
37 return ctx; | |
38 } | |
39 | |
40 void GpuViewX::OnMessageReceived(const IPC::Message& msg) { | |
41 IPC_BEGIN_MESSAGE_MAP(GpuViewX, msg) | |
42 IPC_MESSAGE_HANDLER(GpuMsg_NewBackingStore, OnNewBackingStore) | |
43 IPC_MESSAGE_HANDLER(GpuMsg_NewVideoLayer, OnNewVideoLayer) | |
44 IPC_MESSAGE_HANDLER(GpuMsg_WindowPainted, OnWindowPainted) | |
45 IPC_END_MESSAGE_MAP_EX() | |
46 } | |
47 | |
48 void GpuViewX::OnChannelConnected(int32 peer_pid) { | |
49 } | |
50 | |
51 void GpuViewX::OnChannelError() { | |
52 // TODO(brettw) do we need to delete ourselves now? | |
53 } | |
54 | |
55 void GpuViewX::DidScrollBackingStoreRect(int dx, int dy, | |
56 const gfx::Rect& rect) { | |
57 } | |
58 | |
59 void GpuViewX::Repaint() { | |
60 BindContext(); | |
61 | |
62 const gfx::Size& size = backing_store_->size(); | |
63 | |
64 glViewport(0, 0, size.width(), size.height()); | |
65 | |
66 // TODO(apatrick): These functions are not available in GLES2. | |
67 // glMatrixMode(GL_MODELVIEW); | |
68 // glLoadIdentity(); | |
69 | |
70 glEnable(GL_TEXTURE_2D); | |
71 glBindTexture(GL_TEXTURE_2D, backing_store_->texture_id()); | |
72 | |
73 // TODO(brettw) use vertex buffers. | |
74 // TODO(brettw) make this so we use the texture size rather than the whole | |
75 // area size so we don't stretch bitmaps. | |
76 // TODO(apatrick): These functions are not available in GLES2. | |
77 // glBegin(GL_QUADS); | |
78 // glTexCoord2f(0.0f, 0.0f); | |
79 // glVertex2f(-1.0, 1.0); | |
80 | |
81 // glTexCoord2f(0.0f, 1.0f); | |
82 // glVertex2f(-1.0, -1.0); | |
83 | |
84 // glTexCoord2f(1.0f, 1.0f); | |
85 // glVertex2f(1.0, -1.0); | |
86 | |
87 // glTexCoord2f(1.0f, 0.0f); | |
88 // glVertex2f(1.0, 1.0); | |
89 // glEnd(); | |
90 DCHECK(glGetError() == GL_NO_ERROR); | |
91 | |
92 if (video_layer_.get()) { | |
93 video_layer_->Render(backing_store_->size()); | |
94 DCHECK(glGetError() == GL_NO_ERROR); | |
95 } | |
96 | |
97 // TODO(brettw) when we no longer stretch non-fitting bitmaps, we should | |
98 // paint white over any unpainted area here. | |
99 | |
100 glXSwapBuffers(gpu_thread_->display(), window_); | |
101 } | |
102 | |
103 void GpuViewX::OnNewBackingStore(int32 routing_id, const gfx::Size& size) { | |
104 backing_store_.reset( | |
105 new GpuBackingStoreGLX(this, gpu_thread_, routing_id, size)); | |
106 } | |
107 | |
108 void GpuViewX::OnNewVideoLayer(int32 routing_id, const gfx::Size& size) { | |
109 video_layer_.reset( | |
110 new GpuVideoLayerGLX(this, gpu_thread_, routing_id, size)); | |
111 } | |
112 | |
113 void GpuViewX::OnWindowPainted() { | |
114 Repaint(); | |
115 } | |
OLD | NEW |