| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCResourceProvider.h" | 7 #include "CCResourceProvider.h" |
| 8 | 8 |
| 9 #include "CCGraphicsContext.h" | 9 #include "CCGraphicsContext.h" |
| 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread | 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread |
| 11 #include "Extensions3DChromium.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "cc/scoped_ptr_deque.h" | 12 #include "cc/scoped_ptr_deque.h" |
| 14 #include "cc/scoped_ptr_hash_map.h" | 13 #include "cc/scoped_ptr_hash_map.h" |
| 15 #include "cc/test/compositor_fake_web_graphics_context_3d.h" | 14 #include "cc/test/compositor_fake_web_graphics_context_3d.h" |
| 16 #include "cc/test/fake_web_compositor_output_surface.h" | 15 #include "cc/test/fake_web_compositor_output_surface.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/khronos/GLES2/gl2.h" |
| 18 #include "third_party/khronos/GLES2/gl2ext.h" |
| 18 #include <public/WebGraphicsContext3D.h> | 19 #include <public/WebGraphicsContext3D.h> |
| 19 | 20 |
| 20 using namespace cc; | 21 using namespace cc; |
| 21 using namespace WebKit; | 22 using namespace WebKit; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 size_t textureSize(const IntSize& size, WGC3Denum format) | 26 size_t textureSize(const IntSize& size, WGC3Denum format) |
| 26 { | 27 { |
| 27 unsigned int componentsPerPixel = 4; | 28 unsigned int componentsPerPixel = 4; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return syncPoint; | 110 return syncPoint; |
| 110 } | 111 } |
| 111 | 112 |
| 112 virtual void waitSyncPoint(unsigned syncPoint) | 113 virtual void waitSyncPoint(unsigned syncPoint) |
| 113 { | 114 { |
| 114 m_lastWaitedSyncPoint = std::max(syncPoint, m_lastWaitedSyncPoint); | 115 m_lastWaitedSyncPoint = std::max(syncPoint, m_lastWaitedSyncPoint); |
| 115 } | 116 } |
| 116 | 117 |
| 117 virtual void bindTexture(WGC3Denum target, WebGLId texture) | 118 virtual void bindTexture(WGC3Denum target, WebGLId texture) |
| 118 { | 119 { |
| 119 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); | 120 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 120 ASSERT_TRUE(!texture || m_textures.find(texture) != m_textures.end()); | 121 ASSERT_TRUE(!texture || m_textures.find(texture) != m_textures.end()); |
| 121 m_currentTexture = texture; | 122 m_currentTexture = texture; |
| 122 } | 123 } |
| 123 | 124 |
| 124 virtual WebGLId createTexture() | 125 virtual WebGLId createTexture() |
| 125 { | 126 { |
| 126 WebGLId id = CompositorFakeWebGraphicsContext3D::createTexture(); | 127 WebGLId id = CompositorFakeWebGraphicsContext3D::createTexture(); |
| 127 m_textures.add(id, scoped_ptr<Texture>()); | 128 m_textures.add(id, scoped_ptr<Texture>()); |
| 128 return id; | 129 return id; |
| 129 } | 130 } |
| 130 | 131 |
| 131 virtual void deleteTexture(WebGLId id) | 132 virtual void deleteTexture(WebGLId id) |
| 132 { | 133 { |
| 133 TextureMap::iterator it = m_textures.find(id); | 134 TextureMap::iterator it = m_textures.find(id); |
| 134 ASSERT_FALSE(it == m_textures.end()); | 135 ASSERT_FALSE(it == m_textures.end()); |
| 135 m_textures.erase(it); | 136 m_textures.erase(it); |
| 136 if (m_currentTexture == id) | 137 if (m_currentTexture == id) |
| 137 m_currentTexture = 0; | 138 m_currentTexture = 0; |
| 138 } | 139 } |
| 139 | 140 |
| 140 virtual void texStorage2DEXT(WGC3Denum target, WGC3Dint levels, WGC3Duint in
ternalformat, | 141 virtual void texStorage2DEXT(WGC3Denum target, WGC3Dint levels, WGC3Duint in
ternalformat, |
| 141 WGC3Dint width, WGC3Dint height) | 142 WGC3Dint width, WGC3Dint height) |
| 142 { | 143 { |
| 143 ASSERT_TRUE(m_currentTexture); | 144 ASSERT_TRUE(m_currentTexture); |
| 144 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); | 145 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 145 ASSERT_EQ(levels, 1); | 146 ASSERT_EQ(levels, 1); |
| 146 WGC3Denum format = GraphicsContext3D::RGBA; | 147 WGC3Denum format = GL_RGBA; |
| 147 switch (internalformat) { | 148 switch (internalformat) { |
| 148 case Extensions3D::RGBA8_OES: | 149 case GL_RGBA8_OES: |
| 149 break; | 150 break; |
| 150 case Extensions3DChromium::BGRA8_EXT: | 151 case GL_BGRA8_EXT: |
| 151 format = Extensions3D::BGRA_EXT; | 152 format = GL_BGRA_EXT; |
| 152 break; | 153 break; |
| 153 default: | 154 default: |
| 154 NOTREACHED(); | 155 NOTREACHED(); |
| 155 } | 156 } |
| 156 allocateTexture(IntSize(width, height), format); | 157 allocateTexture(IntSize(width, height), format); |
| 157 } | 158 } |
| 158 | 159 |
| 159 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) | 160 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) |
| 160 { | 161 { |
| 161 ASSERT_TRUE(m_currentTexture); | 162 ASSERT_TRUE(m_currentTexture); |
| 162 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); | 163 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 163 ASSERT_FALSE(level); | 164 ASSERT_FALSE(level); |
| 164 ASSERT_EQ(internalformat, format); | 165 ASSERT_EQ(internalformat, format); |
| 165 ASSERT_FALSE(border); | 166 ASSERT_FALSE(border); |
| 166 ASSERT_EQ(type, GraphicsContext3D::UNSIGNED_BYTE); | 167 ASSERT_EQ(type, GL_UNSIGNED_BYTE); |
| 167 allocateTexture(IntSize(width, height), format); | 168 allocateTexture(IntSize(width, height), format); |
| 168 if (pixels) | 169 if (pixels) |
| 169 setPixels(0, 0, width, height, pixels); | 170 setPixels(0, 0, width, height, pixels); |
| 170 } | 171 } |
| 171 | 172 |
| 172 virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffse
t, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3
Denum type, const void* pixels) | 173 virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffse
t, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3
Denum type, const void* pixels) |
| 173 { | 174 { |
| 174 ASSERT_TRUE(m_currentTexture); | 175 ASSERT_TRUE(m_currentTexture); |
| 175 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); | 176 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 176 ASSERT_FALSE(level); | 177 ASSERT_FALSE(level); |
| 177 ASSERT_TRUE(m_textures.get(m_currentTexture)); | 178 ASSERT_TRUE(m_textures.get(m_currentTexture)); |
| 178 ASSERT_EQ(m_textures.get(m_currentTexture)->format, format); | 179 ASSERT_EQ(m_textures.get(m_currentTexture)->format, format); |
| 179 ASSERT_EQ(type, GraphicsContext3D::UNSIGNED_BYTE); | 180 ASSERT_EQ(type, GL_UNSIGNED_BYTE); |
| 180 ASSERT_TRUE(pixels); | 181 ASSERT_TRUE(pixels); |
| 181 setPixels(xoffset, yoffset, width, height, pixels); | 182 setPixels(xoffset, yoffset, width, height, pixels); |
| 182 } | 183 } |
| 183 | 184 |
| 184 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) { return m_sharedData->g
enMailbox(mailbox); } | 185 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) { return m_sharedData->g
enMailbox(mailbox); } |
| 185 virtual void produceTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) | 186 virtual void produceTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) |
| 186 { | 187 { |
| 187 ASSERT_TRUE(m_currentTexture); | 188 ASSERT_TRUE(m_currentTexture); |
| 188 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); | 189 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 189 | 190 |
| 190 // Delay moving the texture into the mailbox until the next | 191 // Delay moving the texture into the mailbox until the next |
| 191 // insertSyncPoint, so that it is not visible to other contexts that | 192 // insertSyncPoint, so that it is not visible to other contexts that |
| 192 // haven't waited on that sync point. | 193 // haven't waited on that sync point. |
| 193 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); | 194 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); |
| 194 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 195 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
| 195 pending->texture = m_textures.take(m_currentTexture); | 196 pending->texture = m_textures.take(m_currentTexture); |
| 196 m_textures.set(m_currentTexture, scoped_ptr<Texture>()); | 197 m_textures.set(m_currentTexture, scoped_ptr<Texture>()); |
| 197 m_pendingProduceTextures.append(pending.Pass()); | 198 m_pendingProduceTextures.append(pending.Pass()); |
| 198 } | 199 } |
| 199 | 200 |
| 200 virtual void consumeTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) | 201 virtual void consumeTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) |
| 201 { | 202 { |
| 202 ASSERT_TRUE(m_currentTexture); | 203 ASSERT_TRUE(m_currentTexture); |
| 203 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); | 204 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 204 m_textures.set(m_currentTexture, m_sharedData->consumeTexture(mailbox, m
_lastWaitedSyncPoint)); | 205 m_textures.set(m_currentTexture, m_sharedData->consumeTexture(mailbox, m
_lastWaitedSyncPoint)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void getPixels(const IntSize& size, WGC3Denum format, uint8_t* pixels) | 208 void getPixels(const IntSize& size, WGC3Denum format, uint8_t* pixels) |
| 208 { | 209 { |
| 209 ASSERT_TRUE(m_currentTexture); | 210 ASSERT_TRUE(m_currentTexture); |
| 210 Texture* texture = m_textures.get(m_currentTexture); | 211 Texture* texture = m_textures.get(m_currentTexture); |
| 211 ASSERT_TRUE(texture); | 212 ASSERT_TRUE(texture); |
| 212 ASSERT_EQ(texture->size, size); | 213 ASSERT_EQ(texture->size, size); |
| 213 ASSERT_EQ(texture->format, format); | 214 ASSERT_EQ(texture->format, format); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 m_resourceProvider->setDefaultResourceType(GetParam()); | 277 m_resourceProvider->setDefaultResourceType(GetParam()); |
| 277 } | 278 } |
| 278 | 279 |
| 279 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_context->context3D()); } | 280 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_context->context3D()); } |
| 280 | 281 |
| 281 void getResourcePixels(CCResourceProvider::ResourceId id, const IntSize& siz
e, WGC3Denum format, uint8_t* pixels) | 282 void getResourcePixels(CCResourceProvider::ResourceId id, const IntSize& siz
e, WGC3Denum format, uint8_t* pixels) |
| 282 { | 283 { |
| 283 if (GetParam() == CCResourceProvider::GLTexture) { | 284 if (GetParam() == CCResourceProvider::GLTexture) { |
| 284 CCResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get()
, id); | 285 CCResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get()
, id); |
| 285 ASSERT_NE(0U, lockGL.textureId()); | 286 ASSERT_NE(0U, lockGL.textureId()); |
| 286 context()->bindTexture(GraphicsContext3D::TEXTURE_2D, lockGL.texture
Id()); | 287 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); |
| 287 context()->getPixels(size, format, pixels); | 288 context()->getPixels(size, format, pixels); |
| 288 } else if (GetParam() == CCResourceProvider::Bitmap) { | 289 } else if (GetParam() == CCResourceProvider::Bitmap) { |
| 289 CCResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourcePr
ovider.get(), id); | 290 CCResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourcePr
ovider.get(), id); |
| 290 memcpy(pixels, lockSoftware.skBitmap()->getPixels(), lockSoftware.sk
Bitmap()->getSize()); | 291 memcpy(pixels, lockSoftware.skBitmap()->getPixels(), lockSoftware.sk
Bitmap()->getSize()); |
| 291 } | 292 } |
| 292 } | 293 } |
| 293 | 294 |
| 294 void expectNumResources(int count) | 295 void expectNumResources(int count) |
| 295 { | 296 { |
| 296 EXPECT_EQ(count, static_cast<int>(m_resourceProvider->numResources())); | 297 EXPECT_EQ(count, static_cast<int>(m_resourceProvider->numResources())); |
| 297 if (GetParam() == CCResourceProvider::GLTexture) | 298 if (GetParam() == CCResourceProvider::GLTexture) |
| 298 EXPECT_EQ(count, context()->textureCount()); | 299 EXPECT_EQ(count, context()->textureCount()); |
| 299 } | 300 } |
| 300 | 301 |
| 301 protected: | 302 protected: |
| 302 DebugScopedSetImplThread implThread; | 303 DebugScopedSetImplThread implThread; |
| 303 scoped_ptr<ContextSharedData> m_sharedData; | 304 scoped_ptr<ContextSharedData> m_sharedData; |
| 304 scoped_ptr<CCGraphicsContext> m_context; | 305 scoped_ptr<CCGraphicsContext> m_context; |
| 305 scoped_ptr<CCResourceProvider> m_resourceProvider; | 306 scoped_ptr<CCResourceProvider> m_resourceProvider; |
| 306 }; | 307 }; |
| 307 | 308 |
| 308 TEST_P(CCResourceProviderTest, Basic) | 309 TEST_P(CCResourceProviderTest, Basic) |
| 309 { | 310 { |
| 310 IntSize size(1, 1); | 311 IntSize size(1, 1); |
| 311 WGC3Denum format = GraphicsContext3D::RGBA; | 312 WGC3Denum format = GL_RGBA; |
| 312 int pool = 1; | 313 int pool = 1; |
| 313 size_t pixelSize = textureSize(size, format); | 314 size_t pixelSize = textureSize(size, format); |
| 314 ASSERT_EQ(4U, pixelSize); | 315 ASSERT_EQ(4U, pixelSize); |
| 315 | 316 |
| 316 CCResourceProvider::ResourceId id = m_resourceProvider->createResource(pool,
size, format, CCResourceProvider::TextureUsageAny); | 317 CCResourceProvider::ResourceId id = m_resourceProvider->createResource(pool,
size, format, CCResourceProvider::TextureUsageAny); |
| 317 expectNumResources(1); | 318 expectNumResources(1); |
| 318 | 319 |
| 319 uint8_t data[4] = {1, 2, 3, 4}; | 320 uint8_t data[4] = {1, 2, 3, 4}; |
| 320 IntRect rect(IntPoint(), size); | 321 IntRect rect(IntPoint(), size); |
| 321 m_resourceProvider->upload(id, data, rect, rect, IntSize()); | 322 m_resourceProvider->upload(id, data, rect, rect, IntSize()); |
| 322 | 323 |
| 323 uint8_t result[4] = {0}; | 324 uint8_t result[4] = {0}; |
| 324 getResourcePixels(id, size, format, result); | 325 getResourcePixels(id, size, format, result); |
| 325 EXPECT_EQ(0, memcmp(data, result, pixelSize)); | 326 EXPECT_EQ(0, memcmp(data, result, pixelSize)); |
| 326 | 327 |
| 327 m_resourceProvider->deleteResource(id); | 328 m_resourceProvider->deleteResource(id); |
| 328 expectNumResources(0); | 329 expectNumResources(0); |
| 329 } | 330 } |
| 330 | 331 |
| 331 TEST_P(CCResourceProviderTest, DeleteOwnedResources) | 332 TEST_P(CCResourceProviderTest, DeleteOwnedResources) |
| 332 { | 333 { |
| 333 IntSize size(1, 1); | 334 IntSize size(1, 1); |
| 334 WGC3Denum format = GraphicsContext3D::RGBA; | 335 WGC3Denum format = GL_RGBA; |
| 335 int pool = 1; | 336 int pool = 1; |
| 336 | 337 |
| 337 const int count = 3; | 338 const int count = 3; |
| 338 for (int i = 0; i < count; ++i) | 339 for (int i = 0; i < count; ++i) |
| 339 m_resourceProvider->createResource(pool, size, format, CCResourceProvide
r::TextureUsageAny); | 340 m_resourceProvider->createResource(pool, size, format, CCResourceProvide
r::TextureUsageAny); |
| 340 expectNumResources(3); | 341 expectNumResources(3); |
| 341 | 342 |
| 342 m_resourceProvider->deleteOwnedResources(pool+1); | 343 m_resourceProvider->deleteOwnedResources(pool+1); |
| 343 expectNumResources(3); | 344 expectNumResources(3); |
| 344 | 345 |
| 345 m_resourceProvider->deleteOwnedResources(pool); | 346 m_resourceProvider->deleteOwnedResources(pool); |
| 346 expectNumResources(0); | 347 expectNumResources(0); |
| 347 } | 348 } |
| 348 | 349 |
| 349 TEST_P(CCResourceProviderTest, Upload) | 350 TEST_P(CCResourceProviderTest, Upload) |
| 350 { | 351 { |
| 351 IntSize size(2, 2); | 352 IntSize size(2, 2); |
| 352 WGC3Denum format = GraphicsContext3D::RGBA; | 353 WGC3Denum format = GL_RGBA; |
| 353 int pool = 1; | 354 int pool = 1; |
| 354 size_t pixelSize = textureSize(size, format); | 355 size_t pixelSize = textureSize(size, format); |
| 355 ASSERT_EQ(16U, pixelSize); | 356 ASSERT_EQ(16U, pixelSize); |
| 356 | 357 |
| 357 CCResourceProvider::ResourceId id = m_resourceProvider->createResource(pool,
size, format, CCResourceProvider::TextureUsageAny); | 358 CCResourceProvider::ResourceId id = m_resourceProvider->createResource(pool,
size, format, CCResourceProvider::TextureUsageAny); |
| 358 | 359 |
| 359 uint8_t image[16] = {0}; | 360 uint8_t image[16] = {0}; |
| 360 IntRect imageRect(IntPoint(), size); | 361 IntRect imageRect(IntPoint(), size); |
| 361 m_resourceProvider->upload(id, image, imageRect, imageRect, IntSize()); | 362 m_resourceProvider->upload(id, image, imageRect, imageRect, IntSize()); |
| 362 | 363 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 TEST_P(CCResourceProviderTest, TransferResources) | 414 TEST_P(CCResourceProviderTest, TransferResources) |
| 414 { | 415 { |
| 415 // Resource transfer is only supported with GL textures for now. | 416 // Resource transfer is only supported with GL textures for now. |
| 416 if (GetParam() != CCResourceProvider::GLTexture) | 417 if (GetParam() != CCResourceProvider::GLTexture) |
| 417 return; | 418 return; |
| 418 | 419 |
| 419 scoped_ptr<CCGraphicsContext> childContext(FakeWebCompositorOutputSurface::c
reate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGrap
hicsContext3D>())); | 420 scoped_ptr<CCGraphicsContext> childContext(FakeWebCompositorOutputSurface::c
reate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGrap
hicsContext3D>())); |
| 420 scoped_ptr<CCResourceProvider> childResourceProvider(CCResourceProvider::cre
ate(childContext.get())); | 421 scoped_ptr<CCResourceProvider> childResourceProvider(CCResourceProvider::cre
ate(childContext.get())); |
| 421 | 422 |
| 422 IntSize size(1, 1); | 423 IntSize size(1, 1); |
| 423 WGC3Denum format = GraphicsContext3D::RGBA; | 424 WGC3Denum format = GL_RGBA; |
| 424 int pool = 1; | 425 int pool = 1; |
| 425 size_t pixelSize = textureSize(size, format); | 426 size_t pixelSize = textureSize(size, format); |
| 426 ASSERT_EQ(4U, pixelSize); | 427 ASSERT_EQ(4U, pixelSize); |
| 427 | 428 |
| 428 CCResourceProvider::ResourceId id1 = childResourceProvider->createResource(p
ool, size, format, CCResourceProvider::TextureUsageAny); | 429 CCResourceProvider::ResourceId id1 = childResourceProvider->createResource(p
ool, size, format, CCResourceProvider::TextureUsageAny); |
| 429 uint8_t data1[4] = {1, 2, 3, 4}; | 430 uint8_t data1[4] = {1, 2, 3, 4}; |
| 430 IntRect rect(IntPoint(), size); | 431 IntRect rect(IntPoint(), size); |
| 431 childResourceProvider->upload(id1, data1, rect, rect, IntSize()); | 432 childResourceProvider->upload(id1, data1, rect, rect, IntSize()); |
| 432 | 433 |
| 433 CCResourceProvider::ResourceId id2 = childResourceProvider->createResource(p
ool, size, format, CCResourceProvider::TextureUsageAny); | 434 CCResourceProvider::ResourceId id2 = childResourceProvider->createResource(p
ool, size, format, CCResourceProvider::TextureUsageAny); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 490 } |
| 490 EXPECT_EQ(0u, m_resourceProvider->mailboxCount()); | 491 EXPECT_EQ(0u, m_resourceProvider->mailboxCount()); |
| 491 EXPECT_EQ(2u, childResourceProvider->mailboxCount()); | 492 EXPECT_EQ(2u, childResourceProvider->mailboxCount()); |
| 492 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id1)); | 493 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id1)); |
| 493 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id2)); | 494 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id2)); |
| 494 | 495 |
| 495 ResourceProviderContext* childContext3D = static_cast<ResourceProviderContex
t*>(childContext->context3D()); | 496 ResourceProviderContext* childContext3D = static_cast<ResourceProviderContex
t*>(childContext->context3D()); |
| 496 { | 497 { |
| 497 CCResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), i
d1); | 498 CCResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), i
d1); |
| 498 ASSERT_NE(0U, lock.textureId()); | 499 ASSERT_NE(0U, lock.textureId()); |
| 499 childContext3D->bindTexture(GraphicsContext3D::TEXTURE_2D, lock.textureI
d()); | 500 childContext3D->bindTexture(GL_TEXTURE_2D, lock.textureId()); |
| 500 childContext3D->getPixels(size, format, result); | 501 childContext3D->getPixels(size, format, result); |
| 501 EXPECT_EQ(0, memcmp(data1, result, pixelSize)); | 502 EXPECT_EQ(0, memcmp(data1, result, pixelSize)); |
| 502 } | 503 } |
| 503 { | 504 { |
| 504 CCResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), i
d2); | 505 CCResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), i
d2); |
| 505 ASSERT_NE(0U, lock.textureId()); | 506 ASSERT_NE(0U, lock.textureId()); |
| 506 childContext3D->bindTexture(GraphicsContext3D::TEXTURE_2D, lock.textureI
d()); | 507 childContext3D->bindTexture(GL_TEXTURE_2D, lock.textureId()); |
| 507 childContext3D->getPixels(size, format, result); | 508 childContext3D->getPixels(size, format, result); |
| 508 EXPECT_EQ(0, memcmp(data2, result, pixelSize)); | 509 EXPECT_EQ(0, memcmp(data2, result, pixelSize)); |
| 509 } | 510 } |
| 510 | 511 |
| 511 { | 512 { |
| 512 // Transfer resources to the parent again. | 513 // Transfer resources to the parent again. |
| 513 CCResourceProvider::ResourceIdArray resourceIdsToTransfer; | 514 CCResourceProvider::ResourceIdArray resourceIdsToTransfer; |
| 514 resourceIdsToTransfer.push_back(id1); | 515 resourceIdsToTransfer.push_back(id1); |
| 515 resourceIdsToTransfer.push_back(id2); | 516 resourceIdsToTransfer.push_back(id2); |
| 516 CCResourceProvider::TransferableResourceList list = childResourceProvide
r->prepareSendToParent(resourceIdsToTransfer); | 517 CCResourceProvider::TransferableResourceList list = childResourceProvide
r->prepareSendToParent(resourceIdsToTransfer); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 530 TEST_P(CCResourceProviderTest, DeleteTransferredResources) | 531 TEST_P(CCResourceProviderTest, DeleteTransferredResources) |
| 531 { | 532 { |
| 532 // Resource transfer is only supported with GL textures for now. | 533 // Resource transfer is only supported with GL textures for now. |
| 533 if (GetParam() != CCResourceProvider::GLTexture) | 534 if (GetParam() != CCResourceProvider::GLTexture) |
| 534 return; | 535 return; |
| 535 | 536 |
| 536 scoped_ptr<CCGraphicsContext> childContext(FakeWebCompositorOutputSurface::c
reate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGrap
hicsContext3D>())); | 537 scoped_ptr<CCGraphicsContext> childContext(FakeWebCompositorOutputSurface::c
reate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGrap
hicsContext3D>())); |
| 537 scoped_ptr<CCResourceProvider> childResourceProvider(CCResourceProvider::cre
ate(childContext.get())); | 538 scoped_ptr<CCResourceProvider> childResourceProvider(CCResourceProvider::cre
ate(childContext.get())); |
| 538 | 539 |
| 539 IntSize size(1, 1); | 540 IntSize size(1, 1); |
| 540 WGC3Denum format = GraphicsContext3D::RGBA; | 541 WGC3Denum format = GL_RGBA; |
| 541 int pool = 1; | 542 int pool = 1; |
| 542 size_t pixelSize = textureSize(size, format); | 543 size_t pixelSize = textureSize(size, format); |
| 543 ASSERT_EQ(4U, pixelSize); | 544 ASSERT_EQ(4U, pixelSize); |
| 544 | 545 |
| 545 CCResourceProvider::ResourceId id = childResourceProvider->createResource(po
ol, size, format, CCResourceProvider::TextureUsageAny); | 546 CCResourceProvider::ResourceId id = childResourceProvider->createResource(po
ol, size, format, CCResourceProvider::TextureUsageAny); |
| 546 uint8_t data[4] = {1, 2, 3, 4}; | 547 uint8_t data[4] = {1, 2, 3, 4}; |
| 547 IntRect rect(IntPoint(), size); | 548 IntRect rect(IntPoint(), size); |
| 548 childResourceProvider->upload(id, data, rect, rect, IntSize()); | 549 childResourceProvider->upload(id, data, rect, rect, IntSize()); |
| 549 | 550 |
| 550 int childPool = 2; | 551 int childPool = 2; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 579 } | 580 } |
| 580 EXPECT_EQ(0u, childResourceProvider->numResources()); | 581 EXPECT_EQ(0u, childResourceProvider->numResources()); |
| 581 } | 582 } |
| 582 | 583 |
| 583 INSTANTIATE_TEST_CASE_P(CCResourceProviderTests, | 584 INSTANTIATE_TEST_CASE_P(CCResourceProviderTests, |
| 584 CCResourceProviderTest, | 585 CCResourceProviderTest, |
| 585 ::testing::Values(CCResourceProvider::GLTexture, | 586 ::testing::Values(CCResourceProvider::GLTexture, |
| 586 CCResourceProvider::Bitmap)); | 587 CCResourceProvider::Bitmap)); |
| 587 | 588 |
| 588 } // namespace | 589 } // namespace |
| OLD | NEW |