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

Side by Side Diff: cc/resources/resource_provider_unittest.cc

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code reviews Created 7 years, 3 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
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 "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 22 matching lines...) Expand all
33 using WebKit::WGC3Dbyte; 33 using WebKit::WGC3Dbyte;
34 using WebKit::WGC3Denum; 34 using WebKit::WGC3Denum;
35 using WebKit::WGC3Dint; 35 using WebKit::WGC3Dint;
36 using WebKit::WGC3Dsizei; 36 using WebKit::WGC3Dsizei;
37 using WebKit::WGC3Duint; 37 using WebKit::WGC3Duint;
38 using WebKit::WebGLId; 38 using WebKit::WebGLId;
39 39
40 namespace cc { 40 namespace cc {
41 namespace { 41 namespace {
42 42
43 size_t TextureSize(gfx::Size size, WGC3Denum format) { 43 size_t TextureSize(gfx::Size size, ResourceProvider::Format format) {
44 unsigned int components_per_pixel = 4; 44 unsigned int components_per_pixel = 4;
45 unsigned int bytes_per_component = 1; 45 unsigned int bytes_per_component = 1;
46 return size.width() * size.height() * components_per_pixel * 46 return size.width() * size.height() * components_per_pixel *
47 bytes_per_component; 47 bytes_per_component;
48 } 48 }
49 49
50 struct Texture : public base::RefCounted<Texture> { 50 struct Texture : public base::RefCounted<Texture> {
51 Texture() : format(0), filter(GL_NEAREST_MIPMAP_LINEAR) {} 51 Texture() : format(ResourceProvider::RGBA_8888),
52 filter(GL_NEAREST_MIPMAP_LINEAR) {}
52 53
53 void Reallocate(gfx::Size size, WGC3Denum format) { 54 void Reallocate(gfx::Size size, ResourceProvider::Format format) {
54 this->size = size; 55 this->size = size;
55 this->format = format; 56 this->format = format;
56 this->data.reset(new uint8_t[TextureSize(size, format)]); 57 this->data.reset(new uint8_t[TextureSize(size, format)]);
57 } 58 }
58 59
59 gfx::Size size; 60 gfx::Size size;
60 WGC3Denum format; 61 ResourceProvider::Format format;
61 WGC3Denum filter; 62 WGC3Denum filter;
62 scoped_ptr<uint8_t[]> data; 63 scoped_ptr<uint8_t[]> data;
63 64
64 private: 65 private:
65 friend class base::RefCounted<Texture>; 66 friend class base::RefCounted<Texture>;
66 ~Texture() {} 67 ~Texture() {}
67 }; 68 };
68 69
69 // Shared data between multiple ResourceProviderContext. This contains mailbox 70 // Shared data between multiple ResourceProviderContext. This contains mailbox
70 // contents as well as information about sync points. 71 // contents as well as information about sync points.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 WGC3Dint yoffset, 214 WGC3Dint yoffset,
214 WGC3Dsizei width, 215 WGC3Dsizei width,
215 WGC3Dsizei height, 216 WGC3Dsizei height,
216 WGC3Denum format, 217 WGC3Denum format,
217 WGC3Denum type, 218 WGC3Denum type,
218 const void* pixels) OVERRIDE { 219 const void* pixels) OVERRIDE {
219 ASSERT_TRUE(current_texture_); 220 ASSERT_TRUE(current_texture_);
220 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 221 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
221 ASSERT_FALSE(level); 222 ASSERT_FALSE(level);
222 ASSERT_TRUE(textures_[current_texture_].get()); 223 ASSERT_TRUE(textures_[current_texture_].get());
223 ASSERT_EQ(textures_[current_texture_]->format, format); 224 ASSERT_EQ(
225 ResourceProvider::GetGLDataFormat(textures_[current_texture_]->format),
226 format);
224 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); 227 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type);
225 ASSERT_TRUE(pixels); 228 ASSERT_TRUE(pixels);
226 SetPixels(xoffset, yoffset, width, height, pixels); 229 SetPixels(xoffset, yoffset, width, height, pixels);
227 } 230 }
228 231
229 virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value) 232 virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value)
230 OVERRIDE { 233 OVERRIDE {
231 ASSERT_TRUE(current_texture_); 234 ASSERT_TRUE(current_texture_);
232 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 235 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
233 scoped_refptr<Texture> texture = textures_[current_texture_]; 236 scoped_refptr<Texture> texture = textures_[current_texture_];
(...skipping 22 matching lines...) Expand all
256 } 259 }
257 260
258 virtual void consumeTextureCHROMIUM(WGC3Denum target, 261 virtual void consumeTextureCHROMIUM(WGC3Denum target,
259 const WGC3Dbyte* mailbox) OVERRIDE { 262 const WGC3Dbyte* mailbox) OVERRIDE {
260 ASSERT_TRUE(current_texture_); 263 ASSERT_TRUE(current_texture_);
261 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 264 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
262 textures_[current_texture_] = shared_data_->ConsumeTexture( 265 textures_[current_texture_] = shared_data_->ConsumeTexture(
263 mailbox, last_waited_sync_point_); 266 mailbox, last_waited_sync_point_);
264 } 267 }
265 268
266 void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) { 269 void GetPixels(
270 gfx::Size size, ResourceProvider::Format format, uint8_t* pixels) {
267 ASSERT_TRUE(current_texture_); 271 ASSERT_TRUE(current_texture_);
268 scoped_refptr<Texture> texture = textures_[current_texture_]; 272 scoped_refptr<Texture> texture = textures_[current_texture_];
269 ASSERT_TRUE(texture.get()); 273 ASSERT_TRUE(texture.get());
270 ASSERT_EQ(texture->size, size); 274 ASSERT_EQ(texture->size, size);
271 ASSERT_EQ(texture->format, format); 275 ASSERT_EQ(texture->format, format);
272 memcpy(pixels, texture->data.get(), TextureSize(size, format)); 276 memcpy(pixels, texture->data.get(), TextureSize(size, format));
273 } 277 }
274 278
275 WGC3Denum GetTextureFilter() { 279 WGC3Denum GetTextureFilter() {
276 DCHECK(current_texture_); 280 DCHECK(current_texture_);
(...skipping 10 matching lines...) Expand all
287 : TestWebGraphicsContext3D(attrs), 291 : TestWebGraphicsContext3D(attrs),
288 shared_data_(shared_data), 292 shared_data_(shared_data),
289 current_texture_(0), 293 current_texture_(0),
290 last_waited_sync_point_(0) {} 294 last_waited_sync_point_(0) {}
291 295
292 private: 296 private:
293 void AllocateTexture(gfx::Size size, WGC3Denum format) { 297 void AllocateTexture(gfx::Size size, WGC3Denum format) {
294 ASSERT_TRUE(current_texture_); 298 ASSERT_TRUE(current_texture_);
295 scoped_refptr<Texture> texture = textures_[current_texture_]; 299 scoped_refptr<Texture> texture = textures_[current_texture_];
296 ASSERT_TRUE(texture.get()); 300 ASSERT_TRUE(texture.get());
297 texture->Reallocate(size, format); 301 ResourceProvider::Format texture_format = ResourceProvider::RGBA_8888;
302 switch (format) {
303 case GL_RGBA:
304 texture_format = ResourceProvider::RGBA_8888;
305 break;
306 case GL_BGRA_EXT:
307 texture_format = ResourceProvider::BGRA_8888;
308 break;
309 }
310 texture->Reallocate(size, texture_format);
298 } 311 }
299 312
300 void SetPixels(int xoffset, 313 void SetPixels(int xoffset,
301 int yoffset, 314 int yoffset,
302 int width, 315 int width,
303 int height, 316 int height,
304 const void* pixels) { 317 const void* pixels) {
305 ASSERT_TRUE(current_texture_); 318 ASSERT_TRUE(current_texture_);
306 scoped_refptr<Texture> texture = textures_[current_texture_]; 319 scoped_refptr<Texture> texture = textures_[current_texture_];
307 ASSERT_TRUE(texture.get()); 320 ASSERT_TRUE(texture.get());
(...skipping 24 matching lines...) Expand all
332 WebGLId current_texture_; 345 WebGLId current_texture_;
333 TextureMap textures_; 346 TextureMap textures_;
334 unsigned last_waited_sync_point_; 347 unsigned last_waited_sync_point_;
335 PendingProduceTextureList pending_produce_textures_; 348 PendingProduceTextureList pending_produce_textures_;
336 }; 349 };
337 350
338 void GetResourcePixels(ResourceProvider* resource_provider, 351 void GetResourcePixels(ResourceProvider* resource_provider,
339 ResourceProviderContext* context, 352 ResourceProviderContext* context,
340 ResourceProvider::ResourceId id, 353 ResourceProvider::ResourceId id,
341 gfx::Size size, 354 gfx::Size size,
342 WGC3Denum format, 355 ResourceProvider::Format format,
343 uint8_t* pixels) { 356 uint8_t* pixels) {
344 switch (resource_provider->default_resource_type()) { 357 switch (resource_provider->default_resource_type()) {
345 case ResourceProvider::GLTexture: { 358 case ResourceProvider::GLTexture: {
346 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); 359 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id);
347 ASSERT_NE(0U, lock_gl.texture_id()); 360 ASSERT_NE(0U, lock_gl.texture_id());
348 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); 361 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id());
349 context->GetPixels(size, format, pixels); 362 context->GetPixels(size, format, pixels);
350 break; 363 break;
351 } 364 }
352 case ResourceProvider::Bitmap: { 365 case ResourceProvider::Bitmap: {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 scoped_ptr<OutputSurface> output_surface_; 433 scoped_ptr<OutputSurface> output_surface_;
421 scoped_ptr<ResourceProvider> resource_provider_; 434 scoped_ptr<ResourceProvider> resource_provider_;
422 }; 435 };
423 436
424 void CheckCreateResource(ResourceProvider::ResourceType expected_default_type, 437 void CheckCreateResource(ResourceProvider::ResourceType expected_default_type,
425 ResourceProvider* resource_provider, 438 ResourceProvider* resource_provider,
426 ResourceProviderContext* context) { 439 ResourceProviderContext* context) {
427 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); 440 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type());
428 441
429 gfx::Size size(1, 1); 442 gfx::Size size(1, 1);
430 WGC3Denum format = GL_RGBA; 443 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
431 size_t pixel_size = TextureSize(size, format); 444 size_t pixel_size = TextureSize(size, format);
432 ASSERT_EQ(4U, pixel_size); 445 ASSERT_EQ(4U, pixel_size);
433 446
434 ResourceProvider::ResourceId id = resource_provider->CreateResource( 447 ResourceProvider::ResourceId id = resource_provider->CreateResource(
435 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 448 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
436 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); 449 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources()));
437 if (expected_default_type == ResourceProvider::GLTexture) 450 if (expected_default_type == ResourceProvider::GLTexture)
438 EXPECT_EQ(0, context->texture_count()); 451 EXPECT_EQ(0, context->texture_count());
439 452
440 uint8_t data[4] = { 1, 2, 3, 4 }; 453 uint8_t data[4] = { 1, 2, 3, 4 };
441 gfx::Rect rect(size); 454 gfx::Rect rect(size);
442 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); 455 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
443 if (expected_default_type == ResourceProvider::GLTexture) 456 if (expected_default_type == ResourceProvider::GLTexture)
444 EXPECT_EQ(1, context->texture_count()); 457 EXPECT_EQ(1, context->texture_count());
445 458
446 uint8_t result[4] = { 0 }; 459 uint8_t result[4] = { 0 };
447 GetResourcePixels(resource_provider, context, id, size, format, result); 460 GetResourcePixels(resource_provider, context, id, size, format, result);
448 EXPECT_EQ(0, memcmp(data, result, pixel_size)); 461 EXPECT_EQ(0, memcmp(data, result, pixel_size));
449 462
450 resource_provider->DeleteResource(id); 463 resource_provider->DeleteResource(id);
451 EXPECT_EQ(0, static_cast<int>(resource_provider->num_resources())); 464 EXPECT_EQ(0, static_cast<int>(resource_provider->num_resources()));
452 if (expected_default_type == ResourceProvider::GLTexture) 465 if (expected_default_type == ResourceProvider::GLTexture)
453 EXPECT_EQ(0, context->texture_count()); 466 EXPECT_EQ(0, context->texture_count());
454 } 467 }
455 468
456 TEST_P(ResourceProviderTest, Basic) { 469 TEST_P(ResourceProviderTest, Basic) {
457 CheckCreateResource(GetParam(), resource_provider_.get(), context()); 470 CheckCreateResource(GetParam(), resource_provider_.get(), context());
458 } 471 }
459 472
460 TEST_P(ResourceProviderTest, Upload) { 473 TEST_P(ResourceProviderTest, Upload) {
461 gfx::Size size(2, 2); 474 gfx::Size size(2, 2);
462 WGC3Denum format = GL_RGBA; 475 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
463 size_t pixel_size = TextureSize(size, format); 476 size_t pixel_size = TextureSize(size, format);
464 ASSERT_EQ(16U, pixel_size); 477 ASSERT_EQ(16U, pixel_size);
465 478
466 ResourceProvider::ResourceId id = resource_provider_->CreateResource( 479 ResourceProvider::ResourceId id = resource_provider_->CreateResource(
467 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 480 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
468 481
469 uint8_t image[16] = { 0 }; 482 uint8_t image[16] = { 0 };
470 gfx::Rect image_rect(size); 483 gfx::Rect image_rect(size);
471 resource_provider_->SetPixels( 484 resource_provider_->SetPixels(
472 id, image, image_rect, image_rect, gfx::Vector2d()); 485 id, image, image_rect, image_rect, gfx::Vector2d());
473 486
474 for (uint8_t i = 0; i < pixel_size; ++i) 487 for (uint8_t i = 0; i < pixel_size; ++i)
475 image[i] = i; 488 image[i] = i;
476 489
477 uint8_t result[16] = { 0 }; 490 uint8_t result[16] = { 0 };
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 FakeOutputSurfaceClient child_output_surface_client; 549 FakeOutputSurfaceClient child_output_surface_client;
537 scoped_ptr<OutputSurface> child_output_surface( 550 scoped_ptr<OutputSurface> child_output_surface(
538 FakeOutputSurface::Create3d( 551 FakeOutputSurface::Create3d(
539 child_context_owned.PassAs<TestWebGraphicsContext3D>())); 552 child_context_owned.PassAs<TestWebGraphicsContext3D>()));
540 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); 553 CHECK(child_output_surface->BindToClient(&child_output_surface_client));
541 554
542 scoped_ptr<ResourceProvider> child_resource_provider( 555 scoped_ptr<ResourceProvider> child_resource_provider(
543 ResourceProvider::Create(child_output_surface.get(), 0)); 556 ResourceProvider::Create(child_output_surface.get(), 0));
544 557
545 gfx::Size size(1, 1); 558 gfx::Size size(1, 1);
546 WGC3Denum format = GL_RGBA; 559 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
547 size_t pixel_size = TextureSize(size, format); 560 size_t pixel_size = TextureSize(size, format);
548 ASSERT_EQ(4U, pixel_size); 561 ASSERT_EQ(4U, pixel_size);
549 562
550 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( 563 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource(
551 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 564 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
552 uint8_t data1[4] = { 1, 2, 3, 4 }; 565 uint8_t data1[4] = { 1, 2, 3, 4 };
553 gfx::Rect rect(size); 566 gfx::Rect rect(size);
554 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 567 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
555 568
556 ResourceProvider::ResourceId id2 = child_resource_provider->CreateResource( 569 ResourceProvider::ResourceId id2 = child_resource_provider->CreateResource(
557 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 570 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
558 uint8_t data2[4] = { 5, 5, 5, 5 }; 571 uint8_t data2[4] = { 5, 5, 5, 5 };
559 child_resource_provider->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 572 child_resource_provider->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
560 573
561 int child_id = resource_provider_->CreateChild(); 574 int child_id = resource_provider_->CreateChild();
562 { 575 {
563 // Transfer some resources to the parent. 576 // Transfer some resources to the parent.
564 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 577 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
565 resource_ids_to_transfer.push_back(id1); 578 resource_ids_to_transfer.push_back(id1);
566 resource_ids_to_transfer.push_back(id2); 579 resource_ids_to_transfer.push_back(id2);
567 TransferableResourceArray list; 580 TransferableResourceArray list;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 FakeOutputSurfaceClient child_output_surface_client; 685 FakeOutputSurfaceClient child_output_surface_client;
673 scoped_ptr<OutputSurface> child_output_surface( 686 scoped_ptr<OutputSurface> child_output_surface(
674 FakeOutputSurface::Create3d( 687 FakeOutputSurface::Create3d(
675 child_context_owned.PassAs<TestWebGraphicsContext3D>())); 688 child_context_owned.PassAs<TestWebGraphicsContext3D>()));
676 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); 689 CHECK(child_output_surface->BindToClient(&child_output_surface_client));
677 690
678 scoped_ptr<ResourceProvider> child_resource_provider( 691 scoped_ptr<ResourceProvider> child_resource_provider(
679 ResourceProvider::Create(child_output_surface.get(), 0)); 692 ResourceProvider::Create(child_output_surface.get(), 0));
680 693
681 gfx::Size size(1, 1); 694 gfx::Size size(1, 1);
682 WGC3Denum format = GL_RGBA; 695 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
683 size_t pixel_size = TextureSize(size, format); 696 size_t pixel_size = TextureSize(size, format);
684 ASSERT_EQ(4U, pixel_size); 697 ASSERT_EQ(4U, pixel_size);
685 698
686 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( 699 ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
687 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 700 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
688 uint8_t data[4] = { 1, 2, 3, 4 }; 701 uint8_t data[4] = { 1, 2, 3, 4 };
689 gfx::Rect rect(size); 702 gfx::Rect rect(size);
690 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); 703 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
691 704
692 int child_id = resource_provider_->CreateChild(); 705 int child_id = resource_provider_->CreateChild();
693 { 706 {
694 // Transfer some resource to the parent. 707 // Transfer some resource to the parent.
695 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 708 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
696 resource_ids_to_transfer.push_back(id); 709 resource_ids_to_transfer.push_back(id);
697 TransferableResourceArray list; 710 TransferableResourceArray list;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 748
736 FakeOutputSurfaceClient child_output_surface_client; 749 FakeOutputSurfaceClient child_output_surface_client;
737 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( 750 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d(
738 child_context_owned.PassAs<TestWebGraphicsContext3D>())); 751 child_context_owned.PassAs<TestWebGraphicsContext3D>()));
739 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); 752 CHECK(child_output_surface->BindToClient(&child_output_surface_client));
740 753
741 scoped_ptr<ResourceProvider> child_resource_provider( 754 scoped_ptr<ResourceProvider> child_resource_provider(
742 ResourceProvider::Create(child_output_surface.get(), 0)); 755 ResourceProvider::Create(child_output_surface.get(), 0));
743 756
744 gfx::Size size(1, 1); 757 gfx::Size size(1, 1);
745 WGC3Denum format = GL_RGBA; 758 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
746 size_t pixel_size = TextureSize(size, format); 759 size_t pixel_size = TextureSize(size, format);
747 ASSERT_EQ(4U, pixel_size); 760 ASSERT_EQ(4U, pixel_size);
748 761
749 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( 762 ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
750 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 763 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
751 uint8_t data[4] = { 1, 2, 3, 4 }; 764 uint8_t data[4] = { 1, 2, 3, 4 };
752 gfx::Rect rect(size); 765 gfx::Rect rect(size);
753 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); 766 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
754 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), 767 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR),
755 GetResourceFilter(child_resource_provider.get(), 768 GetResourceFilter(child_resource_provider.get(),
756 child_context, 769 child_context,
757 id)); 770 id));
758 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); 771 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST);
759 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), 772 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST),
760 GetResourceFilter(child_resource_provider.get(), 773 GetResourceFilter(child_resource_provider.get(),
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 EXPECT_LE(sync_point, list[0].sync_point); 861 EXPECT_LE(sync_point, list[0].sync_point);
849 EXPECT_EQ(0, 862 EXPECT_EQ(0,
850 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); 863 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name)));
851 EXPECT_EQ(0u, release_sync_point); 864 EXPECT_EQ(0u, release_sync_point);
852 865
853 context()->waitSyncPoint(list[0].sync_point); 866 context()->waitSyncPoint(list[0].sync_point);
854 unsigned other_texture = context()->createTexture(); 867 unsigned other_texture = context()->createTexture();
855 context()->bindTexture(GL_TEXTURE_2D, other_texture); 868 context()->bindTexture(GL_TEXTURE_2D, other_texture);
856 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 869 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
857 uint8_t test_data[4] = { 0 }; 870 uint8_t test_data[4] = { 0 };
858 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); 871 context()->GetPixels(
872 gfx::Size(1, 1), ResourceProvider::RGBA_8888, test_data);
859 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 873 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
860 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 874 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
861 context()->deleteTexture(other_texture); 875 context()->deleteTexture(other_texture);
862 list[0].sync_point = context()->insertSyncPoint(); 876 list[0].sync_point = context()->insertSyncPoint();
863 EXPECT_LT(0u, list[0].sync_point); 877 EXPECT_LT(0u, list[0].sync_point);
864 878
865 // Receive the resource, then delete it, expect the sync points to be 879 // Receive the resource, then delete it, expect the sync points to be
866 // consistent. 880 // consistent.
867 ReturnedResourceArray returned; 881 ReturnedResourceArray returned;
868 TransferableResource::ReturnResources(list, &returned); 882 TransferableResource::ReturnResources(list, &returned);
(...skipping 25 matching lines...) Expand all
894 EXPECT_LE(sync_point, list[0].sync_point); 908 EXPECT_LE(sync_point, list[0].sync_point);
895 EXPECT_EQ(0, 909 EXPECT_EQ(0,
896 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name))); 910 memcmp(mailbox.name, list[0].mailbox.name, sizeof(mailbox.name)));
897 EXPECT_EQ(0u, release_sync_point); 911 EXPECT_EQ(0u, release_sync_point);
898 912
899 context()->waitSyncPoint(list[0].sync_point); 913 context()->waitSyncPoint(list[0].sync_point);
900 unsigned other_texture = context()->createTexture(); 914 unsigned other_texture = context()->createTexture();
901 context()->bindTexture(GL_TEXTURE_2D, other_texture); 915 context()->bindTexture(GL_TEXTURE_2D, other_texture);
902 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 916 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
903 uint8_t test_data[4] = { 0 }; 917 uint8_t test_data[4] = { 0 };
904 context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data); 918 context()->GetPixels(
919 gfx::Size(1, 1), ResourceProvider::RGBA_8888, test_data);
905 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 920 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
906 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 921 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
907 context()->deleteTexture(other_texture); 922 context()->deleteTexture(other_texture);
908 list[0].sync_point = context()->insertSyncPoint(); 923 list[0].sync_point = context()->insertSyncPoint();
909 EXPECT_LT(0u, list[0].sync_point); 924 EXPECT_LT(0u, list[0].sync_point);
910 925
911 // Delete the resource, which shouldn't do anything. 926 // Delete the resource, which shouldn't do anything.
912 resource_provider_->DeleteResource(resource); 927 resource_provider_->DeleteResource(resource);
913 EXPECT_EQ(1, context()->texture_count()); 928 EXPECT_EQ(1, context()->texture_count());
914 EXPECT_EQ(0u, release_sync_point); 929 EXPECT_EQ(0u, release_sync_point);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1101
1087 FakeOutputSurfaceClient output_surface_client; 1102 FakeOutputSurfaceClient output_surface_client;
1088 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1103 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1089 context_owned.PassAs<TestWebGraphicsContext3D>())); 1104 context_owned.PassAs<TestWebGraphicsContext3D>()));
1090 CHECK(output_surface->BindToClient(&output_surface_client)); 1105 CHECK(output_surface->BindToClient(&output_surface_client));
1091 1106
1092 scoped_ptr<ResourceProvider> resource_provider( 1107 scoped_ptr<ResourceProvider> resource_provider(
1093 ResourceProvider::Create(output_surface.get(), 0)); 1108 ResourceProvider::Create(output_surface.get(), 0));
1094 1109
1095 gfx::Size size(1, 1); 1110 gfx::Size size(1, 1);
1096 WGC3Denum format = GL_RGBA; 1111 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1097 int texture_id = 1; 1112 int texture_id = 1;
1098 1113
1099 // Check that the texture gets created with the right sampler settings. 1114 // Check that the texture gets created with the right sampler settings.
1100 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) 1115 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id))
1101 .Times(2); // Once to create and once to allocate. 1116 .Times(2); // Once to create and once to allocate.
1102 EXPECT_CALL(*context, 1117 EXPECT_CALL(*context,
1103 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1118 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1104 EXPECT_CALL(*context, 1119 EXPECT_CALL(*context,
1105 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 1120 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
1106 EXPECT_CALL( 1121 EXPECT_CALL(
1107 *context, 1122 *context,
1108 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 1123 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1109 EXPECT_CALL( 1124 EXPECT_CALL(
1110 *context, 1125 *context,
1111 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 1126 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1112 EXPECT_CALL(*context, 1127 EXPECT_CALL(*context,
1113 texParameteri(GL_TEXTURE_2D, 1128 texParameteri(GL_TEXTURE_2D,
1114 GL_TEXTURE_POOL_CHROMIUM, 1129 GL_TEXTURE_POOL_CHROMIUM,
1115 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 1130 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
1116 ResourceProvider::ResourceId id = resource_provider->CreateResource( 1131 ResourceProvider::ResourceId id = resource_provider->CreateResource(
1117 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1132 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1118 resource_provider->AllocateForTesting(id); 1133 resource_provider->AllocateForTesting(id);
1119 1134
1120 // Creating a sampler with the default filter should not change any texture 1135 // Creating a sampler with the default filter should not change any texture
1121 // parameters. 1136 // parameters.
1122 { 1137 {
1123 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 1138 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
1124 ResourceProvider::ScopedSamplerGL sampler( 1139 ResourceProvider::ScopedSamplerGL sampler(
1125 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); 1140 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR);
1126 } 1141 }
1127 1142
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 1178
1164 FakeOutputSurfaceClient output_surface_client; 1179 FakeOutputSurfaceClient output_surface_client;
1165 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1180 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1166 context_owned.PassAs<TestWebGraphicsContext3D>())); 1181 context_owned.PassAs<TestWebGraphicsContext3D>()));
1167 CHECK(output_surface->BindToClient(&output_surface_client)); 1182 CHECK(output_surface->BindToClient(&output_surface_client));
1168 1183
1169 scoped_ptr<ResourceProvider> resource_provider( 1184 scoped_ptr<ResourceProvider> resource_provider(
1170 ResourceProvider::Create(output_surface.get(), 0)); 1185 ResourceProvider::Create(output_surface.get(), 0));
1171 1186
1172 gfx::Size size(1, 1); 1187 gfx::Size size(1, 1);
1173 WGC3Denum format = GL_RGBA; 1188 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1174 int texture_id = 1; 1189 int texture_id = 1;
1175 1190
1176 // Check that the texture gets created with the right sampler settings. 1191 // Check that the texture gets created with the right sampler settings.
1177 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( 1192 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource(
1178 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1193 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1179 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 1194 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
1180 EXPECT_CALL(*context, 1195 EXPECT_CALL(*context,
1181 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1196 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1182 EXPECT_CALL(*context, 1197 EXPECT_CALL(*context,
1183 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 1198 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
1184 EXPECT_CALL( 1199 EXPECT_CALL(
1185 *context, 1200 *context,
1186 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 1201 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1187 EXPECT_CALL( 1202 EXPECT_CALL(
1188 *context, 1203 *context,
(...skipping 19 matching lines...) Expand all
1208 1223
1209 FakeOutputSurfaceClient output_surface_client; 1224 FakeOutputSurfaceClient output_surface_client;
1210 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1225 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1211 context_owned.PassAs<TestWebGraphicsContext3D>())); 1226 context_owned.PassAs<TestWebGraphicsContext3D>()));
1212 CHECK(output_surface->BindToClient(&output_surface_client)); 1227 CHECK(output_surface->BindToClient(&output_surface_client));
1213 1228
1214 scoped_ptr<ResourceProvider> resource_provider( 1229 scoped_ptr<ResourceProvider> resource_provider(
1215 ResourceProvider::Create(output_surface.get(), 0)); 1230 ResourceProvider::Create(output_surface.get(), 0));
1216 1231
1217 gfx::Size size(1, 1); 1232 gfx::Size size(1, 1);
1218 WGC3Denum format = GL_RGBA; 1233 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1219 int texture_id = 1; 1234 int texture_id = 1;
1220 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; 1235 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
1221 1236
1222 for (int i = 0; i < 2; ++i) { 1237 for (int i = 0; i < 2; ++i) {
1223 GLint wrap_mode = i ? GL_CLAMP_TO_EDGE : GL_REPEAT; 1238 GLint wrap_mode = i ? GL_CLAMP_TO_EDGE : GL_REPEAT;
1224 // Check that the texture gets created with the right sampler settings. 1239 // Check that the texture gets created with the right sampler settings.
1225 ResourceProvider::ResourceId id = resource_provider->CreateGLTexture( 1240 ResourceProvider::ResourceId id =
1226 size, format, texture_pool, wrap_mode, 1241 resource_provider->CreateGLTexture(size,
1227 ResourceProvider::TextureUsageAny); 1242 texture_pool,
1243 wrap_mode,
1244 ResourceProvider::TextureUsageAny,
1245 format);
1228 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 1246 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
1229 EXPECT_CALL(*context, 1247 EXPECT_CALL(*context,
1230 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1248 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1231 EXPECT_CALL(*context, 1249 EXPECT_CALL(*context,
1232 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 1250 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
1233 EXPECT_CALL( 1251 EXPECT_CALL(
1234 *context, 1252 *context,
1235 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode)); 1253 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode));
1236 EXPECT_CALL( 1254 EXPECT_CALL(
1237 *context, 1255 *context,
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1499 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1482 context_owned.PassAs<TestWebGraphicsContext3D>())); 1500 context_owned.PassAs<TestWebGraphicsContext3D>()));
1483 CHECK(output_surface->BindToClient(&output_surface_client)); 1501 CHECK(output_surface->BindToClient(&output_surface_client));
1484 1502
1485 scoped_ptr<ResourceProvider> resource_provider( 1503 scoped_ptr<ResourceProvider> resource_provider(
1486 ResourceProvider::Create(output_surface.get(), 0)); 1504 ResourceProvider::Create(output_surface.get(), 0));
1487 1505
1488 gfx::Size size(2, 2); 1506 gfx::Size size(2, 2);
1489 gfx::Vector2d offset(0, 0); 1507 gfx::Vector2d offset(0, 0);
1490 gfx::Rect rect(0, 0, 2, 2); 1508 gfx::Rect rect(0, 0, 2, 2);
1491 WGC3Denum format = GL_RGBA; 1509 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1492 ResourceProvider::ResourceId id = 0; 1510 ResourceProvider::ResourceId id = 0;
1493 uint8_t pixels[16] = { 0 }; 1511 uint8_t pixels[16] = { 0 };
1494 int texture_id = 123; 1512 int texture_id = 123;
1495 1513
1496 // Lazy allocation. Don't allocate when creating the resource. 1514 // Lazy allocation. Don't allocate when creating the resource.
1497 id = resource_provider->CreateResource( 1515 id = resource_provider->CreateResource(
1498 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1516 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1499 1517
1500 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); 1518 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
1501 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 1519 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
1502 resource_provider->CreateForTesting(id); 1520 resource_provider->CreateForTesting(id);
1503 1521
1504 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); 1522 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1);
1505 resource_provider->DeleteResource(id); 1523 resource_provider->DeleteResource(id);
1506 1524
1507 Mock::VerifyAndClearExpectations(context); 1525 Mock::VerifyAndClearExpectations(context);
1508 1526
1509 // Do allocate when we set the pixels. 1527 // Do allocate when we set the pixels.
1510 id = resource_provider->CreateResource( 1528 id = resource_provider->CreateResource(
1511 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1529 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1512 1530
1513 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); 1531 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
1514 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 1532 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
1515 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); 1533 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1);
1516 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); 1534 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1);
1517 resource_provider->SetPixels(id, pixels, rect, rect, offset); 1535 resource_provider->SetPixels(id, pixels, rect, rect, offset);
1518 1536
1519 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); 1537 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1);
1520 resource_provider->DeleteResource(id); 1538 resource_provider->DeleteResource(id);
1521 1539
1522 Mock::VerifyAndClearExpectations(context); 1540 Mock::VerifyAndClearExpectations(context);
1523 1541
1524 // Same for async version. 1542 // Same for async version.
1525 id = resource_provider->CreateResource( 1543 id = resource_provider->CreateResource(
1526 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1544 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1527 resource_provider->AcquirePixelBuffer(id); 1545 resource_provider->AcquirePixelBuffer(id);
1528 1546
1529 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); 1547 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
1530 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 1548 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
1531 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 1549 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
1532 .Times(1); 1550 .Times(1);
1533 resource_provider->BeginSetPixels(id); 1551 resource_provider->BeginSetPixels(id);
1534 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); 1552 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id));
1535 1553
1536 resource_provider->ReleasePixelBuffer(id); 1554 resource_provider->ReleasePixelBuffer(id);
(...skipping 10 matching lines...) Expand all
1547 scoped_ptr<AllocationTrackingContext3D> context_owned( 1565 scoped_ptr<AllocationTrackingContext3D> context_owned(
1548 new StrictMock<AllocationTrackingContext3D>); 1566 new StrictMock<AllocationTrackingContext3D>);
1549 AllocationTrackingContext3D* context = context_owned.get(); 1567 AllocationTrackingContext3D* context = context_owned.get();
1550 1568
1551 FakeOutputSurfaceClient output_surface_client; 1569 FakeOutputSurfaceClient output_surface_client;
1552 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1570 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1553 context_owned.PassAs<TestWebGraphicsContext3D>())); 1571 context_owned.PassAs<TestWebGraphicsContext3D>()));
1554 CHECK(output_surface->BindToClient(&output_surface_client)); 1572 CHECK(output_surface->BindToClient(&output_surface_client));
1555 1573
1556 gfx::Size size(2, 2); 1574 gfx::Size size(2, 2);
1557 WGC3Denum format = GL_RGBA; 1575 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1558 ResourceProvider::ResourceId id = 0; 1576 ResourceProvider::ResourceId id = 0;
1559 int texture_id = 123; 1577 int texture_id = 123;
1560 1578
1561 scoped_ptr<ResourceProvider> resource_provider( 1579 scoped_ptr<ResourceProvider> resource_provider(
1562 ResourceProvider::Create(output_surface.get(), 0)); 1580 ResourceProvider::Create(output_surface.get(), 0));
1563 1581
1564 id = resource_provider->CreateResource( 1582 id = resource_provider->CreateResource(
1565 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1583 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1566 resource_provider->AcquirePixelBuffer(id); 1584 resource_provider->AcquirePixelBuffer(id);
1567 1585
1568 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); 1586 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
1569 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 1587 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
1570 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 1588 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
1571 .Times(1); 1589 .Times(1);
1572 resource_provider->BeginSetPixels(id); 1590 resource_provider->BeginSetPixels(id);
1573 1591
1574 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); 1592 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id));
1575 1593
1576 resource_provider->ReleasePixelBuffer(id); 1594 resource_provider->ReleasePixelBuffer(id);
1577 1595
1578 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); 1596 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1);
1579 resource_provider->DeleteResource(id); 1597 resource_provider->DeleteResource(id);
1580 1598
1581 Mock::VerifyAndClearExpectations(context); 1599 Mock::VerifyAndClearExpectations(context);
1582 } 1600 }
1583 1601
1584 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { 1602 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) {
1585 if (GetParam() != ResourceProvider::Bitmap) 1603 if (GetParam() != ResourceProvider::Bitmap)
1586 return; 1604 return;
1587 FakeOutputSurfaceClient output_surface_client; 1605 FakeOutputSurfaceClient output_surface_client;
1588 scoped_ptr<OutputSurface> output_surface( 1606 scoped_ptr<OutputSurface> output_surface(
1589 FakeOutputSurface::CreateSoftware(make_scoped_ptr( 1607 FakeOutputSurface::CreateSoftware(make_scoped_ptr(
1590 new SoftwareOutputDevice))); 1608 new SoftwareOutputDevice)));
1591 CHECK(output_surface->BindToClient(&output_surface_client)); 1609 CHECK(output_surface->BindToClient(&output_surface_client));
1592 1610
1593 gfx::Size size(1, 1); 1611 gfx::Size size(1, 1);
1594 WGC3Denum format = GL_RGBA; 1612 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1595 ResourceProvider::ResourceId id = 0; 1613 ResourceProvider::ResourceId id = 0;
1596 const uint32_t kBadBeef = 0xbadbeef; 1614 const uint32_t kBadBeef = 0xbadbeef;
1597 1615
1598 scoped_ptr<ResourceProvider> resource_provider( 1616 scoped_ptr<ResourceProvider> resource_provider(
1599 ResourceProvider::Create(output_surface.get(), 0)); 1617 ResourceProvider::Create(output_surface.get(), 0));
1600 1618
1601 id = resource_provider->CreateResource( 1619 id = resource_provider->CreateResource(
1602 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1620 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1603 resource_provider->AcquirePixelBuffer(id); 1621 resource_provider->AcquirePixelBuffer(id);
1604 1622
1605 void* data = resource_provider->MapPixelBuffer(id); 1623 void* data = resource_provider->MapPixelBuffer(id);
1606 ASSERT_TRUE(!!data); 1624 ASSERT_TRUE(!!data);
1607 memcpy(data, &kBadBeef, sizeof(kBadBeef)); 1625 memcpy(data, &kBadBeef, sizeof(kBadBeef));
1608 resource_provider->UnmapPixelBuffer(id); 1626 resource_provider->UnmapPixelBuffer(id);
1609 1627
1610 resource_provider->BeginSetPixels(id); 1628 resource_provider->BeginSetPixels(id);
1611 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); 1629 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id));
1612 1630
(...skipping 17 matching lines...) Expand all
1630 scoped_ptr<AllocationTrackingContext3D> context_owned( 1648 scoped_ptr<AllocationTrackingContext3D> context_owned(
1631 new StrictMock<AllocationTrackingContext3D>); 1649 new StrictMock<AllocationTrackingContext3D>);
1632 AllocationTrackingContext3D* context = context_owned.get(); 1650 AllocationTrackingContext3D* context = context_owned.get();
1633 1651
1634 FakeOutputSurfaceClient output_surface_client; 1652 FakeOutputSurfaceClient output_surface_client;
1635 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1653 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1636 context_owned.PassAs<TestWebGraphicsContext3D>())); 1654 context_owned.PassAs<TestWebGraphicsContext3D>()));
1637 CHECK(output_surface->BindToClient(&output_surface_client)); 1655 CHECK(output_surface->BindToClient(&output_surface_client));
1638 1656
1639 gfx::Size size(2, 2); 1657 gfx::Size size(2, 2);
1640 WGC3Denum format = GL_RGBA; 1658 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1641 ResourceProvider::ResourceId id = 0; 1659 ResourceProvider::ResourceId id = 0;
1642 int texture_id = 123; 1660 int texture_id = 123;
1643 1661
1644 scoped_ptr<ResourceProvider> resource_provider( 1662 scoped_ptr<ResourceProvider> resource_provider(
1645 ResourceProvider::Create(output_surface.get(), 0)); 1663 ResourceProvider::Create(output_surface.get(), 0));
1646 1664
1647 id = resource_provider->CreateResource( 1665 id = resource_provider->CreateResource(
1648 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1666 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1649 resource_provider->AcquirePixelBuffer(id); 1667 resource_provider->AcquirePixelBuffer(id);
1650 1668
1651 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); 1669 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
1652 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 1670 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
1653 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 1671 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
1654 .Times(1); 1672 .Times(1);
1655 resource_provider->BeginSetPixels(id); 1673 resource_provider->BeginSetPixels(id);
1656 1674
1657 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 1675 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
1658 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); 1676 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1);
(...skipping 12 matching lines...) Expand all
1671 scoped_ptr<AllocationTrackingContext3D> context_owned( 1689 scoped_ptr<AllocationTrackingContext3D> context_owned(
1672 new NiceMock<AllocationTrackingContext3D>); 1690 new NiceMock<AllocationTrackingContext3D>);
1673 AllocationTrackingContext3D* context = context_owned.get(); 1691 AllocationTrackingContext3D* context = context_owned.get();
1674 1692
1675 FakeOutputSurfaceClient output_surface_client; 1693 FakeOutputSurfaceClient output_surface_client;
1676 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1694 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1677 context_owned.PassAs<TestWebGraphicsContext3D>())); 1695 context_owned.PassAs<TestWebGraphicsContext3D>()));
1678 CHECK(output_surface->BindToClient(&output_surface_client)); 1696 CHECK(output_surface->BindToClient(&output_surface_client));
1679 1697
1680 gfx::Size size(2, 2); 1698 gfx::Size size(2, 2);
1681 WGC3Denum format = GL_RGBA; 1699 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1682 ResourceProvider::ResourceId id = 0; 1700 ResourceProvider::ResourceId id = 0;
1683 int texture_id = 123; 1701 int texture_id = 123;
1684 1702
1685 scoped_ptr<ResourceProvider> resource_provider( 1703 scoped_ptr<ResourceProvider> resource_provider(
1686 ResourceProvider::Create(output_surface.get(), 0)); 1704 ResourceProvider::Create(output_surface.get(), 0));
1687 1705
1688 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); 1706 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id));
1689 1707
1690 id = resource_provider->CreateResource( 1708 id = resource_provider->CreateResource(
1691 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1709 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1692 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 1710 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
1693 GL_INNOCENT_CONTEXT_RESET_ARB); 1711 GL_INNOCENT_CONTEXT_RESET_ARB);
1694 resource_provider->AcquirePixelBuffer(id); 1712 resource_provider->AcquirePixelBuffer(id);
1695 uint8_t* buffer = resource_provider->MapPixelBuffer(id); 1713 uint8_t* buffer = resource_provider->MapPixelBuffer(id);
1696 EXPECT_TRUE(buffer == NULL); 1714 EXPECT_TRUE(buffer == NULL);
1697 resource_provider->UnmapPixelBuffer(id); 1715 resource_provider->UnmapPixelBuffer(id);
1698 resource_provider->ReleasePixelBuffer(id); 1716 resource_provider->ReleasePixelBuffer(id);
1699 Mock::VerifyAndClearExpectations(context); 1717 Mock::VerifyAndClearExpectations(context);
1700 } 1718 }
1701 1719
1702 TEST_P(ResourceProviderTest, Image_GLTexture) { 1720 TEST_P(ResourceProviderTest, Image_GLTexture) {
1703 // Only for GL textures. 1721 // Only for GL textures.
1704 if (GetParam() != ResourceProvider::GLTexture) 1722 if (GetParam() != ResourceProvider::GLTexture)
1705 return; 1723 return;
1706 scoped_ptr<AllocationTrackingContext3D> context_owned( 1724 scoped_ptr<AllocationTrackingContext3D> context_owned(
1707 new StrictMock<AllocationTrackingContext3D>); 1725 new StrictMock<AllocationTrackingContext3D>);
1708 AllocationTrackingContext3D* context = context_owned.get(); 1726 AllocationTrackingContext3D* context = context_owned.get();
1709 1727
1710 FakeOutputSurfaceClient output_surface_client; 1728 FakeOutputSurfaceClient output_surface_client;
1711 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 1729 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1712 context_owned.PassAs<TestWebGraphicsContext3D>())); 1730 context_owned.PassAs<TestWebGraphicsContext3D>()));
1713 CHECK(output_surface->BindToClient(&output_surface_client)); 1731 CHECK(output_surface->BindToClient(&output_surface_client));
1714 1732
1715 const int kWidth = 2; 1733 const int kWidth = 2;
1716 const int kHeight = 2; 1734 const int kHeight = 2;
1717 gfx::Size size(kWidth, kHeight); 1735 gfx::Size size(kWidth, kHeight);
1718 WGC3Denum format = GL_RGBA; 1736 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1719 ResourceProvider::ResourceId id = 0; 1737 ResourceProvider::ResourceId id = 0;
1720 const unsigned kTextureId = 123u; 1738 const unsigned kTextureId = 123u;
1721 const unsigned kImageId = 234u; 1739 const unsigned kImageId = 234u;
1722 1740
1723 scoped_ptr<ResourceProvider> resource_provider( 1741 scoped_ptr<ResourceProvider> resource_provider(
1724 ResourceProvider::Create(output_surface.get(), 0)); 1742 ResourceProvider::Create(output_surface.get(), 0));
1725 1743
1726 id = resource_provider->CreateResource( 1744 id = resource_provider->CreateResource(
1727 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1745 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1728 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) 1746 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES))
1729 .WillOnce(Return(kImageId)) 1747 .WillOnce(Return(kImageId))
1730 .RetiresOnSaturation(); 1748 .RetiresOnSaturation();
1731 resource_provider->AcquireImage(id); 1749 resource_provider->AcquireImage(id);
1732 1750
1733 void* dummy_mapped_buffer_address = NULL; 1751 void* dummy_mapped_buffer_address = NULL;
1734 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) 1752 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE))
1735 .WillOnce(Return(dummy_mapped_buffer_address)) 1753 .WillOnce(Return(dummy_mapped_buffer_address))
1736 .RetiresOnSaturation(); 1754 .RetiresOnSaturation();
1737 resource_provider->MapImage(id); 1755 resource_provider->MapImage(id);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 TEST_P(ResourceProviderTest, Image_Bitmap) { 1798 TEST_P(ResourceProviderTest, Image_Bitmap) {
1781 if (GetParam() != ResourceProvider::Bitmap) 1799 if (GetParam() != ResourceProvider::Bitmap)
1782 return; 1800 return;
1783 FakeOutputSurfaceClient output_surface_client; 1801 FakeOutputSurfaceClient output_surface_client;
1784 scoped_ptr<OutputSurface> output_surface( 1802 scoped_ptr<OutputSurface> output_surface(
1785 FakeOutputSurface::CreateSoftware(make_scoped_ptr( 1803 FakeOutputSurface::CreateSoftware(make_scoped_ptr(
1786 new SoftwareOutputDevice))); 1804 new SoftwareOutputDevice)));
1787 CHECK(output_surface->BindToClient(&output_surface_client)); 1805 CHECK(output_surface->BindToClient(&output_surface_client));
1788 1806
1789 gfx::Size size(1, 1); 1807 gfx::Size size(1, 1);
1790 WGC3Denum format = GL_RGBA; 1808 ResourceProvider::Format format = ResourceProvider::RGBA_8888;
1791 ResourceProvider::ResourceId id = 0; 1809 ResourceProvider::ResourceId id = 0;
1792 const uint32_t kBadBeef = 0xbadbeef; 1810 const uint32_t kBadBeef = 0xbadbeef;
1793 1811
1794 scoped_ptr<ResourceProvider> resource_provider( 1812 scoped_ptr<ResourceProvider> resource_provider(
1795 ResourceProvider::Create(output_surface.get(), 0)); 1813 ResourceProvider::Create(output_surface.get(), 0));
1796 1814
1797 id = resource_provider->CreateResource( 1815 id = resource_provider->CreateResource(
1798 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); 1816 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
1799 resource_provider->AcquireImage(id); 1817 resource_provider->AcquireImage(id);
1800 1818
1801 const int kStride = 0; 1819 const int kStride = 0;
1802 int stride = resource_provider->GetImageStride(id); 1820 int stride = resource_provider->GetImageStride(id);
1803 EXPECT_EQ(kStride, stride); 1821 EXPECT_EQ(kStride, stride);
1804 1822
1805 void* data = resource_provider->MapImage(id); 1823 void* data = resource_provider->MapImage(id);
1806 ASSERT_TRUE(!!data); 1824 ASSERT_TRUE(!!data);
1807 memcpy(data, &kBadBeef, sizeof(kBadBeef)); 1825 memcpy(data, &kBadBeef, sizeof(kBadBeef));
1808 resource_provider->UnmapImage(id); 1826 resource_provider->UnmapImage(id);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 output_surface.get()); 1878 output_surface.get());
1861 } 1879 }
1862 1880
1863 INSTANTIATE_TEST_CASE_P( 1881 INSTANTIATE_TEST_CASE_P(
1864 ResourceProviderTests, 1882 ResourceProviderTests,
1865 ResourceProviderTest, 1883 ResourceProviderTest,
1866 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); 1884 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap));
1867 1885
1868 } // namespace 1886 } // namespace
1869 } // namespace cc 1887 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698