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

Side by Side Diff: cc/output/geometry_binding.cc

Issue 14600002: HW draw workarounds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixups to force hw with this patch Created 7 years, 7 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 | « cc/output/geometry_binding.h ('k') | cc/output/gl_renderer.h » ('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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/output/geometry_binding.h" 5 #include "cc/output/geometry_binding.h"
6 6
7 #include "cc/output/gl_renderer.h" // For the GLC() macro. 7 #include "cc/output/gl_renderer.h" // For the GLC() macro.
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 8 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
9 #include "third_party/khronos/GLES2/gl2.h" 9 #include "third_party/khronos/GLES2/gl2.h"
10 #include "ui/gfx/rect_f.h"
11 10
12 namespace cc { 11 namespace cc {
13 12
14 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, 13 GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context,
15 const gfx::RectF& quad_vertex_rect) 14 const gfx::RectF& quad_vertex_rect)
16 : context_(context), 15 : quad_vertex_rect_(quad_vertex_rect),
16 context_(context),
17 quad_vertices_vbo_(0), 17 quad_vertices_vbo_(0),
18 quad_elements_vbo_(0) { 18 quad_elements_vbo_(0) {
19 }
20
21 GeometryBinding::~GeometryBinding() {
22 GLC(context_, context_->deleteBuffer(quad_vertices_vbo_));
23 GLC(context_, context_->deleteBuffer(quad_elements_vbo_));
24 }
25
26 void GeometryBinding::PrepareForDraw() {
19 struct Vertex { 27 struct Vertex {
20 float a_position[3]; 28 float a_position[3];
21 float a_texCoord[2]; 29 float a_texCoord[2];
22 // Index of the vertex, divide by 4 to have the matrix for this quad. 30 // Index of the vertex, divide by 4 to have the matrix for this quad.
23 float a_index; 31 float a_index;
24 }; 32 };
25 struct Quad { 33 struct Quad {
26 Vertex v0, v1, v2, v3; 34 Vertex v0, v1, v2, v3;
27 }; 35 };
28 struct QuadIndex { 36 struct QuadIndex {
29 uint16 data[6]; 37 uint16 data[6];
30 }; 38 };
31 39
32 COMPILE_ASSERT( 40 COMPILE_ASSERT(
33 sizeof(Quad) == 24 * sizeof(float), // NOLINT(runtime/sizeof) 41 sizeof(Quad) == 24 * sizeof(float), // NOLINT(runtime/sizeof)
34 struct_is_densely_packed); 42 struct_is_densely_packed);
35 COMPILE_ASSERT( 43 COMPILE_ASSERT(
36 sizeof(QuadIndex) == 6 * sizeof(uint16_t), // NOLINT(runtime/sizeof) 44 sizeof(QuadIndex) == 6 * sizeof(uint16_t), // NOLINT(runtime/sizeof)
37 struct_is_densely_packed); 45 struct_is_densely_packed);
38 46
39 Quad quad_list[8]; 47 Quad quad_list[8];
40 QuadIndex quad_index_list[8]; 48 QuadIndex quad_index_list[8];
41 for (int i = 0; i < 8; i++) { 49 for (int i = 0; i < 8; i++) {
42 Vertex v0 = { { quad_vertex_rect.x(), quad_vertex_rect.bottom(), 0.0f, }, 50 Vertex v0 = { { quad_vertex_rect_.x(), quad_vertex_rect_.bottom(), 0.0f, },
43 { 0.0f, 1.0f, }, 51 { 0.0f, 1.0f, },
44 i * 4.0f + 0.0f }; 52 i * 4.0f + 0.0f };
45 Vertex v1 = { { quad_vertex_rect.x(), quad_vertex_rect.y(), 0.0f, }, 53 Vertex v1 = { { quad_vertex_rect_.x(), quad_vertex_rect_.y(), 0.0f, },
46 { 0.0f, 0.0f, }, 54 { 0.0f, 0.0f, },
47 i * 4.0f + 1.0f }; 55 i * 4.0f + 1.0f };
48 Vertex v2 = { { quad_vertex_rect.right(), quad_vertex_rect.y(), 0.0f, }, 56 Vertex v2 = { { quad_vertex_rect_.right(), quad_vertex_rect_.y(), 0.0f, },
49 { 1.0f, .0f, }, 57 { 1.0f, .0f, },
50 i * 4.0f + 2.0f }; 58 i * 4.0f + 2.0f };
51 Vertex v3 = { { quad_vertex_rect.right(), 59 Vertex v3 = { { quad_vertex_rect_.right(),
52 quad_vertex_rect.bottom(), 60 quad_vertex_rect_.bottom(),
53 0.0f, }, 61 0.0f, },
54 { 1.0f, 1.0f, }, 62 { 1.0f, 1.0f, },
55 i * 4.0f + 3.0f }; 63 i * 4.0f + 3.0f };
56 Quad x = { v0, v1, v2, v3 }; 64 Quad x = { v0, v1, v2, v3 };
57 quad_list[i] = x; 65 quad_list[i] = x;
58 QuadIndex y = { { static_cast<uint16>(0 + 4 * i), 66 QuadIndex y = { { static_cast<uint16>(0 + 4 * i),
59 static_cast<uint16>(1 + 4 * i), 67 static_cast<uint16>(1 + 4 * i),
60 static_cast<uint16>(2 + 4 * i), 68 static_cast<uint16>(2 + 4 * i),
61 static_cast<uint16>(3 + 4 * i), 69 static_cast<uint16>(3 + 4 * i),
62 static_cast<uint16>(0 + 4 * i), 70 static_cast<uint16>(0 + 4 * i),
63 static_cast<uint16>(2 + 4 * i) } }; 71 static_cast<uint16>(2 + 4 * i) } };
64 quad_index_list[i] = y; 72 quad_index_list[i] = y;
65 } 73 }
66 74
75 // Leaks
67 GLC(context_, quad_vertices_vbo_ = context_->createBuffer()); 76 GLC(context_, quad_vertices_vbo_ = context_->createBuffer());
68 GLC(context_, quad_elements_vbo_ = context_->createBuffer()); 77 GLC(context_, quad_elements_vbo_ = context_->createBuffer());
69 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); 78 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
70 GLC(context_, 79 GLC(context_,
71 context_->bufferData( 80 context_->bufferData(
72 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW)); 81 GL_ARRAY_BUFFER, sizeof(quad_list), quad_list, GL_STATIC_DRAW));
73 GLC(context_, 82 GLC(context_,
74 context_->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); 83 context_->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
75 GLC(context_, 84 GLC(context_,
76 context_->bufferData(GL_ELEMENT_ARRAY_BUFFER, 85 context_->bufferData(GL_ELEMENT_ARRAY_BUFFER,
77 sizeof(quad_index_list), 86 sizeof(quad_index_list),
78 quad_index_list, 87 quad_index_list,
79 GL_STATIC_DRAW)); 88 GL_STATIC_DRAW));
80 }
81 89
82 GeometryBinding::~GeometryBinding() {
83 GLC(context_, context_->deleteBuffer(quad_vertices_vbo_));
84 GLC(context_, context_->deleteBuffer(quad_elements_vbo_));
85 }
86
87 void GeometryBinding::PrepareForDraw() {
88 GLC(context_, 90 GLC(context_,
89 context_->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_)); 91 context_->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, quad_elements_vbo_));
90 92
91 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_)); 93 GLC(context_, context_->bindBuffer(GL_ARRAY_BUFFER, quad_vertices_vbo_));
92 GLC(context_, 94 GLC(context_,
93 context_->vertexAttribPointer( 95 context_->vertexAttribPointer(
94 PositionAttribLocation(), 96 PositionAttribLocation(),
95 3, 97 3,
96 GL_FLOAT, 98 GL_FLOAT,
97 false, 99 false,
(...skipping 15 matching lines...) Expand all
113 false, 115 false,
114 6 * sizeof(float), // NOLINT(runtime/sizeof) 116 6 * sizeof(float), // NOLINT(runtime/sizeof)
115 5 * sizeof(float))); // NOLINT(runtime/sizeof) 117 5 * sizeof(float))); // NOLINT(runtime/sizeof)
116 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation())); 118 GLC(context_, context_->enableVertexAttribArray(PositionAttribLocation()));
117 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation())); 119 GLC(context_, context_->enableVertexAttribArray(TexCoordAttribLocation()));
118 GLC(context_, 120 GLC(context_,
119 context_->enableVertexAttribArray(TriangleIndexAttribLocation())); 121 context_->enableVertexAttribArray(TriangleIndexAttribLocation()));
120 } 122 }
121 123
122 } // namespace cc 124 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/geometry_binding.h ('k') | cc/output/gl_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698