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

Side by Side Diff: cc/resource_provider_unittest.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MoreAndroidCompilings Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/render_surface_unittest.cc ('k') | cc/resource_update_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resource_provider.h" 5 #include "cc/resource_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/output_surface.h" 9 #include "cc/output_surface.h"
10 #include "cc/scoped_ptr_deque.h" 10 #include "cc/scoped_ptr_deque.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 gfx::Size size; 54 gfx::Size size;
55 WGC3Denum format; 55 WGC3Denum format;
56 WGC3Denum filter; 56 WGC3Denum filter;
57 scoped_array<uint8_t> data; 57 scoped_array<uint8_t> data;
58 }; 58 };
59 59
60 // Shared data between multiple ResourceProviderContext. This contains mailbox 60 // Shared data between multiple ResourceProviderContext. This contains mailbox
61 // contents as well as information about sync points. 61 // contents as well as information about sync points.
62 class ContextSharedData { 62 class ContextSharedData {
63 public: 63 public:
64 static scoped_ptr<ContextSharedData> create() { return make_scoped_ptr(new C ontextSharedData()); } 64 static scoped_ptr<ContextSharedData> Create() { return make_scoped_ptr(new C ontextSharedData()); }
65 65
66 unsigned insertSyncPoint() { return m_nextSyncPoint++; } 66 unsigned insertSyncPoint() { return m_nextSyncPoint++; }
67 67
68 void genMailbox(WGC3Dbyte* mailbox) 68 void genMailbox(WGC3Dbyte* mailbox)
69 { 69 {
70 memset(mailbox, 0, sizeof(WGC3Dbyte[64])); 70 memset(mailbox, 0, sizeof(WGC3Dbyte[64]));
71 memcpy(mailbox, &m_nextMailBox, sizeof(m_nextMailBox)); 71 memcpy(mailbox, &m_nextMailBox, sizeof(m_nextMailBox));
72 ++m_nextMailBox; 72 ++m_nextMailBox;
73 } 73 }
74 74
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 unsigned m_nextSyncPoint; 107 unsigned m_nextSyncPoint;
108 unsigned m_nextMailBox; 108 unsigned m_nextMailBox;
109 typedef ScopedPtrHashMap<unsigned, Texture> TextureMap; 109 typedef ScopedPtrHashMap<unsigned, Texture> TextureMap;
110 TextureMap m_textures; 110 TextureMap m_textures;
111 base::hash_map<unsigned, unsigned> m_syncPointForMailbox; 111 base::hash_map<unsigned, unsigned> m_syncPointForMailbox;
112 }; 112 };
113 113
114 class ResourceProviderContext : public TestWebGraphicsContext3D { 114 class ResourceProviderContext : public TestWebGraphicsContext3D {
115 public: 115 public:
116 static scoped_ptr<ResourceProviderContext> create(ContextSharedData* sharedD ata) { return make_scoped_ptr(new ResourceProviderContext(Attributes(), sharedDa ta)); } 116 static scoped_ptr<ResourceProviderContext> Create(ContextSharedData* sharedD ata) { return make_scoped_ptr(new ResourceProviderContext(Attributes(), sharedDa ta)); }
117 117
118 virtual unsigned insertSyncPoint() 118 virtual unsigned insertSyncPoint()
119 { 119 {
120 unsigned syncPoint = m_sharedData->insertSyncPoint(); 120 unsigned syncPoint = m_sharedData->insertSyncPoint();
121 // Commit the produceTextureCHROMIUM calls at this point, so that 121 // Commit the produceTextureCHROMIUM calls at this point, so that
122 // they're associated with the sync point. 122 // they're associated with the sync point.
123 for (PendingProduceTextureList::iterator it = m_pendingProduceTextures.b egin(); it != m_pendingProduceTextures.end(); ++it) 123 for (PendingProduceTextureList::iterator it = m_pendingProduceTextures.b egin(); it != m_pendingProduceTextures.end(); ++it)
124 m_sharedData->produceTexture((*it)->mailbox, syncPoint, (*it)->textu re.Pass()); 124 m_sharedData->produceTexture((*it)->mailbox, syncPoint, (*it)->textu re.Pass());
125 m_pendingProduceTextures.clear(); 125 m_pendingProduceTextures.clear();
126 return syncPoint; 126 return syncPoint;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ContextSharedData* m_sharedData; 301 ContextSharedData* m_sharedData;
302 WebGLId m_currentTexture; 302 WebGLId m_currentTexture;
303 TextureMap m_textures; 303 TextureMap m_textures;
304 unsigned m_lastWaitedSyncPoint; 304 unsigned m_lastWaitedSyncPoint;
305 PendingProduceTextureList m_pendingProduceTextures; 305 PendingProduceTextureList m_pendingProduceTextures;
306 }; 306 };
307 307
308 class ResourceProviderTest : public testing::TestWithParam<ResourceProvider::Res ourceType> { 308 class ResourceProviderTest : public testing::TestWithParam<ResourceProvider::Res ourceType> {
309 public: 309 public:
310 ResourceProviderTest() 310 ResourceProviderTest()
311 : m_sharedData(ContextSharedData::create()) 311 : m_sharedData(ContextSharedData::Create())
312 , m_outputSurface(FakeOutputSurface::Create3d(ResourceProviderContext::c reate(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<WebKit:: WebGraphicsContext3D>())) 312 , m_outputSurface(FakeOutputSurface::Create3d(ResourceProviderContext::C reate(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<WebKit:: WebGraphicsContext3D>()))
313 , m_resourceProvider(ResourceProvider::Create(m_outputSurface.get())) 313 , m_resourceProvider(ResourceProvider::Create(m_outputSurface.get()))
314 { 314 {
315 m_resourceProvider->set_default_resource_type(GetParam()); 315 m_resourceProvider->set_default_resource_type(GetParam());
316 } 316 }
317 317
318 ResourceProviderContext* context() { return static_cast<ResourceProviderCont ext*>(m_outputSurface->context3d()); } 318 ResourceProviderContext* context() { return static_cast<ResourceProviderCont ext*>(m_outputSurface->context3d()); }
319 319
320 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz e, WGC3Denum format, uint8_t* pixels) 320 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz e, WGC3Denum format, uint8_t* pixels)
321 { 321 {
322 if (GetParam() == ResourceProvider::GLTexture) { 322 if (GetParam() == ResourceProvider::GLTexture) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 m_resourceProvider->DeleteResource(id); 443 m_resourceProvider->DeleteResource(id);
444 } 444 }
445 445
446 TEST_P(ResourceProviderTest, TransferResources) 446 TEST_P(ResourceProviderTest, TransferResources)
447 { 447 {
448 // Resource transfer is only supported with GL textures for now. 448 // Resource transfer is only supported with GL textures for now.
449 if (GetParam() != ResourceProvider::GLTexture) 449 if (GetParam() != ResourceProvider::GLTexture)
450 return; 450 return;
451 451
452 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte xt3D>())); 452 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res ourceProviderContext::Create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte xt3D>()));
453 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::Create( childOutputSurface.get())); 453 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::Create( childOutputSurface.get()));
454 454
455 gfx::Size size(1, 1); 455 gfx::Size size(1, 1);
456 WGC3Denum format = GL_RGBA; 456 WGC3Denum format = GL_RGBA;
457 size_t pixelSize = textureSize(size, format); 457 size_t pixelSize = textureSize(size, format);
458 ASSERT_EQ(4U, pixelSize); 458 ASSERT_EQ(4U, pixelSize);
459 459
460 ResourceProvider::ResourceId id1 = childResourceProvider->CreateResource(siz e, format, ResourceProvider::TextureUsageAny); 460 ResourceProvider::ResourceId id1 = childResourceProvider->CreateResource(siz e, format, ResourceProvider::TextureUsageAny);
461 uint8_t data1[4] = {1, 2, 3, 4}; 461 uint8_t data1[4] = {1, 2, 3, 4};
462 gfx::Rect rect(gfx::Point(), size); 462 gfx::Rect rect(gfx::Point(), size);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 m_resourceProvider->DestroyChild(childId); 559 m_resourceProvider->DestroyChild(childId);
560 EXPECT_EQ(0u, m_resourceProvider->num_resources()); 560 EXPECT_EQ(0u, m_resourceProvider->num_resources());
561 } 561 }
562 562
563 TEST_P(ResourceProviderTest, DeleteTransferredResources) 563 TEST_P(ResourceProviderTest, DeleteTransferredResources)
564 { 564 {
565 // Resource transfer is only supported with GL textures for now. 565 // Resource transfer is only supported with GL textures for now.
566 if (GetParam() != ResourceProvider::GLTexture) 566 if (GetParam() != ResourceProvider::GLTexture)
567 return; 567 return;
568 568
569 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte xt3D>())); 569 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res ourceProviderContext::Create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte xt3D>()));
570 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::Create( childOutputSurface.get())); 570 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::Create( childOutputSurface.get()));
571 571
572 gfx::Size size(1, 1); 572 gfx::Size size(1, 1);
573 WGC3Denum format = GL_RGBA; 573 WGC3Denum format = GL_RGBA;
574 size_t pixelSize = textureSize(size, format); 574 size_t pixelSize = textureSize(size, format);
575 ASSERT_EQ(4U, pixelSize); 575 ASSERT_EQ(4U, pixelSize);
576 576
577 ResourceProvider::ResourceId id = childResourceProvider->CreateResource(size , format, ResourceProvider::TextureUsageAny); 577 ResourceProvider::ResourceId id = childResourceProvider->CreateResource(size , format, ResourceProvider::TextureUsageAny);
578 uint8_t data[4] = {1, 2, 3, 4}; 578 uint8_t data[4] = {1, 2, 3, 4};
579 gfx::Rect rect(gfx::Point(), size); 579 gfx::Rect rect(gfx::Point(), size);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 } 612 }
613 EXPECT_EQ(0u, childResourceProvider->num_resources()); 613 EXPECT_EQ(0u, childResourceProvider->num_resources());
614 } 614 }
615 615
616 TEST_P(ResourceProviderTest, TextureFilters) 616 TEST_P(ResourceProviderTest, TextureFilters)
617 { 617 {
618 // Resource transfer is only supported with GL textures for now. 618 // Resource transfer is only supported with GL textures for now.
619 if (GetParam() != ResourceProvider::GLTexture) 619 if (GetParam() != ResourceProvider::GLTexture)
620 return; 620 return;
621 621
622 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte xt3D>())); 622 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res ourceProviderContext::Create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte xt3D>()));
623 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::Create( childOutputSurface.get())); 623 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::Create( childOutputSurface.get()));
624 624
625 gfx::Size size(1, 1); 625 gfx::Size size(1, 1);
626 WGC3Denum format = GL_RGBA; 626 WGC3Denum format = GL_RGBA;
627 size_t pixelSize = textureSize(size, format); 627 size_t pixelSize = textureSize(size, format);
628 ASSERT_EQ(4U, pixelSize); 628 ASSERT_EQ(4U, pixelSize);
629 629
630 ResourceProvider::ResourceId id = childResourceProvider->CreateResource(size , format, ResourceProvider::TextureUsageAny); 630 ResourceProvider::ResourceId id = childResourceProvider->CreateResource(size , format, ResourceProvider::TextureUsageAny);
631 uint8_t data[4] = {1, 2, 3, 4}; 631 uint8_t data[4] = {1, 2, 3, 4};
632 gfx::Rect rect(gfx::Point(), size); 632 gfx::Rect rect(gfx::Point(), size);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 Mock::VerifyAndClearExpectations(context); 948 Mock::VerifyAndClearExpectations(context);
949 } 949 }
950 950
951 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, 951 INSTANTIATE_TEST_CASE_P(ResourceProviderTests,
952 ResourceProviderTest, 952 ResourceProviderTest,
953 ::testing::Values(ResourceProvider::GLTexture, 953 ::testing::Values(ResourceProvider::GLTexture,
954 ResourceProvider::Bitmap)); 954 ResourceProvider::Bitmap));
955 955
956 } // namespace 956 } // namespace
957 } // namespace cc 957 } // namespace cc
OLDNEW
« no previous file with comments | « cc/render_surface_unittest.cc ('k') | cc/resource_update_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698