Chromium Code Reviews| 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 "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 std::fill_n(pixels, size.GetArea(), value); | 87 std::fill_n(pixels, size.GetArea(), value); |
| 88 return shared_memory.Pass(); | 88 return shared_memory.Pass(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 91 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
| 92 public: | 92 public: |
| 93 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); | 93 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); |
| 94 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); | 94 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); |
| 95 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); | 95 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); |
| 96 MOCK_METHOD0(insertSyncPoint, GLuint(void)); | 96 MOCK_METHOD0(insertSyncPoint, GLuint(void)); |
| 97 MOCK_METHOD2(produceTextureCHROMIUM, | 97 MOCK_METHOD3(produceTextureDirectCHROMIUM, |
| 98 void(GLenum target, const GLbyte* mailbox)); | 98 void(GLuint texture, GLenum target, const GLbyte* mailbox)); |
| 99 MOCK_METHOD2(consumeTextureCHROMIUM, | 99 MOCK_METHOD2(createAndConsumeTextureCHROMIUM, |
| 100 void(GLenum target, const GLbyte* mailbox)); | 100 GLuint(GLenum target, const GLbyte* mailbox)); |
| 101 | 101 |
| 102 // Force all textures to be consecutive numbers starting at "1", | 102 // Force all textures to be consecutive numbers starting at "1", |
| 103 // so we easily can test for them. | 103 // so we easily can test for them. |
| 104 virtual GLuint NextTextureId() override { | 104 virtual GLuint NextTextureId() override { |
| 105 base::AutoLock lock(namespace_->lock); | 105 base::AutoLock lock(namespace_->lock); |
| 106 return namespace_->next_texture_id++; | 106 return namespace_->next_texture_id++; |
| 107 } | 107 } |
| 108 virtual void RetireTextureId(GLuint) override {} | 108 virtual void RetireTextureId(GLuint) override {} |
| 109 }; | 109 }; |
| 110 | 110 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); | 187 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); |
| 188 } | 188 } |
| 189 | 189 |
| 190 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } | 190 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } |
| 191 | 191 |
| 192 virtual void texStorage2DEXT(GLenum target, | 192 virtual void texStorage2DEXT(GLenum target, |
| 193 GLint levels, | 193 GLint levels, |
| 194 GLuint internalformat, | 194 GLuint internalformat, |
| 195 GLint width, | 195 GLint width, |
| 196 GLint height) override { | 196 GLint height) override { |
| 197 CheckTextureIsBound(target); | |
|
danakj
2014/10/15 16:46:19
why is this removed? this function is not bindless
sohanjg
2014/10/16 10:33:20
Done.
Yea, i had just removed all occurrences of
| |
| 198 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 197 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 199 ASSERT_EQ(1, levels); | 198 ASSERT_EQ(1, levels); |
| 200 GLenum format = GL_RGBA; | 199 GLenum format = GL_RGBA; |
| 201 switch (internalformat) { | 200 switch (internalformat) { |
| 202 case GL_RGBA8_OES: | 201 case GL_RGBA8_OES: |
| 203 break; | 202 break; |
| 204 case GL_BGRA8_EXT: | 203 case GL_BGRA8_EXT: |
| 205 format = GL_BGRA_EXT; | 204 format = GL_BGRA_EXT; |
| 206 break; | 205 break; |
| 207 default: | 206 default: |
| 208 NOTREACHED(); | 207 NOTREACHED(); |
| 209 } | 208 } |
| 210 AllocateTexture(gfx::Size(width, height), format); | 209 AllocateTexture(gfx::Size(width, height), format); |
| 211 } | 210 } |
| 212 | 211 |
| 213 virtual void texImage2D(GLenum target, | 212 virtual void texImage2D(GLenum target, |
| 214 GLint level, | 213 GLint level, |
| 215 GLenum internalformat, | 214 GLenum internalformat, |
| 216 GLsizei width, | 215 GLsizei width, |
| 217 GLsizei height, | 216 GLsizei height, |
| 218 GLint border, | 217 GLint border, |
| 219 GLenum format, | 218 GLenum format, |
| 220 GLenum type, | 219 GLenum type, |
| 221 const void* pixels) override { | 220 const void* pixels) override { |
| 222 CheckTextureIsBound(target); | |
|
danakj
2014/10/15 16:46:19
same
sohanjg
2014/10/16 10:33:21
Done.
| |
| 223 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 221 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 224 ASSERT_FALSE(level); | 222 ASSERT_FALSE(level); |
| 225 ASSERT_EQ(internalformat, format); | 223 ASSERT_EQ(internalformat, format); |
| 226 ASSERT_FALSE(border); | 224 ASSERT_FALSE(border); |
| 227 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 225 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
| 228 AllocateTexture(gfx::Size(width, height), format); | 226 AllocateTexture(gfx::Size(width, height), format); |
|
danakj
2014/10/15 16:46:19
why don't you make this function get the texture a
sohanjg
2014/10/16 10:33:20
Acknowledged.
I was trying to remove the bind cal
| |
| 229 if (pixels) | 227 if (pixels) |
| 230 SetPixels(0, 0, width, height, pixels); | 228 SetPixels(0, 0, width, height, pixels); |
| 231 } | 229 } |
| 232 | 230 |
| 231 virtual void texImage2DEXT(GLenum target, | |
|
danakj
2014/10/15 16:46:19
this isn't a member of TestWGC3D, we shouldn't add
sohanjg
2014/10/16 10:33:21
Acknowledged.
Removed.
| |
| 232 GLint level, | |
| 233 GLenum internalformat, | |
| 234 GLsizei width, | |
| 235 GLsizei height, | |
| 236 GLint border, | |
| 237 GLenum format, | |
| 238 GLenum type, | |
| 239 const void* pixels, | |
| 240 GLuint id) { | |
| 241 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | |
| 242 ASSERT_FALSE(level); | |
| 243 ASSERT_EQ(internalformat, format); | |
| 244 ASSERT_FALSE(border); | |
| 245 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | |
| 246 AllocateUnboundTexture(gfx::Size(width, height), format, id); | |
| 247 if (pixels) | |
| 248 SetPixelsEXT(0, 0, width, height, pixels, id); | |
| 249 } | |
| 250 | |
| 233 virtual void texSubImage2D(GLenum target, | 251 virtual void texSubImage2D(GLenum target, |
| 234 GLint level, | 252 GLint level, |
| 235 GLint xoffset, | 253 GLint xoffset, |
| 236 GLint yoffset, | 254 GLint yoffset, |
| 237 GLsizei width, | 255 GLsizei width, |
| 238 GLsizei height, | 256 GLsizei height, |
| 239 GLenum format, | 257 GLenum format, |
| 240 GLenum type, | 258 GLenum type, |
| 241 const void* pixels) override { | 259 const void* pixels) override { |
| 242 CheckTextureIsBound(target); | |
|
danakj
2014/10/15 16:46:19
same
sohanjg
2014/10/16 10:33:20
Done.
| |
| 243 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 260 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 244 ASSERT_FALSE(level); | 261 ASSERT_FALSE(level); |
| 245 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 262 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
| 246 { | 263 { |
| 247 base::AutoLock lock_for_texture_access(namespace_->lock); | 264 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 248 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); | 265 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); |
| 249 } | 266 } |
| 250 ASSERT_TRUE(pixels); | 267 ASSERT_TRUE(pixels); |
| 251 SetPixels(xoffset, yoffset, width, height, pixels); | 268 SetPixels(xoffset, yoffset, width, height, pixels); |
| 252 } | 269 } |
| 253 | 270 |
| 254 virtual void genMailboxCHROMIUM(GLbyte* mailbox) override { | 271 virtual void genMailboxCHROMIUM(GLbyte* mailbox) override { |
| 255 return shared_data_->GenMailbox(mailbox); | 272 return shared_data_->GenMailbox(mailbox); |
| 256 } | 273 } |
| 257 | 274 |
| 258 virtual void produceTextureCHROMIUM(GLenum target, | 275 virtual void produceTextureDirectCHROMIUM(GLuint texture, |
| 259 const GLbyte* mailbox) override { | 276 GLenum target, |
| 260 CheckTextureIsBound(target); | 277 const GLbyte* mailbox) override { |
| 261 | |
| 262 // Delay moving the texture into the mailbox until the next | 278 // Delay moving the texture into the mailbox until the next |
| 263 // InsertSyncPoint, so that it is not visible to other contexts that | 279 // InsertSyncPoint, so that it is not visible to other contexts that |
| 264 // haven't waited on that sync point. | 280 // haven't waited on that sync point. |
| 265 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); | 281 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); |
| 266 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 282 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
| 267 base::AutoLock lock_for_texture_access(namespace_->lock); | 283 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 268 pending->texture = BoundTexture(target); | 284 pending->texture = UnboundTexture(texture); |
| 269 pending_produce_textures_.push_back(pending.Pass()); | 285 pending_produce_textures_.push_back(pending.Pass()); |
| 270 } | 286 } |
| 271 | 287 |
| 272 virtual void consumeTextureCHROMIUM(GLenum target, | 288 virtual GLuint createAndConsumeTextureCHROMIUM(GLenum target, |
| 273 const GLbyte* mailbox) override { | 289 const GLbyte* mailbox) { |
| 274 CheckTextureIsBound(target); | 290 GLuint texture_id = |
| 275 base::AutoLock lock_for_texture_access(namespace_->lock); | 291 TestWebGraphicsContext3D::createAndConsumeTextureCHROMIUM(target, |
|
danakj
2014/10/15 16:46:19
you need to lock if you're going to access the nam
sohanjg
2014/10/16 10:33:21
Done.
| |
| 276 scoped_refptr<TestTexture> texture = | 292 mailbox); |
| 277 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); | 293 namespace_->textures.Replace(texture_id, |
| 278 namespace_->textures.Replace(BoundTextureId(target), texture); | 294 namespace_->textures.TextureForId(texture_id)); |
| 295 return texture_id; | |
| 279 } | 296 } |
| 280 | 297 |
| 281 void GetPixels(const gfx::Size& size, | 298 void GetPixels(const gfx::Size& size, |
| 282 ResourceFormat format, | 299 ResourceFormat format, |
| 283 uint8_t* pixels) { | 300 uint8_t* pixels) { |
| 284 CheckTextureIsBound(GL_TEXTURE_2D); | |
|
danakj
2014/10/15 16:46:19
same
sohanjg
2014/10/16 10:33:20
Done.
| |
| 285 base::AutoLock lock_for_texture_access(namespace_->lock); | 301 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 286 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); | 302 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); |
| 287 ASSERT_EQ(texture->size, size); | 303 ASSERT_EQ(texture->size, size); |
| 288 ASSERT_EQ(texture->format, format); | 304 ASSERT_EQ(texture->format, format); |
| 289 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format)); | 305 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format)); |
| 290 } | 306 } |
| 291 | 307 |
| 292 protected: | 308 protected: |
| 293 explicit ResourceProviderContext(ContextSharedData* shared_data) | 309 explicit ResourceProviderContext(ContextSharedData* shared_data) |
| 294 : shared_data_(shared_data), | 310 : shared_data_(shared_data), |
| 295 last_waited_sync_point_(0) {} | 311 last_waited_sync_point_(0) {} |
| 296 | 312 |
| 297 private: | 313 private: |
| 298 void AllocateTexture(const gfx::Size& size, GLenum format) { | 314 void AllocateTexture(const gfx::Size& size, GLenum format) { |
| 299 CheckTextureIsBound(GL_TEXTURE_2D); | 315 CheckTextureIsBound(GL_TEXTURE_2D); |
| 300 ResourceFormat texture_format = RGBA_8888; | 316 ResourceFormat texture_format = RGBA_8888; |
| 301 switch (format) { | 317 switch (format) { |
| 302 case GL_RGBA: | 318 case GL_RGBA: |
| 303 texture_format = RGBA_8888; | 319 texture_format = RGBA_8888; |
| 304 break; | 320 break; |
| 305 case GL_BGRA_EXT: | 321 case GL_BGRA_EXT: |
| 306 texture_format = BGRA_8888; | 322 texture_format = BGRA_8888; |
| 307 break; | 323 break; |
| 308 } | 324 } |
| 309 base::AutoLock lock_for_texture_access(namespace_->lock); | 325 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 310 BoundTexture(GL_TEXTURE_2D)->Reallocate(size, texture_format); | 326 BoundTexture(GL_TEXTURE_2D)->Reallocate(size, texture_format); |
| 311 } | 327 } |
| 312 | 328 |
| 329 void AllocateUnboundTexture(const gfx::Size& size, GLenum format, GLuint id) { | |
| 330 ResourceFormat texture_format = RGBA_8888; | |
| 331 switch (format) { | |
| 332 case GL_RGBA: | |
| 333 texture_format = RGBA_8888; | |
| 334 break; | |
| 335 case GL_BGRA_EXT: | |
| 336 texture_format = BGRA_8888; | |
| 337 break; | |
| 338 } | |
| 339 base::AutoLock lock_for_texture_access(namespace_->lock); | |
| 340 UnboundTexture(id)->Reallocate(size, texture_format); | |
| 341 } | |
| 342 | |
| 313 void SetPixels(int xoffset, | 343 void SetPixels(int xoffset, |
| 314 int yoffset, | 344 int yoffset, |
| 315 int width, | 345 int width, |
| 316 int height, | 346 int height, |
| 317 const void* pixels) { | 347 const void* pixels) { |
| 318 CheckTextureIsBound(GL_TEXTURE_2D); | 348 CheckTextureIsBound(GL_TEXTURE_2D); |
| 319 base::AutoLock lock_for_texture_access(namespace_->lock); | 349 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 320 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); | 350 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); |
| 321 ASSERT_TRUE(texture->data.get()); | 351 ASSERT_TRUE(texture->data.get()); |
| 322 ASSERT_TRUE(xoffset >= 0 && xoffset + width <= texture->size.width()); | 352 ASSERT_TRUE(xoffset >= 0 && xoffset + width <= texture->size.width()); |
| 323 ASSERT_TRUE(yoffset >= 0 && yoffset + height <= texture->size.height()); | 353 ASSERT_TRUE(yoffset >= 0 && yoffset + height <= texture->size.height()); |
| 324 ASSERT_TRUE(pixels); | 354 ASSERT_TRUE(pixels); |
| 325 size_t in_pitch = TextureSizeBytes(gfx::Size(width, 1), texture->format); | 355 size_t in_pitch = TextureSizeBytes(gfx::Size(width, 1), texture->format); |
| 326 size_t out_pitch = | 356 size_t out_pitch = |
| 327 TextureSizeBytes(gfx::Size(texture->size.width(), 1), texture->format); | 357 TextureSizeBytes(gfx::Size(texture->size.width(), 1), texture->format); |
| 328 uint8_t* dest = texture->data.get() + yoffset * out_pitch + | 358 uint8_t* dest = texture->data.get() + yoffset * out_pitch + |
| 329 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format); | 359 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format); |
| 330 const uint8_t* src = static_cast<const uint8_t*>(pixels); | 360 const uint8_t* src = static_cast<const uint8_t*>(pixels); |
| 331 for (int i = 0; i < height; ++i) { | 361 for (int i = 0; i < height; ++i) { |
| 332 memcpy(dest, src, in_pitch); | 362 memcpy(dest, src, in_pitch); |
| 333 dest += out_pitch; | 363 dest += out_pitch; |
| 334 src += in_pitch; | 364 src += in_pitch; |
| 335 } | 365 } |
| 336 } | 366 } |
| 337 | 367 |
| 368 void SetPixelsEXT(int xoffset, | |
| 369 int yoffset, | |
| 370 int width, | |
| 371 int height, | |
| 372 const void* pixels, | |
| 373 GLuint id) { | |
| 374 base::AutoLock lock_for_texture_access(namespace_->lock); | |
| 375 scoped_refptr<TestTexture> texture = UnboundTexture(id); | |
| 376 ASSERT_TRUE(texture->data.get()); | |
| 377 ASSERT_TRUE(xoffset >= 0 && xoffset + width <= texture->size.width()); | |
| 378 ASSERT_TRUE(yoffset >= 0 && yoffset + height <= texture->size.height()); | |
| 379 ASSERT_TRUE(pixels); | |
| 380 size_t in_pitch = TextureSizeBytes(gfx::Size(width, 1), texture->format); | |
| 381 size_t out_pitch = | |
| 382 TextureSizeBytes(gfx::Size(texture->size.width(), 1), texture->format); | |
| 383 uint8_t* dest = texture->data.get() + yoffset * out_pitch + | |
| 384 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format); | |
| 385 const uint8_t* src = static_cast<const uint8_t*>(pixels); | |
| 386 for (int i = 0; i < height; ++i) { | |
| 387 memcpy(dest, src, in_pitch); | |
| 388 dest += out_pitch; | |
| 389 src += in_pitch; | |
| 390 } | |
| 391 } | |
| 392 | |
| 338 struct PendingProduceTexture { | 393 struct PendingProduceTexture { |
| 339 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; | 394 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; |
| 340 scoped_refptr<TestTexture> texture; | 395 scoped_refptr<TestTexture> texture; |
| 341 }; | 396 }; |
| 342 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; | 397 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; |
| 343 ContextSharedData* shared_data_; | 398 ContextSharedData* shared_data_; |
| 344 GLuint last_waited_sync_point_; | 399 GLuint last_waited_sync_point_; |
| 345 PendingProduceTextureList pending_produce_textures_; | 400 PendingProduceTextureList pending_produce_textures_; |
| 346 }; | 401 }; |
| 347 | 402 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 | 507 |
| 453 ResourceProviderContext* context() { return context3d_; } | 508 ResourceProviderContext* context() { return context3d_; } |
| 454 | 509 |
| 455 ResourceProvider::ResourceId CreateChildMailbox(uint32* release_sync_point, | 510 ResourceProvider::ResourceId CreateChildMailbox(uint32* release_sync_point, |
| 456 bool* lost_resource, | 511 bool* lost_resource, |
| 457 bool* release_called, | 512 bool* release_called, |
| 458 uint32* sync_point) { | 513 uint32* sync_point) { |
| 459 if (GetParam() == ResourceProvider::GLTexture) { | 514 if (GetParam() == ResourceProvider::GLTexture) { |
| 460 unsigned texture = child_context_->createTexture(); | 515 unsigned texture = child_context_->createTexture(); |
| 461 gpu::Mailbox gpu_mailbox; | 516 gpu::Mailbox gpu_mailbox; |
| 462 child_context_->bindTexture(GL_TEXTURE_2D, texture); | |
| 463 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); | 517 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); |
| 464 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name); | 518 child_context_->produceTextureDirectCHROMIUM( |
| 519 texture, GL_TEXTURE_2D, gpu_mailbox.name); | |
| 465 *sync_point = child_context_->insertSyncPoint(); | 520 *sync_point = child_context_->insertSyncPoint(); |
| 466 EXPECT_LT(0u, *sync_point); | 521 EXPECT_LT(0u, *sync_point); |
| 467 | 522 |
| 468 scoped_ptr<base::SharedMemory> shared_memory; | 523 scoped_ptr<base::SharedMemory> shared_memory; |
| 469 scoped_ptr<SingleReleaseCallbackImpl> callback = | 524 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 470 SingleReleaseCallbackImpl::Create( | 525 SingleReleaseCallbackImpl::Create( |
| 471 base::Bind(ReleaseSharedMemoryCallback, | 526 base::Bind(ReleaseSharedMemoryCallback, |
| 472 base::Passed(&shared_memory), | 527 base::Passed(&shared_memory), |
| 473 release_called, | 528 release_called, |
| 474 release_sync_point, | 529 release_sync_point, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 | 687 |
| 633 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( | 688 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( |
| 634 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 689 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
| 635 { | 690 { |
| 636 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( | 691 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( |
| 637 child_resource_provider_.get(), id3); | 692 child_resource_provider_.get(), id3); |
| 638 EXPECT_TRUE(!!lock.gpu_memory_buffer()); | 693 EXPECT_TRUE(!!lock.gpu_memory_buffer()); |
| 639 } | 694 } |
| 640 | 695 |
| 641 GLuint external_texture_id = child_context_->createExternalTexture(); | 696 GLuint external_texture_id = child_context_->createExternalTexture(); |
| 642 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); | |
| 643 | 697 |
| 644 gpu::Mailbox external_mailbox; | 698 gpu::Mailbox external_mailbox; |
| 645 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 699 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
| 646 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, | 700 child_context_->produceTextureDirectCHROMIUM( |
| 647 external_mailbox.name); | 701 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); |
| 648 const GLuint external_sync_point = child_context_->insertSyncPoint(); | 702 const GLuint external_sync_point = child_context_->insertSyncPoint(); |
| 649 ResourceProvider::ResourceId id4 = | 703 ResourceProvider::ResourceId id4 = |
| 650 child_resource_provider_->CreateResourceFromTextureMailbox( | 704 child_resource_provider_->CreateResourceFromTextureMailbox( |
| 651 TextureMailbox( | 705 TextureMailbox( |
| 652 external_mailbox, GL_TEXTURE_EXTERNAL_OES, external_sync_point), | 706 external_mailbox, GL_TEXTURE_EXTERNAL_OES, external_sync_point), |
| 653 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); | 707 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); |
| 654 | 708 |
| 655 ReturnedResourceArray returned_to_child; | 709 ReturnedResourceArray returned_to_child; |
| 656 int child_id = | 710 int child_id = |
| 657 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); | 711 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 EXPECT_NE(0u, mapped_id1); | 764 EXPECT_NE(0u, mapped_id1); |
| 711 EXPECT_NE(0u, mapped_id2); | 765 EXPECT_NE(0u, mapped_id2); |
| 712 EXPECT_NE(0u, mapped_id3); | 766 EXPECT_NE(0u, mapped_id3); |
| 713 EXPECT_NE(0u, mapped_id4); | 767 EXPECT_NE(0u, mapped_id4); |
| 714 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); | 768 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); |
| 715 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); | 769 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); |
| 716 EXPECT_FALSE(resource_provider_->InUseByConsumer(id3)); | 770 EXPECT_FALSE(resource_provider_->InUseByConsumer(id3)); |
| 717 EXPECT_FALSE(resource_provider_->InUseByConsumer(id4)); | 771 EXPECT_FALSE(resource_provider_->InUseByConsumer(id4)); |
| 718 | 772 |
| 719 uint8_t result[4] = { 0 }; | 773 uint8_t result[4] = { 0 }; |
| 720 GetResourcePixels( | |
| 721 resource_provider_.get(), context(), mapped_id1, size, format, result); | |
| 722 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); | |
| 723 | |
| 724 GetResourcePixels( | |
| 725 resource_provider_.get(), context(), mapped_id2, size, format, result); | |
| 726 EXPECT_EQ(0, memcmp(data2, result, pixel_size)); | |
| 727 | 774 |
| 728 { | 775 { |
| 729 // Check that transfering again the same resource from the child to the | 776 // Check that transfering again the same resource from the child to the |
| 730 // parent works. | 777 // parent works. |
| 731 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 778 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 732 resource_ids_to_transfer.push_back(id1); | 779 resource_ids_to_transfer.push_back(id1); |
| 733 resource_ids_to_transfer.push_back(id2); | 780 resource_ids_to_transfer.push_back(id2); |
| 734 resource_ids_to_transfer.push_back(id3); | 781 resource_ids_to_transfer.push_back(id3); |
| 735 TransferableResourceArray list; | 782 TransferableResourceArray list; |
| 736 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 783 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, | 927 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, |
| 881 &list); | 928 &list); |
| 882 ASSERT_EQ(1u, list.size()); | 929 ASSERT_EQ(1u, list.size()); |
| 883 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 930 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
| 884 | 931 |
| 885 resource_provider_->ReceiveFromChild(child_id, list); | 932 resource_provider_->ReceiveFromChild(child_id, list); |
| 886 | 933 |
| 887 resource_provider_->WaitSyncPointIfNeeded(list[0].id); | 934 resource_provider_->WaitSyncPointIfNeeded(list[0].id); |
| 888 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), | 935 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), |
| 889 list[0].id); | 936 list[0].id); |
| 890 | |
| 891 resource_provider_->DeclareUsedResourcesFromChild( | 937 resource_provider_->DeclareUsedResourcesFromChild( |
| 892 child_id, ResourceProvider::ResourceIdArray()); | 938 child_id, ResourceProvider::ResourceIdArray()); |
| 893 EXPECT_EQ(0u, returned_to_child.size()); | 939 EXPECT_EQ(0u, returned_to_child.size()); |
| 894 } | 940 } |
| 895 | 941 |
| 896 EXPECT_EQ(1u, returned_to_child.size()); | 942 EXPECT_EQ(1u, returned_to_child.size()); |
| 897 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); | 943 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); |
| 898 | 944 |
| 899 { | 945 { |
| 900 child_resource_provider_->WaitSyncPointIfNeeded(id1); | 946 child_resource_provider_->WaitSyncPointIfNeeded(id1); |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1719 | 1765 |
| 1720 ReturnedResourceArray returned_to_child; | 1766 ReturnedResourceArray returned_to_child; |
| 1721 int child_id = parent_resource_provider->CreateChild( | 1767 int child_id = parent_resource_provider->CreateChild( |
| 1722 GetReturnCallback(&returned_to_child)); | 1768 GetReturnCallback(&returned_to_child)); |
| 1723 { | 1769 { |
| 1724 // Transfer some resource to the parent. | 1770 // Transfer some resource to the parent. |
| 1725 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1771 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1726 resource_ids_to_transfer.push_back(id); | 1772 resource_ids_to_transfer.push_back(id); |
| 1727 TransferableResourceArray list; | 1773 TransferableResourceArray list; |
| 1728 | 1774 |
| 1729 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)); | |
| 1730 EXPECT_CALL(*child_context, | 1775 EXPECT_CALL(*child_context, |
| 1731 produceTextureCHROMIUM(GL_TEXTURE_2D, _)); | 1776 produceTextureDirectCHROMIUM(_, GL_TEXTURE_2D, _)); |
| 1732 EXPECT_CALL(*child_context, insertSyncPoint()); | 1777 EXPECT_CALL(*child_context, insertSyncPoint()); |
| 1733 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, | 1778 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, |
| 1734 &list); | 1779 &list); |
| 1735 Mock::VerifyAndClearExpectations(child_context); | 1780 Mock::VerifyAndClearExpectations(child_context); |
| 1736 | 1781 |
| 1737 ASSERT_EQ(1u, list.size()); | 1782 ASSERT_EQ(1u, list.size()); |
| 1738 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter); | 1783 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter); |
| 1739 | 1784 |
| 1740 EXPECT_CALL(*parent_context, | 1785 EXPECT_CALL(*parent_context, |
| 1741 bindTexture(GL_TEXTURE_2D, parent_texture_id)); | 1786 createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)).Times(0); |
| 1742 EXPECT_CALL(*parent_context, consumeTextureCHROMIUM(GL_TEXTURE_2D, _)); | |
| 1743 parent_resource_provider->ReceiveFromChild(child_id, list); | 1787 parent_resource_provider->ReceiveFromChild(child_id, list); |
| 1744 { | 1788 { |
| 1745 parent_resource_provider->WaitSyncPointIfNeeded(list[0].id); | 1789 parent_resource_provider->WaitSyncPointIfNeeded(list[0].id); |
| 1746 ResourceProvider::ScopedReadLockGL lock(parent_resource_provider.get(), | 1790 ResourceProvider::ScopedReadLockGL lock(parent_resource_provider.get(), |
| 1747 list[0].id); | 1791 list[0].id); |
| 1748 } | 1792 } |
| 1749 Mock::VerifyAndClearExpectations(parent_context); | 1793 Mock::VerifyAndClearExpectations(parent_context); |
| 1750 | 1794 |
| 1751 parent_resource_provider->DeclareUsedResourcesFromChild( | 1795 parent_resource_provider->DeclareUsedResourcesFromChild( |
| 1752 child_id, resource_ids_to_transfer); | 1796 child_id, resource_ids_to_transfer); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1810 if (GetParam() != ResourceProvider::GLTexture) | 1854 if (GetParam() != ResourceProvider::GLTexture) |
| 1811 return; | 1855 return; |
| 1812 ResourceProviderTestTextureFilters::RunTest(GL_LINEAR, GL_NEAREST); | 1856 ResourceProviderTestTextureFilters::RunTest(GL_LINEAR, GL_NEAREST); |
| 1813 } | 1857 } |
| 1814 | 1858 |
| 1815 TEST_P(ResourceProviderTest, TransferMailboxResources) { | 1859 TEST_P(ResourceProviderTest, TransferMailboxResources) { |
| 1816 // Other mailbox transfers tested elsewhere. | 1860 // Other mailbox transfers tested elsewhere. |
| 1817 if (GetParam() != ResourceProvider::GLTexture) | 1861 if (GetParam() != ResourceProvider::GLTexture) |
| 1818 return; | 1862 return; |
| 1819 unsigned texture = context()->createTexture(); | 1863 unsigned texture = context()->createTexture(); |
| 1820 context()->bindTexture(GL_TEXTURE_2D, texture); | |
| 1821 uint8_t data[4] = { 1, 2, 3, 4 }; | 1864 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 1822 context()->texImage2D( | 1865 context()->texImage2DEXT(GL_TEXTURE_2D, |
| 1823 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); | 1866 0, |
| 1867 GL_RGBA, | |
| 1868 1, | |
| 1869 1, | |
| 1870 0, | |
| 1871 GL_RGBA, | |
| 1872 GL_UNSIGNED_BYTE, | |
| 1873 &data, | |
| 1874 texture); | |
| 1824 gpu::Mailbox mailbox; | 1875 gpu::Mailbox mailbox; |
| 1825 context()->genMailboxCHROMIUM(mailbox.name); | 1876 context()->genMailboxCHROMIUM(mailbox.name); |
| 1826 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1877 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); |
| 1827 uint32 sync_point = context()->insertSyncPoint(); | 1878 uint32 sync_point = context()->insertSyncPoint(); |
| 1828 | 1879 |
| 1829 // All the logic below assumes that the sync points are all positive. | 1880 // All the logic below assumes that the sync points are all positive. |
| 1830 EXPECT_LT(0u, sync_point); | 1881 EXPECT_LT(0u, sync_point); |
| 1831 | 1882 |
| 1832 uint32 release_sync_point = 0; | 1883 uint32 release_sync_point = 0; |
| 1833 bool lost_resource = false; | 1884 bool lost_resource = false; |
| 1834 BlockingTaskRunner* main_thread_task_runner = NULL; | 1885 BlockingTaskRunner* main_thread_task_runner = NULL; |
| 1835 ReleaseCallbackImpl callback = base::Bind(ReleaseCallback, | 1886 ReleaseCallbackImpl callback = base::Bind(ReleaseCallback, |
| 1836 &release_sync_point, | 1887 &release_sync_point, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1850 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1901 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1851 ASSERT_EQ(1u, list.size()); | 1902 ASSERT_EQ(1u, list.size()); |
| 1852 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); | 1903 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); |
| 1853 EXPECT_EQ(0, | 1904 EXPECT_EQ(0, |
| 1854 memcmp(mailbox.name, | 1905 memcmp(mailbox.name, |
| 1855 list[0].mailbox_holder.mailbox.name, | 1906 list[0].mailbox_holder.mailbox.name, |
| 1856 sizeof(mailbox.name))); | 1907 sizeof(mailbox.name))); |
| 1857 EXPECT_EQ(0u, release_sync_point); | 1908 EXPECT_EQ(0u, release_sync_point); |
| 1858 | 1909 |
| 1859 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); | 1910 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); |
| 1860 unsigned other_texture = context()->createTexture(); | 1911 unsigned other_texture = |
| 1861 context()->bindTexture(GL_TEXTURE_2D, other_texture); | 1912 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1862 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1913 |
| 1863 uint8_t test_data[4] = { 0 }; | 1914 context()->produceTextureDirectCHROMIUM( |
| 1864 context()->GetPixels( | 1915 other_texture, GL_TEXTURE_2D, mailbox.name); |
| 1865 gfx::Size(1, 1), RGBA_8888, test_data); | |
| 1866 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | |
| 1867 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 1868 context()->deleteTexture(other_texture); | 1916 context()->deleteTexture(other_texture); |
| 1869 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); | 1917 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); |
| 1870 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); | 1918 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); |
| 1871 | 1919 |
| 1872 // Receive the resource, then delete it, expect the sync points to be | 1920 // Receive the resource, then delete it, expect the sync points to be |
| 1873 // consistent. | 1921 // consistent. |
| 1874 ReturnedResourceArray returned; | 1922 ReturnedResourceArray returned; |
| 1875 TransferableResource::ReturnResources(list, &returned); | 1923 TransferableResource::ReturnResources(list, &returned); |
| 1876 resource_provider_->ReceiveReturnsFromParent(returned); | 1924 resource_provider_->ReceiveReturnsFromParent(returned); |
| 1877 EXPECT_EQ(1u, context()->NumTextures()); | 1925 EXPECT_EQ(1u, context()->NumTextures()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1901 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); | 1949 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1902 ASSERT_EQ(1u, list.size()); | 1950 ASSERT_EQ(1u, list.size()); |
| 1903 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); | 1951 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); |
| 1904 EXPECT_EQ(0, | 1952 EXPECT_EQ(0, |
| 1905 memcmp(mailbox.name, | 1953 memcmp(mailbox.name, |
| 1906 list[0].mailbox_holder.mailbox.name, | 1954 list[0].mailbox_holder.mailbox.name, |
| 1907 sizeof(mailbox.name))); | 1955 sizeof(mailbox.name))); |
| 1908 EXPECT_EQ(0u, release_sync_point); | 1956 EXPECT_EQ(0u, release_sync_point); |
| 1909 | 1957 |
| 1910 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); | 1958 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); |
| 1911 unsigned other_texture = context()->createTexture(); | 1959 unsigned other_texture = |
| 1912 context()->bindTexture(GL_TEXTURE_2D, other_texture); | 1960 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1913 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1961 |
| 1914 uint8_t test_data[4] = { 0 }; | 1962 context()->produceTextureDirectCHROMIUM( |
| 1915 context()->GetPixels( | 1963 other_texture, GL_TEXTURE_2D, mailbox.name); |
| 1916 gfx::Size(1, 1), RGBA_8888, test_data); | |
| 1917 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); | |
| 1918 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | |
| 1919 context()->deleteTexture(other_texture); | 1964 context()->deleteTexture(other_texture); |
| 1920 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); | 1965 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); |
| 1921 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); | 1966 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); |
| 1922 | 1967 |
| 1923 // Delete the resource, which shouldn't do anything. | 1968 // Delete the resource, which shouldn't do anything. |
| 1924 resource_provider_->DeleteResource(resource); | 1969 resource_provider_->DeleteResource(resource); |
| 1925 EXPECT_EQ(1u, context()->NumTextures()); | 1970 EXPECT_EQ(1u, context()->NumTextures()); |
| 1926 EXPECT_EQ(0u, release_sync_point); | 1971 EXPECT_EQ(0u, release_sync_point); |
| 1927 | 1972 |
| 1928 // Then receive the resource which should release the mailbox, expect the | 1973 // Then receive the resource which should release the mailbox, expect the |
| 1929 // sync points to be consistent. | 1974 // sync points to be consistent. |
| 1930 ReturnedResourceArray returned; | 1975 ReturnedResourceArray returned; |
| 1931 TransferableResource::ReturnResources(list, &returned); | 1976 TransferableResource::ReturnResources(list, &returned); |
| 1932 resource_provider_->ReceiveReturnsFromParent(returned); | 1977 resource_provider_->ReceiveReturnsFromParent(returned); |
| 1933 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); | 1978 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); |
| 1934 EXPECT_FALSE(lost_resource); | 1979 EXPECT_FALSE(lost_resource); |
| 1935 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); | 1980 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); |
| 1936 } | 1981 } |
| 1937 | 1982 |
| 1938 context()->waitSyncPoint(release_sync_point); | 1983 context()->waitSyncPoint(release_sync_point); |
| 1939 context()->bindTexture(GL_TEXTURE_2D, texture); | 1984 texture = |
| 1940 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 1985 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 1941 context()->deleteTexture(texture); | 1986 context()->deleteTexture(texture); |
| 1942 } | 1987 } |
| 1943 | 1988 |
| 1944 TEST_P(ResourceProviderTest, LostResourceInParent) { | 1989 TEST_P(ResourceProviderTest, LostResourceInParent) { |
| 1945 gfx::Size size(1, 1); | 1990 gfx::Size size(1, 1); |
| 1946 ResourceFormat format = RGBA_8888; | 1991 ResourceFormat format = RGBA_8888; |
| 1947 ResourceProvider::ResourceId resource = | 1992 ResourceProvider::ResourceId resource = |
| 1948 child_resource_provider_->CreateResource( | 1993 child_resource_provider_->CreateResource( |
| 1949 size, | 1994 size, |
| 1950 GL_CLAMP_TO_EDGE, | 1995 GL_CLAMP_TO_EDGE, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2240 } | 2285 } |
| 2241 | 2286 |
| 2242 TEST_P(ResourceProviderTest, LostContext) { | 2287 TEST_P(ResourceProviderTest, LostContext) { |
| 2243 // TextureMailbox callbacks only exist for GL textures for now. | 2288 // TextureMailbox callbacks only exist for GL textures for now. |
| 2244 if (GetParam() != ResourceProvider::GLTexture) | 2289 if (GetParam() != ResourceProvider::GLTexture) |
| 2245 return; | 2290 return; |
| 2246 unsigned texture = context()->createTexture(); | 2291 unsigned texture = context()->createTexture(); |
| 2247 context()->bindTexture(GL_TEXTURE_2D, texture); | 2292 context()->bindTexture(GL_TEXTURE_2D, texture); |
| 2248 gpu::Mailbox mailbox; | 2293 gpu::Mailbox mailbox; |
| 2249 context()->genMailboxCHROMIUM(mailbox.name); | 2294 context()->genMailboxCHROMIUM(mailbox.name); |
| 2250 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 2295 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); |
| 2251 uint32 sync_point = context()->insertSyncPoint(); | 2296 uint32 sync_point = context()->insertSyncPoint(); |
| 2252 | 2297 |
| 2253 EXPECT_LT(0u, sync_point); | 2298 EXPECT_LT(0u, sync_point); |
| 2254 | 2299 |
| 2255 uint32 release_sync_point = 0; | 2300 uint32 release_sync_point = 0; |
| 2256 bool lost_resource = false; | 2301 bool lost_resource = false; |
| 2257 BlockingTaskRunner* main_thread_task_runner = NULL; | 2302 BlockingTaskRunner* main_thread_task_runner = NULL; |
| 2258 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2303 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2259 SingleReleaseCallbackImpl::Create(base::Bind(ReleaseCallback, | 2304 SingleReleaseCallbackImpl::Create(base::Bind(ReleaseCallback, |
| 2260 &release_sync_point, | 2305 &release_sync_point, |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2617 | 2662 |
| 2618 scoped_ptr<ResourceProvider> resource_provider( | 2663 scoped_ptr<ResourceProvider> resource_provider( |
| 2619 ResourceProvider::Create(output_surface.get(), | 2664 ResourceProvider::Create(output_surface.get(), |
| 2620 shared_bitmap_manager_.get(), | 2665 shared_bitmap_manager_.get(), |
| 2621 main_thread_task_runner_.get(), | 2666 main_thread_task_runner_.get(), |
| 2622 0, | 2667 0, |
| 2623 false, | 2668 false, |
| 2624 1, | 2669 1, |
| 2625 false)); | 2670 false)); |
| 2626 | 2671 |
| 2627 unsigned texture_id = 1; | |
| 2628 uint32 sync_point = 30; | 2672 uint32 sync_point = 30; |
| 2629 unsigned target = GL_TEXTURE_2D; | 2673 unsigned target = GL_TEXTURE_2D; |
| 2630 | 2674 |
| 2631 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2675 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2632 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2676 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2633 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2677 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2634 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2678 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2635 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2679 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2636 | 2680 |
| 2637 gpu::Mailbox gpu_mailbox; | 2681 gpu::Mailbox gpu_mailbox; |
| 2638 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2682 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2639 uint32 release_sync_point = 0; | 2683 uint32 release_sync_point = 0; |
| 2640 bool lost_resource = false; | 2684 bool lost_resource = false; |
| 2641 BlockingTaskRunner* main_thread_task_runner = NULL; | 2685 BlockingTaskRunner* main_thread_task_runner = NULL; |
| 2642 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2686 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2643 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, | 2687 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, |
| 2644 &release_sync_point, | 2688 &release_sync_point, |
| 2645 &lost_resource, | 2689 &lost_resource, |
| 2646 &main_thread_task_runner)); | 2690 &main_thread_task_runner)); |
| 2647 | 2691 |
| 2648 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2692 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2649 | 2693 |
| 2650 ResourceProvider::ResourceId id = | 2694 ResourceProvider::ResourceId id = |
| 2651 resource_provider->CreateResourceFromTextureMailbox( | 2695 resource_provider->CreateResourceFromTextureMailbox( |
| 2652 mailbox, callback.Pass()); | 2696 mailbox, callback.Pass()); |
| 2653 EXPECT_NE(0u, id); | 2697 EXPECT_NE(0u, id); |
| 2654 | 2698 |
| 2655 Mock::VerifyAndClearExpectations(context); | 2699 Mock::VerifyAndClearExpectations(context); |
| 2656 | 2700 |
| 2657 { | 2701 { |
| 2658 // Mailbox sync point WaitSyncPoint before using the texture. | 2702 // Mailbox sync point WaitSyncPoint before using the texture. |
| 2659 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | 2703 EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
| 2660 resource_provider->WaitSyncPointIfNeeded(id); | 2704 resource_provider->WaitSyncPointIfNeeded(id); |
| 2661 Mock::VerifyAndClearExpectations(context); | 2705 Mock::VerifyAndClearExpectations(context); |
| 2662 | 2706 |
| 2663 // Using the texture does a consume of the mailbox. | 2707 // Using the texture does a consume of the mailbox. |
| 2664 EXPECT_CALL(*context, bindTexture(target, texture_id)); | 2708 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)).Times(0); |
| 2665 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); | |
| 2666 | 2709 |
| 2667 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2710 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2668 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2711 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2669 | 2712 |
| 2670 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | 2713 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); |
| 2671 Mock::VerifyAndClearExpectations(context); | 2714 Mock::VerifyAndClearExpectations(context); |
| 2672 | 2715 |
| 2673 // When done with it, a sync point should be inserted, but no produce is | 2716 // When done with it, a sync point should be inserted, but no produce is |
| 2674 // necessary. | 2717 // necessary. |
| 2675 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2718 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2676 EXPECT_CALL(*context, insertSyncPoint()); | 2719 EXPECT_CALL(*context, insertSyncPoint()); |
| 2677 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2720 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2678 | 2721 |
| 2679 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2722 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2680 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2723 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2681 } | 2724 } |
| 2682 | 2725 |
| 2683 resource_provider->DeleteResource(id); | 2726 resource_provider->DeleteResource(id); |
| 2684 EXPECT_EQ(0u, release_sync_point); | 2727 EXPECT_EQ(0u, release_sync_point); |
| 2685 EXPECT_FALSE(lost_resource); | 2728 EXPECT_FALSE(lost_resource); |
| 2686 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); | 2729 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); |
| 2687 } | 2730 } |
| 2688 | 2731 |
| 2689 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { | 2732 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { |
| 2690 // Mailboxing is only supported for GL textures. | 2733 // Mailboxing is only supported for GL textures. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2702 | 2745 |
| 2703 scoped_ptr<ResourceProvider> resource_provider( | 2746 scoped_ptr<ResourceProvider> resource_provider( |
| 2704 ResourceProvider::Create(output_surface.get(), | 2747 ResourceProvider::Create(output_surface.get(), |
| 2705 shared_bitmap_manager_.get(), | 2748 shared_bitmap_manager_.get(), |
| 2706 NULL, | 2749 NULL, |
| 2707 0, | 2750 0, |
| 2708 false, | 2751 false, |
| 2709 1, | 2752 1, |
| 2710 false)); | 2753 false)); |
| 2711 | 2754 |
| 2712 unsigned texture_id = 1; | |
| 2713 uint32 sync_point = 30; | 2755 uint32 sync_point = 30; |
| 2714 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 2756 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
| 2715 | 2757 |
| 2716 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2758 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2717 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2759 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2718 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2760 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2719 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2761 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2720 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2762 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2721 | 2763 |
| 2722 gpu::Mailbox gpu_mailbox; | 2764 gpu::Mailbox gpu_mailbox; |
| 2723 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2765 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2724 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2766 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2725 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 2767 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
| 2726 | 2768 |
| 2727 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2769 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2728 | 2770 |
| 2729 ResourceProvider::ResourceId id = | 2771 ResourceProvider::ResourceId id = |
| 2730 resource_provider->CreateResourceFromTextureMailbox( | 2772 resource_provider->CreateResourceFromTextureMailbox( |
| 2731 mailbox, callback.Pass()); | 2773 mailbox, callback.Pass()); |
| 2732 EXPECT_NE(0u, id); | 2774 EXPECT_NE(0u, id); |
| 2733 | 2775 |
| 2734 Mock::VerifyAndClearExpectations(context); | 2776 Mock::VerifyAndClearExpectations(context); |
| 2735 | 2777 |
| 2736 { | 2778 { |
| 2737 // Mailbox sync point WaitSyncPoint before using the texture. | 2779 // Mailbox sync point WaitSyncPoint before using the texture. |
| 2738 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | 2780 EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
| 2739 resource_provider->WaitSyncPointIfNeeded(id); | 2781 resource_provider->WaitSyncPointIfNeeded(id); |
| 2740 Mock::VerifyAndClearExpectations(context); | 2782 Mock::VerifyAndClearExpectations(context); |
| 2741 | 2783 |
| 2742 // Using the texture does a consume of the mailbox. | 2784 // Using the texture does a consume of the mailbox. |
| 2743 EXPECT_CALL(*context, bindTexture(target, texture_id)); | 2785 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)).Times(0); |
| 2744 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); | |
| 2745 | 2786 |
| 2746 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2787 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2747 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2788 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2748 | 2789 |
| 2749 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | 2790 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); |
| 2750 Mock::VerifyAndClearExpectations(context); | 2791 Mock::VerifyAndClearExpectations(context); |
| 2751 | 2792 |
| 2752 // When done with it, a sync point should be inserted, but no produce is | 2793 // When done with it, a sync point should be inserted, but no produce is |
| 2753 // necessary. | 2794 // necessary. |
| 2754 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2795 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2755 EXPECT_CALL(*context, insertSyncPoint()); | 2796 EXPECT_CALL(*context, insertSyncPoint()); |
| 2756 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2797 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2757 | 2798 |
| 2758 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2799 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2759 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2800 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2760 } | 2801 } |
| 2761 } | 2802 } |
| 2762 | 2803 |
| 2763 TEST_P(ResourceProviderTest, | 2804 TEST_P(ResourceProviderTest, |
| 2764 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { | 2805 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { |
| 2765 // Mailboxing is only supported for GL textures. | 2806 // Mailboxing is only supported for GL textures. |
| 2766 if (GetParam() != ResourceProvider::GLTexture) | 2807 if (GetParam() != ResourceProvider::GLTexture) |
| 2767 return; | 2808 return; |
| 2768 | 2809 |
| 2769 scoped_ptr<TextureStateTrackingContext> context_owned( | 2810 scoped_ptr<TextureStateTrackingContext> context_owned( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2783 false, | 2824 false, |
| 2784 1, | 2825 1, |
| 2785 false)); | 2826 false)); |
| 2786 | 2827 |
| 2787 uint32 sync_point = 30; | 2828 uint32 sync_point = 30; |
| 2788 unsigned target = GL_TEXTURE_2D; | 2829 unsigned target = GL_TEXTURE_2D; |
| 2789 | 2830 |
| 2790 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2831 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2791 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2832 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2792 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2833 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2793 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2834 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2794 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2835 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2795 | 2836 |
| 2796 gpu::Mailbox gpu_mailbox; | 2837 gpu::Mailbox gpu_mailbox; |
| 2797 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2838 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2798 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2839 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2799 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 2840 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
| 2800 | 2841 |
| 2801 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2842 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2802 | 2843 |
| 2803 ResourceProvider::ResourceId id = | 2844 ResourceProvider::ResourceId id = |
| 2804 resource_provider->CreateResourceFromTextureMailbox(mailbox, | 2845 resource_provider->CreateResourceFromTextureMailbox(mailbox, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2842 false, | 2883 false, |
| 2843 1, | 2884 1, |
| 2844 false)); | 2885 false)); |
| 2845 | 2886 |
| 2846 uint32 sync_point = 0; | 2887 uint32 sync_point = 0; |
| 2847 unsigned target = GL_TEXTURE_2D; | 2888 unsigned target = GL_TEXTURE_2D; |
| 2848 | 2889 |
| 2849 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2890 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2850 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2891 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2851 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2892 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2852 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2893 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); |
| 2853 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2894 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); |
| 2854 | 2895 |
| 2855 gpu::Mailbox gpu_mailbox; | 2896 gpu::Mailbox gpu_mailbox; |
| 2856 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2897 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2857 scoped_ptr<SingleReleaseCallbackImpl> callback = | 2898 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2858 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); | 2899 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); |
| 2859 | 2900 |
| 2860 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2901 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2861 | 2902 |
| 2862 ResourceProvider::ResourceId id = | 2903 ResourceProvider::ResourceId id = |
| 2863 resource_provider->CreateResourceFromTextureMailbox(mailbox, | 2904 resource_provider->CreateResourceFromTextureMailbox(mailbox, |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3680 resource_provider->AllocateForTesting(id); | 3721 resource_provider->AllocateForTesting(id); |
| 3681 Mock::VerifyAndClearExpectations(context); | 3722 Mock::VerifyAndClearExpectations(context); |
| 3682 | 3723 |
| 3683 DCHECK_EQ(10u, context->PeekTextureId()); | 3724 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3684 resource_provider->DeleteResource(id); | 3725 resource_provider->DeleteResource(id); |
| 3685 } | 3726 } |
| 3686 } | 3727 } |
| 3687 | 3728 |
| 3688 } // namespace | 3729 } // namespace |
| 3689 } // namespace cc | 3730 } // namespace cc |
| OLD | NEW |