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

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

Powered by Google App Engine
This is Rietveld 408576698