OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // Whole-tree processing that's likely to be helpful in multiple render models. | 5 // Whole-tree processing that's likely to be helpful in multiple render models. |
6 | 6 |
7 #include "gpu/tools/compositor_model_bench/render_model_utils.h" | 7 #include "gpu/tools/compositor_model_bench/render_model_utils.h" |
8 | 8 |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
| 11 |
9 #include <cstdlib> | 12 #include <cstdlib> |
10 #include <map> | 13 #include <map> |
11 #include <set> | 14 #include <set> |
12 #include <vector> | 15 #include <vector> |
13 | 16 |
14 #include "base/logging.h" | 17 #include "base/logging.h" |
15 | 18 |
16 TextureGenerator::TextureGenerator(RenderNode* root) | 19 TextureGenerator::TextureGenerator(RenderNode* root) |
17 : stage_(DiscoveryStage), | 20 : stage_(DiscoveryStage), |
18 images_generated_(0) { | 21 images_generated_(0) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 void TextureGenerator::GenerateImageForTexture(int texID, | 135 void TextureGenerator::GenerateImageForTexture(int texID, |
133 int width, | 136 int width, |
134 int height, | 137 int height, |
135 GLenum format) { | 138 GLenum format) { |
136 int bytes_per_pixel = FormatBytesPerPixel(format); | 139 int bytes_per_pixel = FormatBytesPerPixel(format); |
137 DCHECK_LE(bytes_per_pixel, 4); | 140 DCHECK_LE(bytes_per_pixel, 4); |
138 int imgID = images_generated_++; | 141 int imgID = images_generated_++; |
139 image_data_[imgID].reset(new uint8[width*height*bytes_per_pixel]); | 142 image_data_[imgID].reset(new uint8_t[width * height * bytes_per_pixel]); |
140 // Pick random colors to use for this texture. | 143 // Pick random colors to use for this texture. |
141 uint8 random_color[4]; | 144 uint8_t random_color[4]; |
142 for (int c = 0; c < 4; ++c) { | 145 for (int c = 0; c < 4; ++c) { |
143 random_color[c] = std::rand() % 255; | 146 random_color[c] = std::rand() % 255; |
144 } | 147 } |
145 // Create the image from those colors. | 148 // Create the image from those colors. |
146 for (int x = 0; x < width; ++x) { | 149 for (int x = 0; x < width; ++x) { |
147 for (int y = 0; y < height; ++y) { | 150 for (int y = 0; y < height; ++y) { |
148 int pix_addr = (y * width + x) * bytes_per_pixel; | 151 int pix_addr = (y * width + x) * bytes_per_pixel; |
149 for (int c = 0; c < bytes_per_pixel; ++c) { | 152 for (int c = 0; c < bytes_per_pixel; ++c) { |
150 bool on = ((x/8) + (y/8)) % 2; | 153 bool on = ((x/8) + (y/8)) % 2; |
151 uint8 v = on ? random_color[c] : ~random_color[c]; | 154 uint8_t v = on ? random_color[c] : ~random_color[c]; |
152 (image_data_[imgID])[pix_addr + c] = v; | 155 (image_data_[imgID])[pix_addr + c] = v; |
153 } | 156 } |
154 if (bytes_per_pixel == 4) { // Randomize alpha. | 157 if (bytes_per_pixel == 4) { // Randomize alpha. |
155 image_data_[imgID][pix_addr + 3] = std::rand() % 255; | 158 image_data_[imgID][pix_addr + 3] = std::rand() % 255; |
156 } | 159 } |
157 } | 160 } |
158 } | 161 } |
159 // Set up GL texture. | 162 // Set up GL texture. |
160 glBindTexture(GL_TEXTURE_2D, texID); | 163 glBindTexture(GL_TEXTURE_2D, texID); |
161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 164 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 165 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
163 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 166 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
164 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | 167 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
165 glTexImage2D(GL_TEXTURE_2D, | 168 glTexImage2D(GL_TEXTURE_2D, |
166 0, | 169 0, |
167 format, | 170 format, |
168 width, height, | 171 width, height, |
169 0, | 172 0, |
170 format, | 173 format, |
171 GL_UNSIGNED_BYTE, | 174 GL_UNSIGNED_BYTE, |
172 image_data_[imgID].get()); | 175 image_data_[imgID].get()); |
173 } | 176 } |
174 | 177 |
OLD | NEW |