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

Side by Side Diff: content/renderer/gpu/compositor_software_output_device_gl_adapter.cc

Issue 11967033: [CLOSED] In-browser software compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the lack SkCanvas::clear scissoring. Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/gpu/compositor_software_output_device_gl_adapter.h" 5 #include "content/renderer/gpu/compositor_software_output_device_gl_adapter.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkDevice.h"
10 #include "third_party/skia/include/core/SkPixelRef.h" 11 #include "third_party/skia/include/core/SkPixelRef.h"
11 #include "third_party/skia/include/core/SkDevice.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
14 12
15 #include <GLES2/gl2.h> 13 #include <GLES2/gl2.h>
16 14
17 using WebKit::WebImage;
18 using WebKit::WebGraphicsContext3D;
19 using WebKit::WebSize;
20
21 namespace content { 15 namespace content {
22 16
23 //------------------------------------------------------------------------------
24
25 CompositorSoftwareOutputDeviceGLAdapter:: 17 CompositorSoftwareOutputDeviceGLAdapter::
26 CompositorSoftwareOutputDeviceGLAdapter(WebGraphicsContext3D* context3D) 18 CompositorSoftwareOutputDeviceGLAdapter(
27 : initialized_(false), 19 WebKit::WebGraphicsContext3D* context3D)
28 program_(0), 20 : program_(0),
29 vertex_shader_(0), 21 vertex_shader_(0),
30 fragment_shader_(0), 22 fragment_shader_(0),
31 vertex_buffer_(0), 23 vertex_buffer_(0),
32 framebuffer_texture_id_(0), 24 texture_id_(0),
33 context3d_(context3D), 25 context3d_(context3D) {
34 locked_for_write_(false) {
35 } 26 }
36 27
37 CompositorSoftwareOutputDeviceGLAdapter:: 28 CompositorSoftwareOutputDeviceGLAdapter::
38 ~CompositorSoftwareOutputDeviceGLAdapter() { 29 ~CompositorSoftwareOutputDeviceGLAdapter() {
39 Destroy(); 30 if (!device_)
31 return;
32
33 context3d_->makeContextCurrent();
34 context3d_->deleteShader(vertex_shader_);
35 context3d_->deleteShader(fragment_shader_);
36 context3d_->deleteProgram(program_);
37 context3d_->deleteBuffer(vertex_buffer_);
38 context3d_->deleteTexture(texture_id_);
40 } 39 }
41 40
42 WebImage* CompositorSoftwareOutputDeviceGLAdapter::Lock(bool forWrite) { 41 void CompositorSoftwareOutputDeviceGLAdapter::EndPaint(
43 locked_for_write_ = forWrite; 42 const gfx::Rect& damage_rect) {
44 image_ = device_->accessBitmap(forWrite); 43 TRACE_EVENT0("renderer", "CompositorSoftwareOutputDeviceGLAdapter::EndPaint");
45 return &image_; 44 DCHECK(device_);
45 const SkBitmap& bitmap = device_->accessBitmap(false);
46
47 context3d_->makeContextCurrent();
48 context3d_->ensureBackbufferCHROMIUM();
49 context3d_->clear(GL_COLOR_BUFFER_BIT);
50 context3d_->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
51 viewport_size_.width(), viewport_size_.height(),
52 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap.pixelRef()->pixels());
53 context3d_->drawArrays(GL_TRIANGLE_STRIP, 0, 4);
54 context3d_->prepareTexture();
46 } 55 }
47 56
48 void CompositorSoftwareOutputDeviceGLAdapter::Unlock() { 57 void CompositorSoftwareOutputDeviceGLAdapter::Resize(
49 if (locked_for_write_) 58 const gfx::Size& viewport_size) {
50 Draw(device_->accessBitmap(false).pixelRef()->pixels()); 59 if (!device_)
51 image_.reset(); 60 InitShaders();
61
62 SoftwareOutputDeviceImpl::Resize(viewport_size);
63
64 context3d_->makeContextCurrent();
65 context3d_->ensureBackbufferCHROMIUM();
66 context3d_->viewport(0, 0, viewport_size.width(), viewport_size.height());
67 context3d_->reshape(viewport_size.width(), viewport_size.height());
52 } 68 }
53 69
54 void CompositorSoftwareOutputDeviceGLAdapter::DidChangeViewportSize( 70 void CompositorSoftwareOutputDeviceGLAdapter::InitShaders() {
55 gfx::Size size) {
56 if (!initialized_)
57 Initialize();
58
59 if (framebuffer_texture_size_ != gfx::Size(size))
60 Resize(size);
61 }
62
63 void CompositorSoftwareOutputDeviceGLAdapter::Initialize() {
64 // Vertex shader that flips the y axis. 71 // Vertex shader that flips the y axis.
65 static const char g_vertex_shader[] = 72 static const char g_vertex_shader[] =
66 "attribute vec4 a_Position;" 73 "attribute vec4 a_Position;"
67 "attribute vec2 a_texCoord;" 74 "attribute vec2 a_texCoord;"
68 "varying vec2 v_texCoord;" 75 "varying vec2 v_texCoord;"
69 "void main() {" 76 "void main() {"
70 " gl_Position = a_Position;" 77 " gl_Position = a_Position;"
71 " gl_Position.y = -gl_Position.y;" 78 " gl_Position.y = -gl_Position.y;"
72 " v_texCoord = a_texCoord;" 79 " v_texCoord = a_texCoord;"
73 "}"; 80 "}";
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 context3d_->bindAttribLocation(program_, 1, "a_texCoord"); 126 context3d_->bindAttribLocation(program_, 1, "a_texCoord");
120 127
121 context3d_->linkProgram(program_); 128 context3d_->linkProgram(program_);
122 context3d_->useProgram(program_); 129 context3d_->useProgram(program_);
123 130
124 int texture_uniform = context3d_->getUniformLocation(program_, "s_texture"); 131 int texture_uniform = context3d_->getUniformLocation(program_, "s_texture");
125 context3d_->uniform1i(texture_uniform, 0); 132 context3d_->uniform1i(texture_uniform, 0);
126 context3d_->disable(GL_SCISSOR_TEST); 133 context3d_->disable(GL_SCISSOR_TEST);
127 context3d_->clearColor(0, 0, 1, 1); 134 context3d_->clearColor(0, 0, 1, 1);
128 135
129 initialized_ = true; 136 texture_id_ = context3d_->createTexture();
130 } 137 context3d_->bindTexture(GL_TEXTURE_2D, texture_id_);
131
132 void CompositorSoftwareOutputDeviceGLAdapter::Destroy() {
133 if (!initialized_)
134 return;
135
136 context3d_->makeContextCurrent();
137 context3d_->deleteShader(vertex_shader_);
138 context3d_->deleteShader(fragment_shader_);
139 context3d_->deleteProgram(program_);
140 context3d_->deleteBuffer(vertex_buffer_);
141 if (framebuffer_texture_id_)
142 context3d_->deleteTexture(framebuffer_texture_id_);
143 }
144
145 void CompositorSoftwareOutputDeviceGLAdapter::Resize(
146 const gfx::Size& viewport_size) {
147 framebuffer_texture_size_ = viewport_size;
148 device_.reset(new SkDevice(SkBitmap::kARGB_8888_Config,
149 viewport_size.width(), viewport_size.height(), true));
150
151 context3d_->makeContextCurrent();
152 context3d_->ensureBackbufferCHROMIUM();
153 framebuffer_texture_id_ = context3d_->createTexture();
154 context3d_->bindTexture(GL_TEXTURE_2D, framebuffer_texture_id_);
155 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 138 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
156 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 139 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
157 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 140 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
158 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 141 context3d_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
159
160 context3d_->viewport(0, 0, viewport_size.width(), viewport_size.height());
161 context3d_->reshape(viewport_size.width(), viewport_size.height());
162 }
163
164 void CompositorSoftwareOutputDeviceGLAdapter::Draw(void* pixels) {
165 TRACE_EVENT0("renderer", "CompositorSoftwareOutputDeviceGLAdapter::Draw");
166 if (!initialized_)
167 NOTREACHED();
168 if (!framebuffer_texture_id_)
169 NOTREACHED();
170
171 context3d_->makeContextCurrent();
172 context3d_->ensureBackbufferCHROMIUM();
173 context3d_->clear(GL_COLOR_BUFFER_BIT);
174
175 context3d_->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
176 framebuffer_texture_size_.width(), framebuffer_texture_size_.height(),
177 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
178
179 context3d_->drawArrays(GL_TRIANGLE_STRIP, 0, 4);
180
181 context3d_->prepareTexture();
182 } 142 }
183 143
184 } // namespace content 144 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/compositor_software_output_device_gl_adapter.h ('k') | ui/base/x/x11_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698