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

Side by Side Diff: cc/texture_uploader.cc

Issue 11266030: Use gfx:: Geometry types for the resource provider and layer updater classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: uint8 Created 8 years, 1 month 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/texture_uploader.h ('k') | cc/texture_uploader_unittest.cc » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/texture_uploader.h" 7 #include "cc/texture_uploader.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "cc/texture.h" 15 #include "cc/texture.h"
16 #include "cc/prioritized_texture.h" 16 #include "cc/prioritized_texture.h"
17 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
18 #include "third_party/khronos/GLES2/gl2ext.h" 18 #include "third_party/khronos/GLES2/gl2ext.h"
19 #include "ui/gfx/rect.h"
20 #include "ui/gfx/vector2d.h"
19 #include <public/WebGraphicsContext3D.h> 21 #include <public/WebGraphicsContext3D.h>
20 22
21 namespace { 23 namespace {
22 24
23 // How many previous uploads to use when predicting future throughput. 25 // How many previous uploads to use when predicting future throughput.
24 static const size_t uploadHistorySizeMax = 1000; 26 static const size_t uploadHistorySizeMax = 1000;
25 static const size_t uploadHistorySizeInitial = 100; 27 static const size_t uploadHistorySizeInitial = 100;
26 28
27 // Global estimated number of textures per second to maintain estimates across 29 // Global estimated number of textures per second to maintain estimates across
28 // subsequent instances of TextureUploader. 30 // subsequent instances of TextureUploader.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 m_availableQueries.first()->begin(); 142 m_availableQueries.first()->begin();
141 } 143 }
142 144
143 void TextureUploader::endQuery() 145 void TextureUploader::endQuery()
144 { 146 {
145 m_availableQueries.first()->end(); 147 m_availableQueries.first()->end();
146 m_pendingQueries.append(m_availableQueries.takeFirst()); 148 m_pendingQueries.append(m_availableQueries.takeFirst());
147 m_numBlockingTextureUploads++; 149 m_numBlockingTextureUploads++;
148 } 150 }
149 151
150 void TextureUploader::upload(const uint8_t* image, 152 void TextureUploader::upload(const uint8* image,
151 const IntRect& image_rect, 153 const gfx::Rect& image_rect,
152 const IntRect& source_rect, 154 const gfx::Rect& source_rect,
153 const IntSize& dest_offset, 155 const gfx::Vector2d& dest_offset,
154 GLenum format, 156 GLenum format,
155 IntSize size) 157 const gfx::Size& size)
156 { 158 {
157 CHECK(image_rect.contains(source_rect)); 159 CHECK(image_rect.Contains(source_rect));
158 160
159 bool isFullUpload = dest_offset.isZero() && source_rect.size() == size; 161 bool isFullUpload = dest_offset.IsZero() && source_rect.size() == size;
160 162
161 if (isFullUpload) 163 if (isFullUpload)
162 beginQuery(); 164 beginQuery();
163 165
164 if (m_useMapTexSubImage) { 166 if (m_useMapTexSubImage) {
165 uploadWithMapTexSubImage( 167 uploadWithMapTexSubImage(
166 image, image_rect, source_rect, dest_offset, format); 168 image, image_rect, source_rect, dest_offset, format);
167 } else { 169 } else {
168 uploadWithTexSubImage( 170 uploadWithTexSubImage(
169 image, image_rect, source_rect, dest_offset, format); 171 image, image_rect, source_rect, dest_offset, format);
170 } 172 }
171 173
172 if (isFullUpload) 174 if (isFullUpload)
173 endQuery(); 175 endQuery();
174 } 176 }
175 177
176 void TextureUploader::uploadWithTexSubImage(const uint8_t* image, 178 void TextureUploader::uploadWithTexSubImage(const uint8* image,
177 const IntRect& image_rect, 179 const gfx::Rect& image_rect,
178 const IntRect& source_rect, 180 const gfx::Rect& source_rect,
179 const IntSize& dest_offset, 181 const gfx::Vector2d& dest_offset,
180 GLenum format) 182 GLenum format)
181 { 183 {
182 // Instrumentation to debug issue 156107 184 // Instrumentation to debug issue 156107
183 int source_rect_x = source_rect.x(); 185 int source_rect_x = source_rect.x();
184 int source_rect_y = source_rect.y(); 186 int source_rect_y = source_rect.y();
185 int source_rect_width = source_rect.width(); 187 int source_rect_width = source_rect.width();
186 int source_rect_height = source_rect.height(); 188 int source_rect_height = source_rect.height();
187 int image_rect_x = image_rect.x(); 189 int image_rect_x = image_rect.x();
188 int image_rect_y = image_rect.y(); 190 int image_rect_y = image_rect.y();
189 int image_rect_width = image_rect.width(); 191 int image_rect_width = image_rect.width();
190 int image_rect_height = image_rect.height(); 192 int image_rect_height = image_rect.height();
191 int dest_offset_width = dest_offset.width(); 193 int dest_offset_x = dest_offset.x();
192 int dest_offset_height = dest_offset.height(); 194 int dest_offset_y = dest_offset.y();
193 base::debug::Alias(&image); 195 base::debug::Alias(&image);
194 base::debug::Alias(&source_rect_x); 196 base::debug::Alias(&source_rect_x);
195 base::debug::Alias(&source_rect_y); 197 base::debug::Alias(&source_rect_y);
196 base::debug::Alias(&source_rect_width); 198 base::debug::Alias(&source_rect_width);
197 base::debug::Alias(&source_rect_height); 199 base::debug::Alias(&source_rect_height);
198 base::debug::Alias(&image_rect_x); 200 base::debug::Alias(&image_rect_x);
199 base::debug::Alias(&image_rect_y); 201 base::debug::Alias(&image_rect_y);
200 base::debug::Alias(&image_rect_width); 202 base::debug::Alias(&image_rect_width);
201 base::debug::Alias(&image_rect_height); 203 base::debug::Alias(&image_rect_height);
202 base::debug::Alias(&dest_offset_width); 204 base::debug::Alias(&dest_offset_x);
203 base::debug::Alias(&dest_offset_height); 205 base::debug::Alias(&dest_offset_y);
204 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage"); 206 TRACE_EVENT0("cc", "TextureUploader::uploadWithTexSubImage");
205 207
206 // Offset from image-rect to source-rect. 208 // Offset from image-rect to source-rect.
207 IntPoint offset(source_rect.x() - image_rect.x(), 209 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
208 source_rect.y() - image_rect.y());
209 210
210 const uint8_t* pixel_source; 211 const uint8* pixel_source;
211 unsigned int bytes_per_pixel = Texture::bytesPerPixel(format); 212 unsigned int bytes_per_pixel = Texture::bytesPerPixel(format);
212 213
213 if (image_rect.width() == source_rect.width() && !offset.x()) { 214 if (image_rect.width() == source_rect.width() && !offset.x()) {
214 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ; 215 pixel_source = &image[bytes_per_pixel * offset.y() * image_rect.width()] ;
215 } else { 216 } else {
216 size_t needed_size = source_rect.width() * source_rect.height() * bytes_ per_pixel; 217 size_t needed_size = source_rect.width() * source_rect.height() * bytes_ per_pixel;
217 if (m_subImageSize < needed_size) { 218 if (m_subImageSize < needed_size) {
218 m_subImage.reset(new uint8_t[needed_size]); 219 m_subImage.reset(new uint8[needed_size]);
219 m_subImageSize = needed_size; 220 m_subImageSize = needed_size;
220 } 221 }
221 // Strides not equal, so do a row-by-row memcpy from the 222 // Strides not equal, so do a row-by-row memcpy from the
222 // paint results into a temp buffer for uploading. 223 // paint results into a temp buffer for uploading.
223 for (int row = 0; row < source_rect.height(); ++row) 224 for (int row = 0; row < source_rect.height(); ++row)
224 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row], 225 memcpy(&m_subImage[source_rect.width() * bytes_per_pixel * row],
225 &image[bytes_per_pixel * (offset.x() + 226 &image[bytes_per_pixel * (offset.x() +
226 (offset.y() + row) * image_rect.width())], 227 (offset.y() + row) * image_rect.width())],
227 source_rect.width() * bytes_per_pixel); 228 source_rect.width() * bytes_per_pixel);
228 229
229 pixel_source = &m_subImage[0]; 230 pixel_source = &m_subImage[0];
230 } 231 }
231 232
232 m_context->texSubImage2D(GL_TEXTURE_2D, 233 m_context->texSubImage2D(GL_TEXTURE_2D,
233 0, 234 0,
234 dest_offset.width(), 235 dest_offset.x(),
235 dest_offset.height(), 236 dest_offset.y(),
236 source_rect.width(), 237 source_rect.width(),
237 source_rect.height(), 238 source_rect.height(),
238 format, 239 format,
239 GL_UNSIGNED_BYTE, 240 GL_UNSIGNED_BYTE,
240 pixel_source); 241 pixel_source);
241 } 242 }
242 243
243 void TextureUploader::uploadWithMapTexSubImage(const uint8_t* image, 244 void TextureUploader::uploadWithMapTexSubImage(const uint8* image,
244 const IntRect& image_rect, 245 const gfx::Rect& image_rect,
245 const IntRect& source_rect, 246 const gfx::Rect& source_rect,
246 const IntSize& dest_offset, 247 const gfx::Vector2d& dest_offset,
247 GLenum format) 248 GLenum format)
248 { 249 {
249 // Instrumentation to debug issue 156107 250 // Instrumentation to debug issue 156107
250 int source_rect_x = source_rect.x(); 251 int source_rect_x = source_rect.x();
251 int source_rect_y = source_rect.y(); 252 int source_rect_y = source_rect.y();
252 int source_rect_width = source_rect.width(); 253 int source_rect_width = source_rect.width();
253 int source_rect_height = source_rect.height(); 254 int source_rect_height = source_rect.height();
254 int image_rect_x = image_rect.x(); 255 int image_rect_x = image_rect.x();
255 int image_rect_y = image_rect.y(); 256 int image_rect_y = image_rect.y();
256 int image_rect_width = image_rect.width(); 257 int image_rect_width = image_rect.width();
257 int image_rect_height = image_rect.height(); 258 int image_rect_height = image_rect.height();
258 int dest_offset_width = dest_offset.width(); 259 int dest_offset_x = dest_offset.x();
259 int dest_offset_height = dest_offset.height(); 260 int dest_offset_y = dest_offset.y();
260 base::debug::Alias(&image); 261 base::debug::Alias(&image);
261 base::debug::Alias(&source_rect_x); 262 base::debug::Alias(&source_rect_x);
262 base::debug::Alias(&source_rect_y); 263 base::debug::Alias(&source_rect_y);
263 base::debug::Alias(&source_rect_width); 264 base::debug::Alias(&source_rect_width);
264 base::debug::Alias(&source_rect_height); 265 base::debug::Alias(&source_rect_height);
265 base::debug::Alias(&image_rect_x); 266 base::debug::Alias(&image_rect_x);
266 base::debug::Alias(&image_rect_y); 267 base::debug::Alias(&image_rect_y);
267 base::debug::Alias(&image_rect_width); 268 base::debug::Alias(&image_rect_width);
268 base::debug::Alias(&image_rect_height); 269 base::debug::Alias(&image_rect_height);
269 base::debug::Alias(&dest_offset_width); 270 base::debug::Alias(&dest_offset_x);
270 base::debug::Alias(&dest_offset_height); 271 base::debug::Alias(&dest_offset_y);
271 272
272 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage"); 273 TRACE_EVENT0("cc", "TextureUploader::uploadWithMapTexSubImage");
273 274
274 // Offset from image-rect to source-rect. 275 // Offset from image-rect to source-rect.
275 IntPoint offset(source_rect.x() - image_rect.x(), 276 gfx::Vector2d offset(source_rect.origin() - image_rect.origin());
276 source_rect.y() - image_rect.y());
277 277
278 // Upload tile data via a mapped transfer buffer 278 // Upload tile data via a mapped transfer buffer
279 uint8_t* pixel_dest = static_cast<uint8_t*>( 279 uint8* pixel_dest = static_cast<uint8*>(
280 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 280 m_context->mapTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
281 0, 281 0,
282 dest_offset.width(), 282 dest_offset.x(),
283 dest_offset.height(), 283 dest_offset.y(),
284 source_rect.width(), 284 source_rect.width(),
285 source_rect.height(), 285 source_rect.height(),
286 format, 286 format,
287 GL_UNSIGNED_BYTE, 287 GL_UNSIGNED_BYTE,
288 GL_WRITE_ONLY)); 288 GL_WRITE_ONLY));
289 289
290 if (!pixel_dest) { 290 if (!pixel_dest) {
291 uploadWithTexSubImage( 291 uploadWithTexSubImage(
292 image, image_rect, source_rect, dest_offset, format); 292 image, image_rect, source_rect, dest_offset, format);
293 return; 293 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ; 330 m_texturesPerSecondHistory.erase(m_texturesPerSecondHistory.begin()) ;
331 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ; 331 m_texturesPerSecondHistory.erase(--m_texturesPerSecondHistory.end()) ;
332 } 332 }
333 m_texturesPerSecondHistory.insert(texturesPerSecond); 333 m_texturesPerSecondHistory.insert(texturesPerSecond);
334 334
335 m_availableQueries.append(m_pendingQueries.takeFirst()); 335 m_availableQueries.append(m_pendingQueries.takeFirst());
336 } 336 }
337 } 337 }
338 338
339 } 339 }
OLDNEW
« no previous file with comments | « cc/texture_uploader.h ('k') | cc/texture_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698