OLD | NEW |
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/gpu/gpu_backing_store_glx.h" | 5 #include "chrome/gpu/gpu_backing_store_glx.h" |
6 | 6 |
7 #include <GL/glew.h> | 7 #include "app/gfx/gl/gl_bindings.h" |
8 | |
9 #include "app/surface/transport_dib.h" | 8 #include "app/surface/transport_dib.h" |
10 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
11 #include "chrome/common/gpu_messages.h" | 10 #include "chrome/common/gpu_messages.h" |
12 #include "chrome/gpu/gpu_backing_store_glx_context.h" | 11 #include "chrome/gpu/gpu_backing_store_glx_context.h" |
13 #include "chrome/gpu/gpu_thread.h" | 12 #include "chrome/gpu/gpu_thread.h" |
14 #include "chrome/gpu/gpu_view_x.h" | 13 #include "chrome/gpu/gpu_view_x.h" |
15 #include "skia/ext/platform_canvas.h" | 14 #include "skia/ext/platform_canvas.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
17 | 16 |
18 GpuBackingStoreGLX::GpuBackingStoreGLX(GpuViewX* view, | 17 GpuBackingStoreGLX::GpuBackingStoreGLX(GpuViewX* view, |
19 GpuThread* gpu_thread, | 18 GpuThread* gpu_thread, |
20 int32 routing_id, | 19 int32 routing_id, |
21 const gfx::Size& size) | 20 const gfx::Size& size) |
22 : view_(view), | 21 : view_(view), |
23 gpu_thread_(gpu_thread), | 22 gpu_thread_(gpu_thread), |
24 routing_id_(routing_id), | 23 routing_id_(routing_id), |
25 size_(size), | 24 size_(size), |
26 texture_id_(0) { | 25 texture_id_(0) { |
27 gpu_thread_->AddRoute(routing_id_, this); | 26 gpu_thread_->AddRoute(routing_id_, this); |
28 | 27 |
29 view_->BindContext(); // Must do this before issuing OpenGl. | 28 view_->BindContext(); // Must do this before issuing OpenGl. |
30 | 29 |
31 glGenTextures(1, &texture_id_); | 30 glGenTextures(1, &texture_id_); |
32 glBindTexture(GL_TEXTURE_2D, texture_id_); | 31 glBindTexture(GL_TEXTURE_2D, texture_id_); |
33 | 32 |
34 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 33 // TODO(apatrick): This function are not available in GLES2. |
| 34 // glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
37 } | 37 } |
38 | 38 |
39 GpuBackingStoreGLX::~GpuBackingStoreGLX() { | 39 GpuBackingStoreGLX::~GpuBackingStoreGLX() { |
40 if (texture_id_) | 40 if (texture_id_) |
41 glDeleteTextures(1, &texture_id_); | 41 glDeleteTextures(1, &texture_id_); |
42 gpu_thread_->RemoveRoute(routing_id_); | 42 gpu_thread_->RemoveRoute(routing_id_); |
43 } | 43 } |
44 | 44 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // Create a framebuffer to render our scrolled texture into. | 85 // Create a framebuffer to render our scrolled texture into. |
86 GpuBackingStoreGLXContext* context = view_->gpu_thread()->GetGLXContext(); | 86 GpuBackingStoreGLXContext* context = view_->gpu_thread()->GetGLXContext(); |
87 if (!context->BindTextureForScrolling(view_->window(), size_)) | 87 if (!context->BindTextureForScrolling(view_->window(), size_)) |
88 return; | 88 return; |
89 | 89 |
90 glEnable(GL_TEXTURE_2D); | 90 glEnable(GL_TEXTURE_2D); |
91 glBindTexture(GL_TEXTURE_2D, texture_id_); | 91 glBindTexture(GL_TEXTURE_2D, texture_id_); |
92 | 92 |
93 // Set up the the tranform so we can paint exact pixels to the screen, with | 93 // Set up the the tranform so we can paint exact pixels to the screen, with |
94 // (0, 0) at the bottom left. | 94 // (0, 0) at the bottom left. |
95 float w = static_cast<float>(size_.width()); | 95 // TODO(apatrick): Commenting out because these variables were only used by |
96 float h = static_cast<float>(size_.height()); | 96 // code that is now commented out. |
| 97 // float w = static_cast<float>(size_.width()); |
| 98 // float h = static_cast<float>(size_.height()); |
97 glViewport(0, 0, size_.width(), size_.height()); | 99 glViewport(0, 0, size_.width(), size_.height()); |
98 glLoadIdentity(); | 100 |
99 glOrtho(0.0, w, 0.0, h, -1.0, 1.0); | 101 // TODO(apatrick): These functions are not available in GLES2. |
| 102 // glLoadIdentity(); |
| 103 // glOrtho(0.0, w, 0.0, h, -1.0, 1.0); |
100 | 104 |
101 // Paint the non-scrolled background of the page. Note that we try to avoid | 105 // Paint the non-scrolled background of the page. Note that we try to avoid |
102 // this if the entire thing is scrolling, which is a common case. | 106 // this if the entire thing is scrolling, which is a common case. |
103 if (view_size != clip_rect.size()) { | 107 if (view_size != clip_rect.size()) { |
104 glBegin(GL_QUADS); | 108 // TODO(apatrick): These functions are not available in GLES2. |
105 glTexCoord2f(0.0f, 0.0f); | 109 // glBegin(GL_QUADS); |
106 glVertex2f(0.0, 0.0); | 110 // glTexCoord2f(0.0f, 0.0f); |
| 111 // glVertex2f(0.0, 0.0); |
107 | 112 |
108 glTexCoord2f(0.0f, 1.0f); | 113 // glTexCoord2f(0.0f, 1.0f); |
109 glVertex2f(0.0, h); | 114 // glVertex2f(0.0, h); |
110 | 115 |
111 glTexCoord2f(1.0f, 1.0f); | 116 // glTexCoord2f(1.0f, 1.0f); |
112 glVertex2f(w, h); | 117 // glVertex2f(w, h); |
113 | 118 |
114 glTexCoord2f(1.0f, 0.0f); | 119 // glTexCoord2f(1.0f, 0.0f); |
115 glVertex2f(w, 0.0); | 120 // glVertex2f(w, 0.0); |
116 glEnd(); | 121 // glEnd(); |
117 } | 122 } |
118 | 123 |
119 // Constrain the painting to only the area we're scrolling. Compute the clip | 124 // Constrain the painting to only the area we're scrolling. Compute the clip |
120 // rect in OpenGL pixel coords, which uses the lower-left as the origin. | 125 // rect in OpenGL pixel coords, which uses the lower-left as the origin. |
121 gfx::Rect gl_clip_rect(clip_rect.x(), clip_rect.y(), | 126 gfx::Rect gl_clip_rect(clip_rect.x(), clip_rect.y(), |
122 clip_rect.width(), clip_rect.height()); | 127 clip_rect.width(), clip_rect.height()); |
123 | 128 |
124 glEnable(GL_SCISSOR_TEST); | 129 glEnable(GL_SCISSOR_TEST); |
125 glScissor(gl_clip_rect.x(), gl_clip_rect.y(), | 130 glScissor(gl_clip_rect.x(), gl_clip_rect.y(), |
126 gl_clip_rect.width(), gl_clip_rect.height()); | 131 gl_clip_rect.width(), gl_clip_rect.height()); |
127 | 132 |
128 // Paint the offset texture. | 133 // Paint the offset texture. |
129 glTranslatef(static_cast<float>(dx), static_cast<float>(dy), 0.0f); | 134 // TODO(apatrick): These functions are not available in GLES2. |
130 glBegin(GL_QUADS); | 135 // glTranslatef(static_cast<float>(dx), static_cast<float>(dy), 0.0f); |
131 glTexCoord2f(0.0f, 0.0f); | 136 // glBegin(GL_QUADS); |
132 glVertex2f(0.0, 0.0); | 137 // glTexCoord2f(0.0f, 0.0f); |
| 138 // glVertex2f(0.0, 0.0); |
133 | 139 |
134 glTexCoord2f(0.0f, 1.0f); | 140 // glTexCoord2f(0.0f, 1.0f); |
135 glVertex2f(0.0, h); | 141 // glVertex2f(0.0, h); |
136 | 142 |
137 glTexCoord2f(1.0f, 1.0f); | 143 // glTexCoord2f(1.0f, 1.0f); |
138 glVertex2f(w, h); | 144 // glVertex2f(w, h); |
139 | 145 |
140 glTexCoord2f(1.0f, 0.0f); | 146 // glTexCoord2f(1.0f, 0.0f); |
141 glVertex2f(w, 0.0); | 147 // glVertex2f(w, 0.0); |
142 glEnd(); | 148 // glEnd(); |
143 glDisable(GL_SCISSOR_TEST); | 149 glDisable(GL_SCISSOR_TEST); |
144 | 150 |
145 glBindTexture(GL_TEXTURE_2D, 0); | 151 glBindTexture(GL_TEXTURE_2D, 0); |
146 texture_id_ = context->SwapTextureForScrolling(texture_id_, size_); | 152 texture_id_ = context->SwapTextureForScrolling(texture_id_, size_); |
147 glFlush(); | 153 glFlush(); |
148 DCHECK(texture_id_); | 154 DCHECK(texture_id_); |
149 } | 155 } |
150 | 156 |
151 void GpuBackingStoreGLX::PaintOneRectToBackingStore( | 157 void GpuBackingStoreGLX::PaintOneRectToBackingStore( |
152 const SkBitmap& transport_bitmap, | 158 const SkBitmap& transport_bitmap, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 DCHECK(err == GL_NO_ERROR) << "Error " << err << | 220 DCHECK(err == GL_NO_ERROR) << "Error " << err << |
215 " copying (" << copy_rect.x() << "," << copy_rect.y() << | 221 " copying (" << copy_rect.x() << "," << copy_rect.y() << |
216 ")," << copy_rect.width() << "x" << copy_rect.height() << | 222 ")," << copy_rect.width() << "x" << copy_rect.height() << |
217 " for bitmap " << texture_size_.width() << "x" << | 223 " for bitmap " << texture_size_.width() << "x" << |
218 texture_size_.height() << | 224 texture_size_.height() << |
219 " real size " << existing_width << "x" << existing_height << | 225 " real size " << existing_width << "x" << existing_height << |
220 " for " << this; | 226 " for " << this; |
221 */ | 227 */ |
222 } | 228 } |
223 } | 229 } |
OLD | NEW |