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

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_transformer_mac_unittest.cc

Issue 13749002: Cache OpenGL textures and other objects in CompositingIOSurfaceMac copy/transform code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks, per nick@'s comments. Created 7 years, 8 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 | « content/browser/renderer_host/compositing_iosurface_transformer_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/browser/renderer_host/compositing_iosurface_transformer_mac.h" 5 #include "content/browser/renderer_host/compositing_iosurface_transformer_mac.h"
6 6
7 #include <OpenGL/CGLCurrent.h> 7 #include <OpenGL/CGLCurrent.h>
8 #include <OpenGL/CGLRenderers.h> 8 #include <OpenGL/CGLRenderers.h>
9 #include <OpenGL/CGLTypes.h> 9 #include <OpenGL/CGLTypes.h>
10 #include <OpenGL/OpenGL.h> 10 #include <OpenGL/OpenGL.h>
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // unit tests, once it's established that the trybots and buildbots behave 273 // unit tests, once it's established that the trybots and buildbots behave
274 // well when using the GPU. 274 // well when using the GPU.
275 CHECK(InitializeGLContext(&context_, RESTRICTION_SOFTWARE_ONLY)); 275 CHECK(InitializeGLContext(&context_, RESTRICTION_SOFTWARE_ONLY));
276 CGLSetCurrentContext(context_); 276 CGLSetCurrentContext(context_);
277 shader_program_cache_.reset(new CompositingIOSurfaceShaderPrograms()); 277 shader_program_cache_.reset(new CompositingIOSurfaceShaderPrograms());
278 transformer_.reset(new CompositingIOSurfaceTransformer( 278 transformer_.reset(new CompositingIOSurfaceTransformer(
279 kGLTextureTarget, false, shader_program_cache_.get())); 279 kGLTextureTarget, false, shader_program_cache_.get()));
280 } 280 }
281 281
282 virtual ~CompositingIOSurfaceTransformerTest() { 282 virtual ~CompositingIOSurfaceTransformerTest() {
283 transformer_->ReleaseCachedGLObjects();
283 shader_program_cache_->Reset(); 284 shader_program_cache_->Reset();
284 CGLSetCurrentContext(NULL); 285 CGLSetCurrentContext(NULL);
285 CGLDestroyContext(context_); 286 CGLDestroyContext(context_);
286 } 287 }
287 288
288 protected: 289 protected:
289 void RunResizeTest(const SkBitmap& src_bitmap, const gfx::Rect& src_rect, 290 void RunResizeTest(const SkBitmap& src_bitmap, const gfx::Rect& src_rect,
290 const gfx::Size& dst_size) { 291 const gfx::Size& dst_size) {
291 SCOPED_TRACE(::testing::Message() 292 SCOPED_TRACE(::testing::Message()
292 << "src_rect=" << src_rect.x() << ',' << src_rect.y() 293 << "src_rect=(" << src_rect.x() << ',' << src_rect.y()
293 << ")x[" << src_rect.width() << 'x' << src_rect.height() 294 << ")x[" << src_rect.width() << 'x' << src_rect.height()
294 << "]; dst_size=[" << dst_size.width() << 'x' 295 << "]; dst_size=[" << dst_size.width() << 'x'
295 << dst_size.height() << ']'); 296 << dst_size.height() << ']');
296 297
298 // Do the scale operation on the GPU.
297 const GLuint original_texture = CreateTextureWithImage(src_bitmap); 299 const GLuint original_texture = CreateTextureWithImage(src_bitmap);
298 EXPECT_NE(0u, original_texture); 300 ASSERT_NE(0u, original_texture);
299
300 // Do the scale operation on the GPU.
301 GLuint scaled_texture = 0u; 301 GLuint scaled_texture = 0u;
302 EXPECT_TRUE(transformer_->ResizeBilinear( 302 ASSERT_TRUE(transformer_->ResizeBilinear(
303 original_texture, src_rect, dst_size, &scaled_texture)); 303 original_texture, src_rect, dst_size, &scaled_texture));
304 EXPECT_NE(0u, scaled_texture); 304 EXPECT_NE(0u, scaled_texture);
305 CGLFlushDrawable(context_); // Account for some buggy driver impls. 305 CGLFlushDrawable(context_); // Account for some buggy driver impls.
306 const SkBitmap result_bitmap = ReadBackTexture(scaled_texture, dst_size); 306 const SkBitmap result_bitmap = ReadBackTexture(scaled_texture, dst_size);
307
308 // Delete the textures.
309 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &original_texture)); 307 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &original_texture));
310 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &scaled_texture));
311 308
312 // Compare the image read back to the version produced by a known-working 309 // Compare the image read back to the version produced by a known-working
313 // software implementation. Allow up to 2 lines of mismatch due to how 310 // software implementation. Allow up to 2 lines of mismatch due to how
314 // implementations disagree on resolving the processing of edges. 311 // implementations disagree on resolving the processing of edges.
315 const SkBitmap expected_bitmap = 312 const SkBitmap expected_bitmap =
316 ScaleBitmapWithSkia(src_bitmap, src_rect, dst_size); 313 ScaleBitmapWithSkia(src_bitmap, src_rect, dst_size);
317 EXPECT_GE(std::max(expected_bitmap.width(), expected_bitmap.height()) * 2, 314 EXPECT_GE(std::max(expected_bitmap.width(), expected_bitmap.height()) * 2,
318 ImageDifference(expected_bitmap, result_bitmap)); 315 ImageDifference(expected_bitmap, result_bitmap));
319 } 316 }
320 317
321 void RunTransformRGBToYV12Test( 318 void RunTransformRGBToYV12Test(
322 const SkBitmap& src_bitmap, const gfx::Rect& src_rect, 319 const SkBitmap& src_bitmap, const gfx::Rect& src_rect,
323 const gfx::Size& dst_size) { 320 const gfx::Size& dst_size) {
324 SCOPED_TRACE(::testing::Message() 321 SCOPED_TRACE(::testing::Message()
325 << "src_rect=" << src_rect.x() << ',' << src_rect.y() 322 << "src_rect=(" << src_rect.x() << ',' << src_rect.y()
326 << ")x[" << src_rect.width() << 'x' << src_rect.height() 323 << ")x[" << src_rect.width() << 'x' << src_rect.height()
327 << "]; dst_size=[" << dst_size.width() << 'x' 324 << "]; dst_size=[" << dst_size.width() << 'x'
328 << dst_size.height() << ']'); 325 << dst_size.height() << ']');
329 326
327 // Perform the RGB to YV12 conversion.
330 const GLuint original_texture = CreateTextureWithImage(src_bitmap); 328 const GLuint original_texture = CreateTextureWithImage(src_bitmap);
331 EXPECT_NE(0u, original_texture); 329 ASSERT_NE(0u, original_texture);
332
333 // Perform the RGB to YV12 conversion.
334 GLuint texture_y = 0u; 330 GLuint texture_y = 0u;
335 GLuint texture_u = 0u; 331 GLuint texture_u = 0u;
336 GLuint texture_v = 0u; 332 GLuint texture_v = 0u;
337 gfx::Size packed_y_size; 333 gfx::Size packed_y_size;
338 gfx::Size packed_uv_size; 334 gfx::Size packed_uv_size;
339 EXPECT_TRUE(transformer_->TransformRGBToYV12( 335 ASSERT_TRUE(transformer_->TransformRGBToYV12(
340 original_texture, src_rect, dst_size, 336 original_texture, src_rect, dst_size,
341 &texture_y, &texture_u, &texture_v, &packed_y_size, &packed_uv_size)); 337 &texture_y, &texture_u, &texture_v, &packed_y_size, &packed_uv_size));
342 EXPECT_NE(0u, texture_y); 338 EXPECT_NE(0u, texture_y);
343 EXPECT_NE(0u, texture_u); 339 EXPECT_NE(0u, texture_u);
344 EXPECT_NE(0u, texture_v); 340 EXPECT_NE(0u, texture_v);
345 EXPECT_FALSE(packed_y_size.IsEmpty()); 341 EXPECT_FALSE(packed_y_size.IsEmpty());
346 EXPECT_FALSE(packed_uv_size.IsEmpty()); 342 EXPECT_FALSE(packed_uv_size.IsEmpty());
343 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &original_texture));
347 344
348 // Read-back the texture for each plane. 345 // Read-back the texture for each plane.
349 CGLFlushDrawable(context_); // Account for some buggy driver impls. 346 CGLFlushDrawable(context_); // Account for some buggy driver impls.
350 const SkBitmap result_y_bitmap = ReadBackTexture(texture_y, packed_y_size); 347 const SkBitmap result_y_bitmap = ReadBackTexture(texture_y, packed_y_size);
351 const SkBitmap result_u_bitmap = ReadBackTexture(texture_u, packed_uv_size); 348 const SkBitmap result_u_bitmap = ReadBackTexture(texture_u, packed_uv_size);
352 const SkBitmap result_v_bitmap = ReadBackTexture(texture_v, packed_uv_size); 349 const SkBitmap result_v_bitmap = ReadBackTexture(texture_v, packed_uv_size);
353 350
354 // Delete the textures.
355 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &original_texture));
356 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &texture_y));
357 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &texture_u));
358 EXPECT_NO_GL_ERROR(glDeleteTextures(1, &texture_v));
359
360 // Compare the Y, U, and V planes read-back to the version produced by a 351 // Compare the Y, U, and V planes read-back to the version produced by a
361 // known-working software implementation. Allow up to 2 lines of mismatch 352 // known-working software implementation. Allow up to 2 lines of mismatch
362 // due to how implementations disagree on resolving the processing of edges. 353 // due to how implementations disagree on resolving the processing of edges.
363 const SkBitmap expected_bitmap = 354 const SkBitmap expected_bitmap =
364 ScaleBitmapWithSkia(src_bitmap, src_rect, dst_size); 355 ScaleBitmapWithSkia(src_bitmap, src_rect, dst_size);
365 const gfx::Size dst_uv_size( 356 const gfx::Size dst_uv_size(
366 (dst_size.width() + 1) / 2, (dst_size.height() + 1) / 2); 357 (dst_size.width() + 1) / 2, (dst_size.height() + 1) / 2);
367 scoped_ptr<uint8[]> expected_y_plane( 358 scoped_ptr<uint8[]> expected_y_plane(
368 new uint8[dst_size.width() * dst_size.height()]); 359 new uint8[dst_size.width() * dst_size.height()]);
369 scoped_ptr<uint8[]> expected_u_plane( 360 scoped_ptr<uint8[]> expected_u_plane(
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 dst_size); 511 dst_size);
521 // Subrect resize test: missing top row, and left+right columns in source. 512 // Subrect resize test: missing top row, and left+right columns in source.
522 RunTransformRGBToYV12Test( 513 RunTransformRGBToYV12Test(
523 src_bitmap, 514 src_bitmap,
524 gfx::Rect(1, 1, params.src_width - 2, params.src_height - 1), 515 gfx::Rect(1, 1, params.src_width - 2, params.src_height - 1),
525 dst_size); 516 dst_size);
526 } 517 }
527 } 518 }
528 519
529 } // namespace content 520 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/compositing_iosurface_transformer_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698