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

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

Issue 1427543002: Modified old wait sync point functions to also accept new sync tokens. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + autogen Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 25 matching lines...) Expand all
36 using testing::Mock; 36 using testing::Mock;
37 using testing::NiceMock; 37 using testing::NiceMock;
38 using testing::Return; 38 using testing::Return;
39 using testing::SetArgPointee; 39 using testing::SetArgPointee;
40 using testing::StrictMock; 40 using testing::StrictMock;
41 using testing::_; 41 using testing::_;
42 42
43 namespace cc { 43 namespace cc {
44 namespace { 44 namespace {
45 45
46 static void EmptyReleaseCallback(uint32 sync_point, 46 MATCHER_P(MatchesSyncToken, sync_token, "") {
47 bool lost_resource, 47 gpu::SyncToken other;
48 BlockingTaskRunner* main_thread_task_runner) { 48 memcpy(&other, arg, sizeof(other));
49 return other == sync_token;
49 } 50 }
50 51
52 static void EmptyReleaseCallback(const gpu::SyncToken& sync_token,
53 bool lost_resource,
54 BlockingTaskRunner* main_thread_task_runner) {}
55
51 static void ReleaseCallback( 56 static void ReleaseCallback(
52 uint32* release_sync_point, 57 gpu::SyncToken* release_sync_token,
53 bool* release_lost_resource, 58 bool* release_lost_resource,
54 BlockingTaskRunner** release_main_thread_task_runner, 59 BlockingTaskRunner** release_main_thread_task_runner,
55 uint32 sync_point, 60 const gpu::SyncToken& sync_token,
56 bool lost_resource, 61 bool lost_resource,
57 BlockingTaskRunner* main_thread_task_runner) { 62 BlockingTaskRunner* main_thread_task_runner) {
58 *release_sync_point = sync_point; 63 *release_sync_token = sync_token;
59 *release_lost_resource = lost_resource; 64 *release_lost_resource = lost_resource;
60 *release_main_thread_task_runner = main_thread_task_runner; 65 *release_main_thread_task_runner = main_thread_task_runner;
61 } 66 }
62 67
63 static void SharedBitmapReleaseCallback( 68 static void SharedBitmapReleaseCallback(
64 scoped_ptr<SharedBitmap> bitmap, 69 scoped_ptr<SharedBitmap> bitmap,
65 uint32 sync_point, 70 const gpu::SyncToken& sync_token,
66 bool lost_resource, 71 bool lost_resource,
67 BlockingTaskRunner* main_thread_task_runner) { 72 BlockingTaskRunner* main_thread_task_runner) {}
68 }
69 73
70 static void ReleaseSharedBitmapCallback( 74 static void ReleaseSharedBitmapCallback(
71 scoped_ptr<SharedBitmap> shared_bitmap, 75 scoped_ptr<SharedBitmap> shared_bitmap,
72 bool* release_called, 76 bool* release_called,
73 uint32* release_sync_point, 77 gpu::SyncToken* release_sync_token,
74 bool* lost_resource_result, 78 bool* lost_resource_result,
75 uint32 sync_point, 79 const gpu::SyncToken& sync_token,
76 bool lost_resource, 80 bool lost_resource,
77 BlockingTaskRunner* main_thread_task_runner) { 81 BlockingTaskRunner* main_thread_task_runner) {
78 *release_called = true; 82 *release_called = true;
79 *release_sync_point = sync_point; 83 *release_sync_token = sync_token;
80 *lost_resource_result = lost_resource; 84 *lost_resource_result = lost_resource;
81 } 85 }
82 86
83 static scoped_ptr<SharedBitmap> CreateAndFillSharedBitmap( 87 static scoped_ptr<SharedBitmap> CreateAndFillSharedBitmap(
84 SharedBitmapManager* manager, 88 SharedBitmapManager* manager,
85 const gfx::Size& size, 89 const gfx::Size& size,
86 uint32_t value) { 90 uint32_t value) {
87 scoped_ptr<SharedBitmap> shared_bitmap = manager->AllocateSharedBitmap(size); 91 scoped_ptr<SharedBitmap> shared_bitmap = manager->AllocateSharedBitmap(size);
88 CHECK(shared_bitmap); 92 CHECK(shared_bitmap);
89 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_bitmap->pixels()); 93 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_bitmap->pixels());
90 CHECK(pixels); 94 CHECK(pixels);
91 std::fill_n(pixels, size.GetArea(), value); 95 std::fill_n(pixels, size.GetArea(), value);
92 return shared_bitmap.Pass(); 96 return shared_bitmap.Pass();
93 } 97 }
94 98
95 class TextureStateTrackingContext : public TestWebGraphicsContext3D { 99 class TextureStateTrackingContext : public TestWebGraphicsContext3D {
96 public: 100 public:
97 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); 101 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture));
98 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); 102 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param));
99 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); 103 MOCK_METHOD1(waitSyncToken, void(const GLbyte* sync_token));
100 MOCK_METHOD0(insertSyncPoint, GLuint(void)); 104 MOCK_METHOD0(insertSyncPoint, GLuint(void));
101 MOCK_METHOD3(produceTextureDirectCHROMIUM, 105 MOCK_METHOD3(produceTextureDirectCHROMIUM,
102 void(GLuint texture, GLenum target, const GLbyte* mailbox)); 106 void(GLuint texture, GLenum target, const GLbyte* mailbox));
103 MOCK_METHOD2(createAndConsumeTextureCHROMIUM, 107 MOCK_METHOD2(createAndConsumeTextureCHROMIUM,
104 unsigned(GLenum target, const GLbyte* mailbox)); 108 unsigned(GLenum target, const GLbyte* mailbox));
105 109
106 // Force all textures to be consecutive numbers starting at "1", 110 // Force all textures to be consecutive numbers starting at "1",
107 // so we easily can test for them. 111 // so we easily can test for them.
108 GLuint NextTextureId() override { 112 GLuint NextTextureId() override {
109 base::AutoLock lock(namespace_->lock); 113 base::AutoLock lock(namespace_->lock);
(...skipping 12 matching lines...) Expand all
122 126
123 uint32 InsertSyncPoint() { return next_sync_point_++; } 127 uint32 InsertSyncPoint() { return next_sync_point_++; }
124 128
125 void GenMailbox(GLbyte* mailbox) { 129 void GenMailbox(GLbyte* mailbox) {
126 memset(mailbox, 0, GL_MAILBOX_SIZE_CHROMIUM); 130 memset(mailbox, 0, GL_MAILBOX_SIZE_CHROMIUM);
127 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); 131 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_));
128 ++next_mailbox_; 132 ++next_mailbox_;
129 } 133 }
130 134
131 void ProduceTexture(const GLbyte* mailbox_name, 135 void ProduceTexture(const GLbyte* mailbox_name,
132 uint32 sync_point, 136 const gpu::SyncToken& sync_token,
133 scoped_refptr<TestTexture> texture) { 137 scoped_refptr<TestTexture> texture) {
138 uint32_t sync_point = static_cast<uint32_t>(sync_token.release_count());
dcheng 2015/11/03 07:39:28 Nit: just make this a uint64_t instead of casting?
David Yen 2015/11/03 18:09:27 sync_point_for_mail_box takes a uint32, I'd rather
139
134 unsigned mailbox = 0; 140 unsigned mailbox = 0;
135 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); 141 memcpy(&mailbox, mailbox_name, sizeof(mailbox));
136 ASSERT_TRUE(mailbox && mailbox < next_mailbox_); 142 ASSERT_TRUE(mailbox && mailbox < next_mailbox_);
137 textures_[mailbox] = texture; 143 textures_[mailbox] = texture;
138 ASSERT_LT(sync_point_for_mailbox_[mailbox], sync_point); 144 ASSERT_LT(sync_point_for_mailbox_[mailbox], sync_point);
139 sync_point_for_mailbox_[mailbox] = sync_point; 145 sync_point_for_mailbox_[mailbox] = sync_point;
140 } 146 }
141 147
142 scoped_refptr<TestTexture> ConsumeTexture(const GLbyte* mailbox_name, 148 scoped_refptr<TestTexture> ConsumeTexture(const GLbyte* mailbox_name,
143 uint32 sync_point) { 149 const gpu::SyncToken& sync_token) {
144 unsigned mailbox = 0; 150 unsigned mailbox = 0;
145 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); 151 memcpy(&mailbox, mailbox_name, sizeof(mailbox));
146 DCHECK(mailbox && mailbox < next_mailbox_); 152 DCHECK(mailbox && mailbox < next_mailbox_);
147 153
148 // If the latest sync point the context has waited on is before the sync 154 // If the latest sync point the context has waited on is before the sync
149 // point for when the mailbox was set, pretend we never saw that 155 // point for when the mailbox was set, pretend we never saw that
150 // ProduceTexture. 156 // ProduceTexture.
151 if (sync_point_for_mailbox_[mailbox] > sync_point) { 157 if (sync_point_for_mailbox_[mailbox] > sync_token.release_count()) {
152 NOTREACHED(); 158 NOTREACHED();
153 return scoped_refptr<TestTexture>(); 159 return scoped_refptr<TestTexture>();
154 } 160 }
155 return textures_[mailbox]; 161 return textures_[mailbox];
156 } 162 }
157 163
158 private: 164 private:
159 ContextSharedData() : next_sync_point_(1), next_mailbox_(1) {} 165 ContextSharedData() : next_sync_point_(1), next_mailbox_(1) {}
160 166
161 uint32 next_sync_point_; 167 uint32 next_sync_point_;
(...skipping 11 matching lines...) Expand all
173 } 179 }
174 180
175 GLuint insertSyncPoint() override { 181 GLuint insertSyncPoint() override {
176 uint32 sync_point = shared_data_->InsertSyncPoint(); 182 uint32 sync_point = shared_data_->InsertSyncPoint();
177 // Commit the produceTextureCHROMIUM calls at this point, so that 183 // Commit the produceTextureCHROMIUM calls at this point, so that
178 // they're associated with the sync point. 184 // they're associated with the sync point.
179 for (PendingProduceTextureList::iterator it = 185 for (PendingProduceTextureList::iterator it =
180 pending_produce_textures_.begin(); 186 pending_produce_textures_.begin();
181 it != pending_produce_textures_.end(); 187 it != pending_produce_textures_.end();
182 ++it) { 188 ++it) {
183 shared_data_->ProduceTexture( 189 shared_data_->ProduceTexture((*it)->mailbox, gpu::SyncToken(sync_point),
184 (*it)->mailbox, sync_point, (*it)->texture); 190 (*it)->texture);
185 } 191 }
186 pending_produce_textures_.clear(); 192 pending_produce_textures_.clear();
187 return sync_point; 193 return sync_point;
188 } 194 }
189 195
190 void waitSyncPoint(GLuint sync_point) override { 196 void waitSyncToken(const GLbyte* sync_token) override {
191 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); 197 gpu::SyncToken sync_token_data;
198 if (sync_token)
199 memcpy(&sync_token_data, sync_token, sizeof(sync_token_data));
200
201 if (sync_token_data.release_count() >
202 last_waited_sync_token_.release_count()) {
203 last_waited_sync_token_ = sync_token_data;
204 }
192 } 205 }
193 206
194 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } 207 const gpu::SyncToken& last_waited_sync_token() const {
208 return last_waited_sync_token_;
209 }
195 210
196 void texStorage2DEXT(GLenum target, 211 void texStorage2DEXT(GLenum target,
197 GLint levels, 212 GLint levels,
198 GLuint internalformat, 213 GLuint internalformat,
199 GLint width, 214 GLint width,
200 GLint height) override { 215 GLint height) override {
201 CheckTextureIsBound(target); 216 CheckTextureIsBound(target);
202 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 217 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
203 ASSERT_EQ(1, levels); 218 ASSERT_EQ(1, levels);
204 GLenum format = GL_RGBA; 219 GLenum format = GL_RGBA;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 base::AutoLock lock_for_texture_access(namespace_->lock); 285 base::AutoLock lock_for_texture_access(namespace_->lock);
271 pending->texture = UnboundTexture(texture); 286 pending->texture = UnboundTexture(texture);
272 pending_produce_textures_.push_back(pending.Pass()); 287 pending_produce_textures_.push_back(pending.Pass());
273 } 288 }
274 289
275 GLuint createAndConsumeTextureCHROMIUM(GLenum target, 290 GLuint createAndConsumeTextureCHROMIUM(GLenum target,
276 const GLbyte* mailbox) override { 291 const GLbyte* mailbox) override {
277 GLuint texture_id = createTexture(); 292 GLuint texture_id = createTexture();
278 base::AutoLock lock_for_texture_access(namespace_->lock); 293 base::AutoLock lock_for_texture_access(namespace_->lock);
279 scoped_refptr<TestTexture> texture = 294 scoped_refptr<TestTexture> texture =
280 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); 295 shared_data_->ConsumeTexture(mailbox, last_waited_sync_token_);
281 namespace_->textures.Replace(texture_id, texture); 296 namespace_->textures.Replace(texture_id, texture);
282 return texture_id; 297 return texture_id;
283 } 298 }
284 299
285 void GetPixels(const gfx::Size& size, 300 void GetPixels(const gfx::Size& size,
286 ResourceFormat format, 301 ResourceFormat format,
287 uint8_t* pixels) { 302 uint8_t* pixels) {
288 CheckTextureIsBound(GL_TEXTURE_2D); 303 CheckTextureIsBound(GL_TEXTURE_2D);
289 base::AutoLock lock_for_texture_access(namespace_->lock); 304 base::AutoLock lock_for_texture_access(namespace_->lock);
290 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); 305 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D);
291 ASSERT_EQ(texture->size, size); 306 ASSERT_EQ(texture->size, size);
292 ASSERT_EQ(texture->format, format); 307 ASSERT_EQ(texture->format, format);
293 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format)); 308 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format));
294 } 309 }
295 310
296 protected: 311 protected:
297 explicit ResourceProviderContext(ContextSharedData* shared_data) 312 explicit ResourceProviderContext(ContextSharedData* shared_data)
298 : shared_data_(shared_data), 313 : shared_data_(shared_data) {}
299 last_waited_sync_point_(0) {}
300 314
301 private: 315 private:
302 void AllocateTexture(const gfx::Size& size, GLenum format) { 316 void AllocateTexture(const gfx::Size& size, GLenum format) {
303 CheckTextureIsBound(GL_TEXTURE_2D); 317 CheckTextureIsBound(GL_TEXTURE_2D);
304 ResourceFormat texture_format = RGBA_8888; 318 ResourceFormat texture_format = RGBA_8888;
305 switch (format) { 319 switch (format) {
306 case GL_RGBA: 320 case GL_RGBA:
307 texture_format = RGBA_8888; 321 texture_format = RGBA_8888;
308 break; 322 break;
309 case GL_BGRA_EXT: 323 case GL_BGRA_EXT:
(...skipping 28 matching lines...) Expand all
338 src += in_pitch; 352 src += in_pitch;
339 } 353 }
340 } 354 }
341 355
342 struct PendingProduceTexture { 356 struct PendingProduceTexture {
343 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; 357 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM];
344 scoped_refptr<TestTexture> texture; 358 scoped_refptr<TestTexture> texture;
345 }; 359 };
346 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; 360 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList;
347 ContextSharedData* shared_data_; 361 ContextSharedData* shared_data_;
348 GLuint last_waited_sync_point_; 362 gpu::SyncToken last_waited_sync_token_;
349 PendingProduceTextureList pending_produce_textures_; 363 PendingProduceTextureList pending_produce_textures_;
350 }; 364 };
351 365
352 void GetResourcePixels(ResourceProvider* resource_provider, 366 void GetResourcePixels(ResourceProvider* resource_provider,
353 ResourceProviderContext* context, 367 ResourceProviderContext* context,
354 ResourceId id, 368 ResourceId id,
355 const gfx::Size& size, 369 const gfx::Size& size,
356 ResourceFormat format, 370 ResourceFormat format,
357 uint8_t* pixels) { 371 uint8_t* pixels) {
358 resource_provider->WaitSyncPointIfNeeded(id); 372 resource_provider->WaitSyncTokenIfNeeded(id);
359 switch (resource_provider->default_resource_type()) { 373 switch (resource_provider->default_resource_type()) {
360 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: { 374 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: {
361 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); 375 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id);
362 ASSERT_NE(0U, lock_gl.texture_id()); 376 ASSERT_NE(0U, lock_gl.texture_id());
363 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); 377 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id());
364 context->GetPixels(size, format, pixels); 378 context->GetPixels(size, format, pixels);
365 break; 379 break;
366 } 380 }
367 case ResourceProvider::RESOURCE_TYPE_BITMAP: { 381 case ResourceProvider::RESOURCE_TYPE_BITMAP: {
368 ResourceProvider::ScopedReadLockSoftware lock_software(resource_provider, 382 ResourceProvider::ScopedReadLockSoftware lock_software(resource_provider,
369 id); 383 id);
370 memcpy(pixels, 384 memcpy(pixels,
371 lock_software.sk_bitmap()->getPixels(), 385 lock_software.sk_bitmap()->getPixels(),
372 lock_software.sk_bitmap()->getSize()); 386 lock_software.sk_bitmap()->getSize());
373 break; 387 break;
374 } 388 }
375 } 389 }
376 } 390 }
377 391
378 class ResourceProviderTest 392 class ResourceProviderTest
379 : public testing::TestWithParam<ResourceProvider::ResourceType> { 393 : public testing::TestWithParam<ResourceProvider::ResourceType> {
380 public: 394 public:
381 explicit ResourceProviderTest(bool child_needs_sync_point) 395 explicit ResourceProviderTest(bool child_needs_sync_token)
382 : shared_data_(ContextSharedData::Create()), 396 : shared_data_(ContextSharedData::Create()),
383 context3d_(NULL), 397 context3d_(NULL),
384 child_context_(NULL), 398 child_context_(NULL),
385 main_thread_task_runner_(BlockingTaskRunner::Create(NULL)) { 399 main_thread_task_runner_(BlockingTaskRunner::Create(NULL)) {
386 switch (GetParam()) { 400 switch (GetParam()) {
387 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: { 401 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: {
388 scoped_ptr<ResourceProviderContext> context3d( 402 scoped_ptr<ResourceProviderContext> context3d(
389 ResourceProviderContext::Create(shared_data_.get())); 403 ResourceProviderContext::Create(shared_data_.get()));
390 context3d_ = context3d.get(); 404 context3d_ = context3d.get();
391 405
392 scoped_refptr<TestContextProvider> context_provider = 406 scoped_refptr<TestContextProvider> context_provider =
393 TestContextProvider::Create(context3d.Pass()); 407 TestContextProvider::Create(context3d.Pass());
394 408
395 output_surface_ = FakeOutputSurface::Create3d(context_provider); 409 output_surface_ = FakeOutputSurface::Create3d(context_provider);
396 410
397 scoped_ptr<ResourceProviderContext> child_context_owned = 411 scoped_ptr<ResourceProviderContext> child_context_owned =
398 ResourceProviderContext::Create(shared_data_.get()); 412 ResourceProviderContext::Create(shared_data_.get());
399 child_context_ = child_context_owned.get(); 413 child_context_ = child_context_owned.get();
400 if (child_needs_sync_point) { 414 if (child_needs_sync_token) {
401 child_output_surface_ = 415 child_output_surface_ =
402 FakeOutputSurface::Create3d(child_context_owned.Pass()); 416 FakeOutputSurface::Create3d(child_context_owned.Pass());
403 } else { 417 } else {
404 child_output_surface_ = FakeOutputSurface::CreateNoRequireSyncPoint( 418 child_output_surface_ = FakeOutputSurface::CreateNoRequireSyncPoint(
405 child_context_owned.Pass()); 419 child_context_owned.Pass());
406 } 420 }
407 break; 421 break;
408 } 422 }
409 case ResourceProvider::RESOURCE_TYPE_BITMAP: 423 case ResourceProvider::RESOURCE_TYPE_BITMAP:
410 output_surface_ = FakeOutputSurface::CreateSoftware( 424 output_surface_ = FakeOutputSurface::CreateSoftware(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 457
444 static void SetResourceFilter(ResourceProvider* resource_provider, 458 static void SetResourceFilter(ResourceProvider* resource_provider,
445 ResourceId id, 459 ResourceId id,
446 GLenum filter) { 460 GLenum filter) {
447 ResourceProvider::ScopedSamplerGL sampler( 461 ResourceProvider::ScopedSamplerGL sampler(
448 resource_provider, id, GL_TEXTURE_2D, filter); 462 resource_provider, id, GL_TEXTURE_2D, filter);
449 } 463 }
450 464
451 ResourceProviderContext* context() { return context3d_; } 465 ResourceProviderContext* context() { return context3d_; }
452 466
453 ResourceId CreateChildMailbox(uint32* release_sync_point, 467 ResourceId CreateChildMailbox(gpu::SyncToken* release_sync_token,
454 bool* lost_resource, 468 bool* lost_resource,
455 bool* release_called, 469 bool* release_called,
456 uint32* sync_point) { 470 gpu::SyncToken* sync_token) {
457 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 471 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
458 unsigned texture = child_context_->createTexture(); 472 unsigned texture = child_context_->createTexture();
459 gpu::Mailbox gpu_mailbox; 473 gpu::Mailbox gpu_mailbox;
460 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); 474 child_context_->genMailboxCHROMIUM(gpu_mailbox.name);
461 child_context_->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, 475 child_context_->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D,
462 gpu_mailbox.name); 476 gpu_mailbox.name);
463 *sync_point = child_context_->insertSyncPoint(); 477 *sync_token = gpu::SyncToken(child_context_->insertSyncPoint());
464 EXPECT_LT(0u, *sync_point); 478 EXPECT_TRUE(sync_token->HasData());
465 479
466 scoped_ptr<SharedBitmap> shared_bitmap; 480 scoped_ptr<SharedBitmap> shared_bitmap;
467 scoped_ptr<SingleReleaseCallbackImpl> callback = 481 scoped_ptr<SingleReleaseCallbackImpl> callback =
468 SingleReleaseCallbackImpl::Create(base::Bind( 482 SingleReleaseCallbackImpl::Create(base::Bind(
469 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap), 483 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap),
470 release_called, release_sync_point, lost_resource)); 484 release_called, release_sync_token, lost_resource));
471 return child_resource_provider_->CreateResourceFromTextureMailbox( 485 return child_resource_provider_->CreateResourceFromTextureMailbox(
472 TextureMailbox(gpu_mailbox, GL_TEXTURE_2D, *sync_point), 486 TextureMailbox(gpu_mailbox, *sync_token, GL_TEXTURE_2D),
473 callback.Pass()); 487 callback.Pass());
474 } else { 488 } else {
475 gfx::Size size(64, 64); 489 gfx::Size size(64, 64);
476 scoped_ptr<SharedBitmap> shared_bitmap( 490 scoped_ptr<SharedBitmap> shared_bitmap(
477 CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, 0)); 491 CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, 0));
478 492
479 SharedBitmap* shared_bitmap_ptr = shared_bitmap.get(); 493 SharedBitmap* shared_bitmap_ptr = shared_bitmap.get();
480 scoped_ptr<SingleReleaseCallbackImpl> callback = 494 scoped_ptr<SingleReleaseCallbackImpl> callback =
481 SingleReleaseCallbackImpl::Create(base::Bind( 495 SingleReleaseCallbackImpl::Create(base::Bind(
482 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap), 496 ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap),
483 release_called, release_sync_point, lost_resource)); 497 release_called, release_sync_token, lost_resource));
484 return child_resource_provider_->CreateResourceFromTextureMailbox( 498 return child_resource_provider_->CreateResourceFromTextureMailbox(
485 TextureMailbox(shared_bitmap_ptr, size), callback.Pass()); 499 TextureMailbox(shared_bitmap_ptr, size), callback.Pass());
486 } 500 }
487 } 501 }
488 502
489 public: 503 public:
490 static std::vector<unsigned> use_image_texture_targets() { 504 static std::vector<unsigned> use_image_texture_targets() {
491 return use_image_texture_targets_; 505 return use_image_texture_targets_;
492 } 506 }
493 507
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 child_resource_provider_.get(), id3); 617 child_resource_provider_.get(), id3);
604 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); 618 EXPECT_TRUE(lock.GetGpuMemoryBuffer());
605 } 619 }
606 620
607 GLuint external_texture_id = child_context_->createExternalTexture(); 621 GLuint external_texture_id = child_context_->createExternalTexture();
608 622
609 gpu::Mailbox external_mailbox; 623 gpu::Mailbox external_mailbox;
610 child_context_->genMailboxCHROMIUM(external_mailbox.name); 624 child_context_->genMailboxCHROMIUM(external_mailbox.name);
611 child_context_->produceTextureDirectCHROMIUM( 625 child_context_->produceTextureDirectCHROMIUM(
612 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); 626 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name);
613 const GLuint external_sync_point = child_context_->insertSyncPoint(); 627 const gpu::SyncToken external_sync_token(child_context_->insertSyncPoint());
614 ResourceId id4 = child_resource_provider_->CreateResourceFromTextureMailbox( 628 ResourceId id4 = child_resource_provider_->CreateResourceFromTextureMailbox(
615 TextureMailbox(external_mailbox, GL_TEXTURE_EXTERNAL_OES, 629 TextureMailbox(external_mailbox, external_sync_token,
616 external_sync_point), 630 GL_TEXTURE_EXTERNAL_OES),
617 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); 631 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)));
618 632
619 ReturnedResourceArray returned_to_child; 633 ReturnedResourceArray returned_to_child;
620 int child_id = 634 int child_id =
621 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 635 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
622 { 636 {
623 // Transfer some resources to the parent. 637 // Transfer some resources to the parent.
624 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 638 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
625 resource_ids_to_transfer.push_back(id1); 639 resource_ids_to_transfer.push_back(id1);
626 resource_ids_to_transfer.push_back(id2); 640 resource_ids_to_transfer.push_back(id2);
627 resource_ids_to_transfer.push_back(id3); 641 resource_ids_to_transfer.push_back(id3);
628 resource_ids_to_transfer.push_back(id4); 642 resource_ids_to_transfer.push_back(id4);
629 TransferableResourceArray list; 643 TransferableResourceArray list;
630 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 644 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
631 &list); 645 &list);
632 ASSERT_EQ(4u, list.size()); 646 ASSERT_EQ(4u, list.size());
633 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 647 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
634 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 648 EXPECT_TRUE(list[1].mailbox_holder.sync_token.HasData());
635 EXPECT_EQ(list[0].mailbox_holder.sync_point, 649 EXPECT_EQ(list[0].mailbox_holder.sync_token,
636 list[1].mailbox_holder.sync_point); 650 list[1].mailbox_holder.sync_token);
637 EXPECT_NE(0u, list[2].mailbox_holder.sync_point); 651 EXPECT_TRUE(list[2].mailbox_holder.sync_token.HasData());
638 EXPECT_EQ(list[0].mailbox_holder.sync_point, 652 EXPECT_EQ(list[0].mailbox_holder.sync_token,
639 list[2].mailbox_holder.sync_point); 653 list[2].mailbox_holder.sync_token);
640 EXPECT_EQ(external_sync_point, list[3].mailbox_holder.sync_point); 654 EXPECT_EQ(external_sync_token, list[3].mailbox_holder.sync_token);
641 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 655 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
642 list[0].mailbox_holder.texture_target); 656 list[0].mailbox_holder.texture_target);
643 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 657 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
644 list[1].mailbox_holder.texture_target); 658 list[1].mailbox_holder.texture_target);
645 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 659 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
646 list[2].mailbox_holder.texture_target); 660 list[2].mailbox_holder.texture_target);
647 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), 661 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES),
648 list[3].mailbox_holder.texture_target); 662 list[3].mailbox_holder.texture_target);
649 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 663 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
650 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 664 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
651 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); 665 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3));
652 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4)); 666 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4));
653 resource_provider_->ReceiveFromChild(child_id, list); 667 resource_provider_->ReceiveFromChild(child_id, list);
654 EXPECT_NE(list[0].mailbox_holder.sync_point, 668 EXPECT_NE(list[0].mailbox_holder.sync_token,
655 context3d_->last_waited_sync_point()); 669 context3d_->last_waited_sync_token());
656 { 670 {
657 resource_provider_->WaitSyncPointIfNeeded(list[0].id); 671 resource_provider_->WaitSyncTokenIfNeeded(list[0].id);
658 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), 672 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
659 list[0].id); 673 list[0].id);
660 } 674 }
661 EXPECT_EQ(list[0].mailbox_holder.sync_point, 675 EXPECT_EQ(list[0].mailbox_holder.sync_token,
662 context3d_->last_waited_sync_point()); 676 context3d_->last_waited_sync_token());
663 ResourceProvider::ResourceIdSet resource_ids_to_receive; 677 ResourceProvider::ResourceIdSet resource_ids_to_receive;
664 resource_ids_to_receive.insert(id1); 678 resource_ids_to_receive.insert(id1);
665 resource_ids_to_receive.insert(id2); 679 resource_ids_to_receive.insert(id2);
666 resource_ids_to_receive.insert(id3); 680 resource_ids_to_receive.insert(id3);
667 resource_ids_to_receive.insert(id4); 681 resource_ids_to_receive.insert(id4);
668 resource_provider_->DeclareUsedResourcesFromChild(child_id, 682 resource_provider_->DeclareUsedResourcesFromChild(child_id,
669 resource_ids_to_receive); 683 resource_ids_to_receive);
670 } 684 }
671 685
672 EXPECT_EQ(4u, resource_provider_->num_resources()); 686 EXPECT_EQ(4u, resource_provider_->num_resources());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 739 }
726 { 740 {
727 EXPECT_EQ(0u, returned_to_child.size()); 741 EXPECT_EQ(0u, returned_to_child.size());
728 742
729 // Transfer resources back from the parent to the child. Set no resources as 743 // Transfer resources back from the parent to the child. Set no resources as
730 // being in use. 744 // being in use.
731 ResourceProvider::ResourceIdSet no_resources; 745 ResourceProvider::ResourceIdSet no_resources;
732 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 746 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
733 747
734 ASSERT_EQ(4u, returned_to_child.size()); 748 ASSERT_EQ(4u, returned_to_child.size());
735 EXPECT_NE(0u, returned_to_child[0].sync_point); 749 EXPECT_TRUE(returned_to_child[0].sync_token.HasData());
736 EXPECT_NE(0u, returned_to_child[1].sync_point); 750 EXPECT_TRUE(returned_to_child[1].sync_token.HasData());
737 EXPECT_NE(0u, returned_to_child[2].sync_point); 751 EXPECT_TRUE(returned_to_child[2].sync_token.HasData());
738 EXPECT_NE(0u, returned_to_child[3].sync_point); 752 EXPECT_TRUE(returned_to_child[3].sync_token.HasData());
739 EXPECT_FALSE(returned_to_child[0].lost); 753 EXPECT_FALSE(returned_to_child[0].lost);
740 EXPECT_FALSE(returned_to_child[1].lost); 754 EXPECT_FALSE(returned_to_child[1].lost);
741 EXPECT_FALSE(returned_to_child[2].lost); 755 EXPECT_FALSE(returned_to_child[2].lost);
742 EXPECT_FALSE(returned_to_child[3].lost); 756 EXPECT_FALSE(returned_to_child[3].lost);
743 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 757 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
744 returned_to_child.clear(); 758 returned_to_child.clear();
745 } 759 }
746 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id1)); 760 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id1));
747 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id2)); 761 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id2));
748 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id3)); 762 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id3));
749 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id4)); 763 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id4));
750 764
751 { 765 {
752 child_resource_provider_->WaitSyncPointIfNeeded(id1); 766 child_resource_provider_->WaitSyncTokenIfNeeded(id1);
753 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), 767 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(),
754 id1); 768 id1);
755 ASSERT_NE(0U, lock.texture_id()); 769 ASSERT_NE(0U, lock.texture_id());
756 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); 770 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id());
757 child_context_->GetPixels(size, format, result); 771 child_context_->GetPixels(size, format, result);
758 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); 772 EXPECT_EQ(0, memcmp(data1, result, pixel_size));
759 } 773 }
760 { 774 {
761 child_resource_provider_->WaitSyncPointIfNeeded(id2); 775 child_resource_provider_->WaitSyncTokenIfNeeded(id2);
762 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), 776 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(),
763 id2); 777 id2);
764 ASSERT_NE(0U, lock.texture_id()); 778 ASSERT_NE(0U, lock.texture_id());
765 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); 779 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id());
766 child_context_->GetPixels(size, format, result); 780 child_context_->GetPixels(size, format, result);
767 EXPECT_EQ(0, memcmp(data2, result, pixel_size)); 781 EXPECT_EQ(0, memcmp(data2, result, pixel_size));
768 } 782 }
769 { 783 {
770 child_resource_provider_->WaitSyncPointIfNeeded(id3); 784 child_resource_provider_->WaitSyncTokenIfNeeded(id3);
771 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), 785 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(),
772 id3); 786 id3);
773 ASSERT_NE(0U, lock.texture_id()); 787 ASSERT_NE(0U, lock.texture_id());
774 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); 788 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id());
775 } 789 }
776 { 790 {
777 // Transfer resources to the parent again. 791 // Transfer resources to the parent again.
778 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 792 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
779 resource_ids_to_transfer.push_back(id1); 793 resource_ids_to_transfer.push_back(id1);
780 resource_ids_to_transfer.push_back(id2); 794 resource_ids_to_transfer.push_back(id2);
781 resource_ids_to_transfer.push_back(id3); 795 resource_ids_to_transfer.push_back(id3);
782 resource_ids_to_transfer.push_back(id4); 796 resource_ids_to_transfer.push_back(id4);
783 TransferableResourceArray list; 797 TransferableResourceArray list;
784 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 798 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
785 &list); 799 &list);
786 ASSERT_EQ(4u, list.size()); 800 ASSERT_EQ(4u, list.size());
787 EXPECT_EQ(id1, list[0].id); 801 EXPECT_EQ(id1, list[0].id);
788 EXPECT_EQ(id2, list[1].id); 802 EXPECT_EQ(id2, list[1].id);
789 EXPECT_EQ(id3, list[2].id); 803 EXPECT_EQ(id3, list[2].id);
790 EXPECT_EQ(id4, list[3].id); 804 EXPECT_EQ(id4, list[3].id);
791 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 805 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
792 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 806 EXPECT_TRUE(list[1].mailbox_holder.sync_token.HasData());
793 EXPECT_NE(0u, list[2].mailbox_holder.sync_point); 807 EXPECT_TRUE(list[2].mailbox_holder.sync_token.HasData());
794 EXPECT_NE(0u, list[3].mailbox_holder.sync_point); 808 EXPECT_TRUE(list[3].mailbox_holder.sync_token.HasData());
795 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 809 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
796 list[0].mailbox_holder.texture_target); 810 list[0].mailbox_holder.texture_target);
797 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 811 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
798 list[1].mailbox_holder.texture_target); 812 list[1].mailbox_holder.texture_target);
799 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 813 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
800 list[2].mailbox_holder.texture_target); 814 list[2].mailbox_holder.texture_target);
801 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), 815 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES),
802 list[3].mailbox_holder.texture_target); 816 list[3].mailbox_holder.texture_target);
803 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 817 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
804 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 818 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
805 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); 819 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3));
806 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4)); 820 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4));
807 resource_provider_->ReceiveFromChild(child_id, list); 821 resource_provider_->ReceiveFromChild(child_id, list);
808 ResourceProvider::ResourceIdSet resource_ids_to_receive; 822 ResourceProvider::ResourceIdSet resource_ids_to_receive;
809 resource_ids_to_receive.insert(id1); 823 resource_ids_to_receive.insert(id1);
810 resource_ids_to_receive.insert(id2); 824 resource_ids_to_receive.insert(id2);
811 resource_ids_to_receive.insert(id3); 825 resource_ids_to_receive.insert(id3);
812 resource_ids_to_receive.insert(id4); 826 resource_ids_to_receive.insert(id4);
813 resource_provider_->DeclareUsedResourcesFromChild(child_id, 827 resource_provider_->DeclareUsedResourcesFromChild(child_id,
814 resource_ids_to_receive); 828 resource_ids_to_receive);
815 } 829 }
816 830
817 EXPECT_EQ(0u, returned_to_child.size()); 831 EXPECT_EQ(0u, returned_to_child.size());
818 832
819 EXPECT_EQ(4u, resource_provider_->num_resources()); 833 EXPECT_EQ(4u, resource_provider_->num_resources());
820 resource_provider_->DestroyChild(child_id); 834 resource_provider_->DestroyChild(child_id);
821 EXPECT_EQ(0u, resource_provider_->num_resources()); 835 EXPECT_EQ(0u, resource_provider_->num_resources());
822 836
823 ASSERT_EQ(4u, returned_to_child.size()); 837 ASSERT_EQ(4u, returned_to_child.size());
824 EXPECT_NE(0u, returned_to_child[0].sync_point); 838 EXPECT_TRUE(returned_to_child[0].sync_token.HasData());
825 EXPECT_NE(0u, returned_to_child[1].sync_point); 839 EXPECT_TRUE(returned_to_child[1].sync_token.HasData());
826 EXPECT_NE(0u, returned_to_child[2].sync_point); 840 EXPECT_TRUE(returned_to_child[2].sync_token.HasData());
827 EXPECT_NE(0u, returned_to_child[3].sync_point); 841 EXPECT_TRUE(returned_to_child[3].sync_token.HasData());
828 EXPECT_FALSE(returned_to_child[0].lost); 842 EXPECT_FALSE(returned_to_child[0].lost);
829 EXPECT_FALSE(returned_to_child[1].lost); 843 EXPECT_FALSE(returned_to_child[1].lost);
830 EXPECT_FALSE(returned_to_child[2].lost); 844 EXPECT_FALSE(returned_to_child[2].lost);
831 EXPECT_FALSE(returned_to_child[3].lost); 845 EXPECT_FALSE(returned_to_child[3].lost);
832 } 846 }
833 847
834 class ResourceProviderTestNoSyncPoint : public ResourceProviderTest { 848 class ResourceProviderTestNoSyncToken : public ResourceProviderTest {
835 public: 849 public:
836 ResourceProviderTestNoSyncPoint() : ResourceProviderTest(false) { 850 ResourceProviderTestNoSyncToken() : ResourceProviderTest(false) {
837 EXPECT_EQ(ResourceProvider::RESOURCE_TYPE_GL_TEXTURE, GetParam()); 851 EXPECT_EQ(ResourceProvider::RESOURCE_TYPE_GL_TEXTURE, GetParam());
838 } 852 }
839 }; 853 };
840 854
841 TEST_P(ResourceProviderTestNoSyncPoint, TransferGLResources) { 855 TEST_P(ResourceProviderTestNoSyncToken, TransferGLResources) {
842 gfx::Size size(1, 1); 856 gfx::Size size(1, 1);
843 ResourceFormat format = RGBA_8888; 857 ResourceFormat format = RGBA_8888;
844 size_t pixel_size = TextureSizeBytes(size, format); 858 size_t pixel_size = TextureSizeBytes(size, format);
845 ASSERT_EQ(4U, pixel_size); 859 ASSERT_EQ(4U, pixel_size);
846 860
847 ResourceId id1 = child_resource_provider_->CreateResource( 861 ResourceId id1 = child_resource_provider_->CreateResource(
848 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 862 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
849 uint8_t data1[4] = {1, 2, 3, 4}; 863 uint8_t data1[4] = {1, 2, 3, 4};
850 child_resource_provider_->CopyToResource(id1, data1, size); 864 child_resource_provider_->CopyToResource(id1, data1, size);
851 865
852 ResourceId id2 = child_resource_provider_->CreateResource( 866 ResourceId id2 = child_resource_provider_->CreateResource(
853 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 867 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
854 { 868 {
855 // Ensure locking the memory buffer doesn't create an unnecessary sync 869 // Ensure locking the memory buffer doesn't create an unnecessary sync
856 // point. 870 // point.
857 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( 871 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock(
858 child_resource_provider_.get(), id2); 872 child_resource_provider_.get(), id2);
859 EXPECT_TRUE(lock.GetGpuMemoryBuffer()); 873 EXPECT_TRUE(lock.GetGpuMemoryBuffer());
860 } 874 }
861 875
862 GLuint external_texture_id = child_context_->createExternalTexture(); 876 GLuint external_texture_id = child_context_->createExternalTexture();
863 877
864 // A sync point is specified directly and should be used. 878 // A sync point is specified directly and should be used.
865 gpu::Mailbox external_mailbox; 879 gpu::Mailbox external_mailbox;
866 child_context_->genMailboxCHROMIUM(external_mailbox.name); 880 child_context_->genMailboxCHROMIUM(external_mailbox.name);
867 child_context_->produceTextureDirectCHROMIUM( 881 child_context_->produceTextureDirectCHROMIUM(
868 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name); 882 external_texture_id, GL_TEXTURE_EXTERNAL_OES, external_mailbox.name);
869 const GLuint external_sync_point = child_context_->insertSyncPoint(); 883 const gpu::SyncToken external_sync_token(child_context_->insertSyncPoint());
870 ResourceId id3 = child_resource_provider_->CreateResourceFromTextureMailbox( 884 ResourceId id3 = child_resource_provider_->CreateResourceFromTextureMailbox(
871 TextureMailbox(external_mailbox, GL_TEXTURE_EXTERNAL_OES, 885 TextureMailbox(external_mailbox, external_sync_token,
872 external_sync_point), 886 GL_TEXTURE_EXTERNAL_OES),
873 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback))); 887 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)));
874 888
875 ReturnedResourceArray returned_to_child; 889 ReturnedResourceArray returned_to_child;
876 int child_id = 890 int child_id =
877 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 891 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
878 resource_provider_->SetChildNeedsSyncPoints(child_id, false); 892 resource_provider_->SetChildNeedsSyncTokens(child_id, false);
879 { 893 {
880 // Transfer some resources to the parent. 894 // Transfer some resources to the parent.
881 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 895 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
882 resource_ids_to_transfer.push_back(id1); 896 resource_ids_to_transfer.push_back(id1);
883 resource_ids_to_transfer.push_back(id2); 897 resource_ids_to_transfer.push_back(id2);
884 resource_ids_to_transfer.push_back(id3); 898 resource_ids_to_transfer.push_back(id3);
885 TransferableResourceArray list; 899 TransferableResourceArray list;
886 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 900 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
887 &list); 901 &list);
888 ASSERT_EQ(3u, list.size()); 902 ASSERT_EQ(3u, list.size());
889 // Standard resources shouldn't require creating and sending a sync point. 903 // Standard resources shouldn't require creating and sending a sync point.
890 EXPECT_EQ(0u, list[0].mailbox_holder.sync_point); 904 EXPECT_FALSE(list[0].mailbox_holder.sync_token.HasData());
891 EXPECT_EQ(0u, list[1].mailbox_holder.sync_point); 905 EXPECT_FALSE(list[1].mailbox_holder.sync_token.HasData());
892 // A given sync point should be passed through. 906 // A given sync point should be passed through.
893 EXPECT_EQ(external_sync_point, list[2].mailbox_holder.sync_point); 907 EXPECT_EQ(external_sync_token, list[2].mailbox_holder.sync_token);
894 resource_provider_->ReceiveFromChild(child_id, list); 908 resource_provider_->ReceiveFromChild(child_id, list);
895 909
896 ResourceProvider::ResourceIdSet resource_ids_to_receive; 910 ResourceProvider::ResourceIdSet resource_ids_to_receive;
897 resource_ids_to_receive.insert(id1); 911 resource_ids_to_receive.insert(id1);
898 resource_ids_to_receive.insert(id2); 912 resource_ids_to_receive.insert(id2);
899 resource_ids_to_receive.insert(id3); 913 resource_ids_to_receive.insert(id3);
900 resource_provider_->DeclareUsedResourcesFromChild(child_id, 914 resource_provider_->DeclareUsedResourcesFromChild(child_id,
901 resource_ids_to_receive); 915 resource_ids_to_receive);
902 } 916 }
903 917
904 { 918 {
905 EXPECT_EQ(0u, returned_to_child.size()); 919 EXPECT_EQ(0u, returned_to_child.size());
906 920
907 // Transfer resources back from the parent to the child. Set no resources as 921 // Transfer resources back from the parent to the child. Set no resources as
908 // being in use. 922 // being in use.
909 ResourceProvider::ResourceIdSet no_resources; 923 ResourceProvider::ResourceIdSet no_resources;
910 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 924 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
911 925
912 ASSERT_EQ(3u, returned_to_child.size()); 926 ASSERT_EQ(3u, returned_to_child.size());
913 std::map<ResourceId, unsigned int> returned_sync_points; 927 std::map<ResourceId, gpu::SyncToken> returned_sync_tokens;
914 for (const auto& returned : returned_to_child) 928 for (const auto& returned : returned_to_child)
915 returned_sync_points[returned.id] = returned.sync_point; 929 returned_sync_tokens[returned.id] = returned.sync_token;
916 930
917 EXPECT_TRUE(returned_sync_points.find(id1) != returned_sync_points.end()); 931 ASSERT_TRUE(returned_sync_tokens.find(id1) != returned_sync_tokens.end());
918 // No new sync point should be created transferring back. 932 // No new sync point should be created transferring back.
919 EXPECT_TRUE(returned_sync_points.find(id1) != returned_sync_points.end()); 933 ASSERT_TRUE(returned_sync_tokens.find(id1) != returned_sync_tokens.end());
920 EXPECT_EQ(0u, returned_sync_points[id1]); 934 EXPECT_FALSE(returned_sync_tokens[id1].HasData());
921 EXPECT_TRUE(returned_sync_points.find(id2) != returned_sync_points.end()); 935 ASSERT_TRUE(returned_sync_tokens.find(id2) != returned_sync_tokens.end());
922 EXPECT_EQ(0u, returned_sync_points[id2]); 936 EXPECT_FALSE(returned_sync_tokens[id2].HasData());
923 // Original sync point given should be returned. 937 // Original sync point given should be returned.
924 EXPECT_TRUE(returned_sync_points.find(id3) != returned_sync_points.end()); 938 ASSERT_TRUE(returned_sync_tokens.find(id3) != returned_sync_tokens.end());
925 EXPECT_EQ(external_sync_point, returned_sync_points[id3]); 939 EXPECT_EQ(external_sync_token, returned_sync_tokens[id3]);
926 EXPECT_FALSE(returned_to_child[0].lost); 940 EXPECT_FALSE(returned_to_child[0].lost);
927 EXPECT_FALSE(returned_to_child[1].lost); 941 EXPECT_FALSE(returned_to_child[1].lost);
928 EXPECT_FALSE(returned_to_child[2].lost); 942 EXPECT_FALSE(returned_to_child[2].lost);
929 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 943 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
930 returned_to_child.clear(); 944 returned_to_child.clear();
931 } 945 }
932 946
933 resource_provider_->DestroyChild(child_id); 947 resource_provider_->DestroyChild(child_id);
934 } 948 }
935 949
936 INSTANTIATE_TEST_CASE_P( 950 INSTANTIATE_TEST_CASE_P(
937 ResourceProviderTests, 951 ResourceProviderTests,
938 ResourceProviderTestNoSyncPoint, 952 ResourceProviderTestNoSyncToken,
939 ::testing::Values(ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)); 953 ::testing::Values(ResourceProvider::RESOURCE_TYPE_GL_TEXTURE));
940 954
941 TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) { 955 TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) {
942 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 956 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
943 return; 957 return;
944 gfx::Size size(1, 1); 958 gfx::Size size(1, 1);
945 ResourceFormat format = RGBA_8888; 959 ResourceFormat format = RGBA_8888;
946 960
947 ResourceId id1 = child_resource_provider_->CreateResource( 961 ResourceId id1 = child_resource_provider_->CreateResource(
948 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 962 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
949 uint8_t data1[4] = {1, 2, 3, 4}; 963 uint8_t data1[4] = {1, 2, 3, 4};
950 child_resource_provider_->CopyToResource(id1, data1, size); 964 child_resource_provider_->CopyToResource(id1, data1, size);
951 965
952 ReturnedResourceArray returned_to_child; 966 ReturnedResourceArray returned_to_child;
953 int child_id = 967 int child_id =
954 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 968 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
955 { 969 {
956 // Transfer some resources to the parent. 970 // Transfer some resources to the parent.
957 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 971 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
958 resource_ids_to_transfer.push_back(id1); 972 resource_ids_to_transfer.push_back(id1);
959 TransferableResourceArray list; 973 TransferableResourceArray list;
960 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 974 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
961 &list); 975 &list);
962 ASSERT_EQ(1u, list.size()); 976 ASSERT_EQ(1u, list.size());
963 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 977 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
964 978
965 resource_provider_->ReceiveFromChild(child_id, list); 979 resource_provider_->ReceiveFromChild(child_id, list);
966 980
967 resource_provider_->WaitSyncPointIfNeeded(list[0].id); 981 resource_provider_->WaitSyncTokenIfNeeded(list[0].id);
968 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), 982 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
969 list[0].id); 983 list[0].id);
970 984
971 resource_provider_->DeclareUsedResourcesFromChild( 985 resource_provider_->DeclareUsedResourcesFromChild(
972 child_id, ResourceProvider::ResourceIdSet()); 986 child_id, ResourceProvider::ResourceIdSet());
973 EXPECT_EQ(0u, returned_to_child.size()); 987 EXPECT_EQ(0u, returned_to_child.size());
974 } 988 }
975 989
976 EXPECT_EQ(1u, returned_to_child.size()); 990 EXPECT_EQ(1u, returned_to_child.size());
977 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 991 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
978 992
979 { 993 {
980 child_resource_provider_->WaitSyncPointIfNeeded(id1); 994 child_resource_provider_->WaitSyncTokenIfNeeded(id1);
981 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), 995 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(),
982 id1); 996 id1);
983 child_resource_provider_->DeleteResource(id1); 997 child_resource_provider_->DeleteResource(id1);
984 EXPECT_EQ(1u, child_resource_provider_->num_resources()); 998 EXPECT_EQ(1u, child_resource_provider_->num_resources());
985 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 999 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
986 } 1000 }
987 1001
988 EXPECT_EQ(0u, child_resource_provider_->num_resources()); 1002 EXPECT_EQ(0u, child_resource_provider_->num_resources());
989 resource_provider_->DestroyChild(child_id); 1003 resource_provider_->DestroyChild(child_id);
990 } 1004 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 ASSERT_EQ(1u, list.size()); 1041 ASSERT_EQ(1u, list.size());
1028 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1042 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1029 EXPECT_TRUE(list[0].read_lock_fences_enabled); 1043 EXPECT_TRUE(list[0].read_lock_fences_enabled);
1030 1044
1031 resource_provider_->ReceiveFromChild(child_id, list); 1045 resource_provider_->ReceiveFromChild(child_id, list);
1032 1046
1033 scoped_refptr<TestFence> fence(new TestFence); 1047 scoped_refptr<TestFence> fence(new TestFence);
1034 resource_provider_->SetReadLockFence(fence.get()); 1048 resource_provider_->SetReadLockFence(fence.get());
1035 { 1049 {
1036 unsigned parent_id = list.front().id; 1050 unsigned parent_id = list.front().id;
1037 resource_provider_->WaitSyncPointIfNeeded(parent_id); 1051 resource_provider_->WaitSyncTokenIfNeeded(parent_id);
1038 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), 1052 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
1039 parent_id); 1053 parent_id);
1040 } 1054 }
1041 resource_provider_->DeclareUsedResourcesFromChild( 1055 resource_provider_->DeclareUsedResourcesFromChild(
1042 child_id, ResourceProvider::ResourceIdSet()); 1056 child_id, ResourceProvider::ResourceIdSet());
1043 EXPECT_EQ(0u, returned_to_child.size()); 1057 EXPECT_EQ(0u, returned_to_child.size());
1044 1058
1045 resource_provider_->DeclareUsedResourcesFromChild( 1059 resource_provider_->DeclareUsedResourcesFromChild(
1046 child_id, ResourceProvider::ResourceIdSet()); 1060 child_id, ResourceProvider::ResourceIdSet());
1047 EXPECT_EQ(0u, returned_to_child.size()); 1061 EXPECT_EQ(0u, returned_to_child.size());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1101 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1088 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1102 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1089 1103
1090 resource_provider_->ReceiveFromChild(child_id, list); 1104 resource_provider_->ReceiveFromChild(child_id, list);
1091 1105
1092 scoped_refptr<TestFence> fence(new TestFence); 1106 scoped_refptr<TestFence> fence(new TestFence);
1093 resource_provider_->SetReadLockFence(fence.get()); 1107 resource_provider_->SetReadLockFence(fence.get());
1094 { 1108 {
1095 for (size_t i = 0; i < list.size(); i++) { 1109 for (size_t i = 0; i < list.size(); i++) {
1096 unsigned parent_id = list[i].id; 1110 unsigned parent_id = list[i].id;
1097 resource_provider_->WaitSyncPointIfNeeded(parent_id); 1111 resource_provider_->WaitSyncTokenIfNeeded(parent_id);
1098 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), 1112 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
1099 parent_id); 1113 parent_id);
1100 } 1114 }
1101 } 1115 }
1102 EXPECT_EQ(0u, returned_to_child.size()); 1116 EXPECT_EQ(0u, returned_to_child.size());
1103 1117
1104 EXPECT_EQ(2u, resource_provider_->num_resources()); 1118 EXPECT_EQ(2u, resource_provider_->num_resources());
1105 1119
1106 resource_provider_->DestroyChild(child_id); 1120 resource_provider_->DestroyChild(child_id);
1107 1121
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1163 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1150 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1164 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1151 1165
1152 resource_provider_->ReceiveFromChild(child_id, list); 1166 resource_provider_->ReceiveFromChild(child_id, list);
1153 1167
1154 scoped_refptr<TestFence> fence(new TestFence); 1168 scoped_refptr<TestFence> fence(new TestFence);
1155 resource_provider_->SetReadLockFence(fence.get()); 1169 resource_provider_->SetReadLockFence(fence.get());
1156 { 1170 {
1157 for (size_t i = 0; i < list.size(); i++) { 1171 for (size_t i = 0; i < list.size(); i++) {
1158 unsigned parent_id = list[i].id; 1172 unsigned parent_id = list[i].id;
1159 resource_provider_->WaitSyncPointIfNeeded(parent_id); 1173 resource_provider_->WaitSyncTokenIfNeeded(parent_id);
1160 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), 1174 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
1161 parent_id); 1175 parent_id);
1162 } 1176 }
1163 } 1177 }
1164 EXPECT_EQ(0u, returned_to_child.size()); 1178 EXPECT_EQ(0u, returned_to_child.size());
1165 1179
1166 EXPECT_EQ(2u, resource_provider_->num_resources()); 1180 EXPECT_EQ(2u, resource_provider_->num_resources());
1167 resource_provider_->DidLoseOutputSurface(); 1181 resource_provider_->DidLoseOutputSurface();
1168 resource_provider_ = nullptr; 1182 resource_provider_ = nullptr;
1169 1183
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 { 1220 {
1207 // Transfer some resources to the parent. 1221 // Transfer some resources to the parent.
1208 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1222 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1209 resource_ids_to_transfer.push_back(id1); 1223 resource_ids_to_transfer.push_back(id1);
1210 resource_ids_to_transfer.push_back(id2); 1224 resource_ids_to_transfer.push_back(id2);
1211 resource_ids_to_transfer.push_back(id3); 1225 resource_ids_to_transfer.push_back(id3);
1212 TransferableResourceArray list; 1226 TransferableResourceArray list;
1213 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1227 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1214 &list); 1228 &list);
1215 ASSERT_EQ(3u, list.size()); 1229 ASSERT_EQ(3u, list.size());
1216 EXPECT_EQ(0u, list[0].mailbox_holder.sync_point); 1230 EXPECT_FALSE(list[0].mailbox_holder.sync_token.HasData());
1217 EXPECT_EQ(0u, list[1].mailbox_holder.sync_point); 1231 EXPECT_FALSE(list[1].mailbox_holder.sync_token.HasData());
1218 EXPECT_EQ(0u, list[2].mailbox_holder.sync_point); 1232 EXPECT_FALSE(list[2].mailbox_holder.sync_token.HasData());
1219 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1233 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1220 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1234 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1221 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); 1235 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3));
1222 resource_provider_->ReceiveFromChild(child_id, list); 1236 resource_provider_->ReceiveFromChild(child_id, list);
1223 ResourceProvider::ResourceIdSet resource_ids_to_receive; 1237 ResourceProvider::ResourceIdSet resource_ids_to_receive;
1224 resource_ids_to_receive.insert(id1); 1238 resource_ids_to_receive.insert(id1);
1225 resource_ids_to_receive.insert(id2); 1239 resource_ids_to_receive.insert(id2);
1226 resource_ids_to_receive.insert(id3); 1240 resource_ids_to_receive.insert(id3);
1227 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1241 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1228 resource_ids_to_receive); 1242 resource_ids_to_receive);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 } 1286 }
1273 { 1287 {
1274 EXPECT_EQ(0u, returned_to_child.size()); 1288 EXPECT_EQ(0u, returned_to_child.size());
1275 1289
1276 // Transfer resources back from the parent to the child. Set no resources as 1290 // Transfer resources back from the parent to the child. Set no resources as
1277 // being in use. 1291 // being in use.
1278 ResourceProvider::ResourceIdSet no_resources; 1292 ResourceProvider::ResourceIdSet no_resources;
1279 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1293 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
1280 1294
1281 ASSERT_EQ(3u, returned_to_child.size()); 1295 ASSERT_EQ(3u, returned_to_child.size());
1282 EXPECT_EQ(0u, returned_to_child[0].sync_point); 1296 EXPECT_FALSE(returned_to_child[0].sync_token.HasData());
1283 EXPECT_EQ(0u, returned_to_child[1].sync_point); 1297 EXPECT_FALSE(returned_to_child[1].sync_token.HasData());
1284 EXPECT_EQ(0u, returned_to_child[2].sync_point); 1298 EXPECT_FALSE(returned_to_child[2].sync_token.HasData());
1285 std::set<ResourceId> expected_ids; 1299 std::set<ResourceId> expected_ids;
1286 expected_ids.insert(id1); 1300 expected_ids.insert(id1);
1287 expected_ids.insert(id2); 1301 expected_ids.insert(id2);
1288 expected_ids.insert(id3); 1302 expected_ids.insert(id3);
1289 std::set<ResourceId> returned_ids; 1303 std::set<ResourceId> returned_ids;
1290 for (unsigned i = 0; i < 3; i++) 1304 for (unsigned i = 0; i < 3; i++)
1291 returned_ids.insert(returned_to_child[i].id); 1305 returned_ids.insert(returned_to_child[i].id);
1292 EXPECT_EQ(expected_ids, returned_ids); 1306 EXPECT_EQ(expected_ids, returned_ids);
1293 EXPECT_FALSE(returned_to_child[0].lost); 1307 EXPECT_FALSE(returned_to_child[0].lost);
1294 EXPECT_FALSE(returned_to_child[1].lost); 1308 EXPECT_FALSE(returned_to_child[1].lost);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 resource_ids_to_receive); 1355 resource_ids_to_receive);
1342 } 1356 }
1343 1357
1344 EXPECT_EQ(0u, returned_to_child.size()); 1358 EXPECT_EQ(0u, returned_to_child.size());
1345 1359
1346 EXPECT_EQ(3u, resource_provider_->num_resources()); 1360 EXPECT_EQ(3u, resource_provider_->num_resources());
1347 resource_provider_->DestroyChild(child_id); 1361 resource_provider_->DestroyChild(child_id);
1348 EXPECT_EQ(0u, resource_provider_->num_resources()); 1362 EXPECT_EQ(0u, resource_provider_->num_resources());
1349 1363
1350 ASSERT_EQ(3u, returned_to_child.size()); 1364 ASSERT_EQ(3u, returned_to_child.size());
1351 EXPECT_EQ(0u, returned_to_child[0].sync_point); 1365 EXPECT_FALSE(returned_to_child[0].sync_token.HasData());
1352 EXPECT_EQ(0u, returned_to_child[1].sync_point); 1366 EXPECT_FALSE(returned_to_child[1].sync_token.HasData());
1353 EXPECT_EQ(0u, returned_to_child[2].sync_point); 1367 EXPECT_FALSE(returned_to_child[2].sync_token.HasData());
1354 std::set<ResourceId> expected_ids; 1368 std::set<ResourceId> expected_ids;
1355 expected_ids.insert(id1); 1369 expected_ids.insert(id1);
1356 expected_ids.insert(id2); 1370 expected_ids.insert(id2);
1357 expected_ids.insert(id3); 1371 expected_ids.insert(id3);
1358 std::set<ResourceId> returned_ids; 1372 std::set<ResourceId> returned_ids;
1359 for (unsigned i = 0; i < 3; i++) 1373 for (unsigned i = 0; i < 3; i++)
1360 returned_ids.insert(returned_to_child[i].id); 1374 returned_ids.insert(returned_to_child[i].id);
1361 EXPECT_EQ(expected_ids, returned_ids); 1375 EXPECT_EQ(expected_ids, returned_ids);
1362 EXPECT_FALSE(returned_to_child[0].lost); 1376 EXPECT_FALSE(returned_to_child[0].lost);
1363 EXPECT_FALSE(returned_to_child[1].lost); 1377 EXPECT_FALSE(returned_to_child[1].lost);
(...skipping 30 matching lines...) Expand all
1394 ReturnedResourceArray returned_to_child; 1408 ReturnedResourceArray returned_to_child;
1395 int child_id = 1409 int child_id =
1396 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1410 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1397 { 1411 {
1398 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1412 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1399 resource_ids_to_transfer.push_back(id1); 1413 resource_ids_to_transfer.push_back(id1);
1400 TransferableResourceArray list; 1414 TransferableResourceArray list;
1401 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, 1415 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
1402 &list); 1416 &list);
1403 ASSERT_EQ(1u, list.size()); 1417 ASSERT_EQ(1u, list.size());
1404 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1418 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
1405 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 1419 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
1406 list[0].mailbox_holder.texture_target); 1420 list[0].mailbox_holder.texture_target);
1407 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1)); 1421 EXPECT_TRUE(child_resource_provider->InUseByConsumer(id1));
1408 resource_provider_->ReceiveFromChild(child_id, list); 1422 resource_provider_->ReceiveFromChild(child_id, list);
1409 } 1423 }
1410 1424
1411 EXPECT_EQ(0u, resource_provider_->num_resources()); 1425 EXPECT_EQ(0u, resource_provider_->num_resources());
1412 ASSERT_EQ(1u, returned_to_child.size()); 1426 ASSERT_EQ(1u, returned_to_child.size());
1413 EXPECT_EQ(returned_to_child[0].id, id1); 1427 EXPECT_EQ(returned_to_child[0].id, id1);
1414 ResourceProvider::ResourceIdMap resource_map = 1428 ResourceProvider::ResourceIdMap resource_map =
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 { 1509 {
1496 // Transfer some resources to the parent. 1510 // Transfer some resources to the parent.
1497 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1511 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1498 resource_ids_to_transfer.push_back(id1); 1512 resource_ids_to_transfer.push_back(id1);
1499 resource_ids_to_transfer.push_back(id2); 1513 resource_ids_to_transfer.push_back(id2);
1500 TransferableResourceArray list; 1514 TransferableResourceArray list;
1501 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1515 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1502 &list); 1516 &list);
1503 ASSERT_EQ(2u, list.size()); 1517 ASSERT_EQ(2u, list.size());
1504 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1518 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1505 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1519 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
1506 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1520 EXPECT_TRUE(list[1].mailbox_holder.sync_token.HasData());
1507 } 1521 }
1508 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1522 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1509 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1523 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1510 resource_provider_->ReceiveFromChild(child_id, list); 1524 resource_provider_->ReceiveFromChild(child_id, list);
1511 ResourceProvider::ResourceIdSet resource_ids_to_receive; 1525 ResourceProvider::ResourceIdSet resource_ids_to_receive;
1512 resource_ids_to_receive.insert(id1); 1526 resource_ids_to_receive.insert(id1);
1513 resource_ids_to_receive.insert(id2); 1527 resource_ids_to_receive.insert(id2);
1514 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1528 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1515 resource_ids_to_receive); 1529 resource_ids_to_receive);
1516 } 1530 }
(...skipping 11 matching lines...) Expand all
1528 { 1542 {
1529 // The parent transfers the resources to the grandparent. 1543 // The parent transfers the resources to the grandparent.
1530 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1544 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1531 resource_ids_to_transfer.push_back(mapped_id1); 1545 resource_ids_to_transfer.push_back(mapped_id1);
1532 resource_ids_to_transfer.push_back(mapped_id2); 1546 resource_ids_to_transfer.push_back(mapped_id2);
1533 TransferableResourceArray list; 1547 TransferableResourceArray list;
1534 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 1548 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
1535 1549
1536 ASSERT_EQ(2u, list.size()); 1550 ASSERT_EQ(2u, list.size());
1537 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1551 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1538 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1552 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
1539 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1553 EXPECT_TRUE(list[1].mailbox_holder.sync_token.HasData());
1540 } 1554 }
1541 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); 1555 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1));
1542 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); 1556 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2));
1543 1557
1544 // Release the resource in the parent. Set no resources as being in use. The 1558 // Release the resource in the parent. Set no resources as being in use. The
1545 // resources are exported so that can't be transferred back yet. 1559 // resources are exported so that can't be transferred back yet.
1546 ResourceProvider::ResourceIdSet no_resources; 1560 ResourceProvider::ResourceIdSet no_resources;
1547 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1561 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
1548 1562
1549 EXPECT_EQ(0u, returned_to_child.size()); 1563 EXPECT_EQ(0u, returned_to_child.size());
1550 EXPECT_EQ(2u, resource_provider_->num_resources()); 1564 EXPECT_EQ(2u, resource_provider_->num_resources());
1551 1565
1552 // Return the resources from the grandparent to the parent. They should be 1566 // Return the resources from the grandparent to the parent. They should be
1553 // returned to the child then. 1567 // returned to the child then.
1554 EXPECT_EQ(2u, list.size()); 1568 EXPECT_EQ(2u, list.size());
1555 EXPECT_EQ(mapped_id1, list[0].id); 1569 EXPECT_EQ(mapped_id1, list[0].id);
1556 EXPECT_EQ(mapped_id2, list[1].id); 1570 EXPECT_EQ(mapped_id2, list[1].id);
1557 ReturnedResourceArray returned; 1571 ReturnedResourceArray returned;
1558 TransferableResource::ReturnResources(list, &returned); 1572 TransferableResource::ReturnResources(list, &returned);
1559 resource_provider_->ReceiveReturnsFromParent(returned); 1573 resource_provider_->ReceiveReturnsFromParent(returned);
1560 1574
1561 EXPECT_EQ(0u, resource_provider_->num_resources()); 1575 EXPECT_EQ(0u, resource_provider_->num_resources());
1562 ASSERT_EQ(2u, returned_to_child.size()); 1576 ASSERT_EQ(2u, returned_to_child.size());
1563 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1577 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1564 EXPECT_NE(0u, returned_to_child[0].sync_point); 1578 EXPECT_TRUE(returned_to_child[0].sync_token.HasData());
1565 EXPECT_NE(0u, returned_to_child[1].sync_point); 1579 EXPECT_TRUE(returned_to_child[1].sync_token.HasData());
1566 } 1580 }
1567 EXPECT_FALSE(returned_to_child[0].lost); 1581 EXPECT_FALSE(returned_to_child[0].lost);
1568 EXPECT_FALSE(returned_to_child[1].lost); 1582 EXPECT_FALSE(returned_to_child[1].lost);
1569 } 1583 }
1570 } 1584 }
1571 1585
1572 TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) { 1586 TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) {
1573 gfx::Size size(1, 1); 1587 gfx::Size size(1, 1);
1574 ResourceFormat format = RGBA_8888; 1588 ResourceFormat format = RGBA_8888;
1575 size_t pixel_size = TextureSizeBytes(size, format); 1589 size_t pixel_size = TextureSizeBytes(size, format);
(...skipping 15 matching lines...) Expand all
1591 { 1605 {
1592 // Transfer some resources to the parent. 1606 // Transfer some resources to the parent.
1593 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1607 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1594 resource_ids_to_transfer.push_back(id1); 1608 resource_ids_to_transfer.push_back(id1);
1595 resource_ids_to_transfer.push_back(id2); 1609 resource_ids_to_transfer.push_back(id2);
1596 TransferableResourceArray list; 1610 TransferableResourceArray list;
1597 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1611 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1598 &list); 1612 &list);
1599 ASSERT_EQ(2u, list.size()); 1613 ASSERT_EQ(2u, list.size());
1600 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1614 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1601 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1615 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
1602 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1616 EXPECT_TRUE(list[1].mailbox_holder.sync_token.HasData());
1603 } 1617 }
1604 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1618 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1605 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1619 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1606 resource_provider_->ReceiveFromChild(child_id, list); 1620 resource_provider_->ReceiveFromChild(child_id, list);
1607 ResourceProvider::ResourceIdSet resource_ids_to_receive; 1621 ResourceProvider::ResourceIdSet resource_ids_to_receive;
1608 resource_ids_to_receive.insert(id1); 1622 resource_ids_to_receive.insert(id1);
1609 resource_ids_to_receive.insert(id2); 1623 resource_ids_to_receive.insert(id2);
1610 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1624 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1611 resource_ids_to_receive); 1625 resource_ids_to_receive);
1612 } 1626 }
(...skipping 11 matching lines...) Expand all
1624 { 1638 {
1625 // The parent transfers the resources to the grandparent. 1639 // The parent transfers the resources to the grandparent.
1626 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1640 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1627 resource_ids_to_transfer.push_back(mapped_id1); 1641 resource_ids_to_transfer.push_back(mapped_id1);
1628 resource_ids_to_transfer.push_back(mapped_id2); 1642 resource_ids_to_transfer.push_back(mapped_id2);
1629 TransferableResourceArray list; 1643 TransferableResourceArray list;
1630 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 1644 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
1631 1645
1632 ASSERT_EQ(2u, list.size()); 1646 ASSERT_EQ(2u, list.size());
1633 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1647 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1634 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1648 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
1635 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1649 EXPECT_TRUE(list[1].mailbox_holder.sync_token.HasData());
1636 } 1650 }
1637 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); 1651 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1));
1638 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); 1652 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2));
1639 1653
1640 // Release the resource in the parent. Set no resources as being in use. The 1654 // Release the resource in the parent. Set no resources as being in use. The
1641 // resources are exported so that can't be transferred back yet. 1655 // resources are exported so that can't be transferred back yet.
1642 ResourceProvider::ResourceIdSet no_resources; 1656 ResourceProvider::ResourceIdSet no_resources;
1643 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1657 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
1644 1658
1645 // Destroy the child, the resources should not be returned yet. 1659 // Destroy the child, the resources should not be returned yet.
(...skipping 13 matching lines...) Expand all
1659 TransferableResourceArray return_list; 1673 TransferableResourceArray return_list;
1660 return_list.push_back(list[1]); 1674 return_list.push_back(list[1]);
1661 list.pop_back(); 1675 list.pop_back();
1662 ReturnedResourceArray returned; 1676 ReturnedResourceArray returned;
1663 TransferableResource::ReturnResources(return_list, &returned); 1677 TransferableResource::ReturnResources(return_list, &returned);
1664 resource_provider_->ReceiveReturnsFromParent(returned); 1678 resource_provider_->ReceiveReturnsFromParent(returned);
1665 1679
1666 EXPECT_EQ(1u, resource_provider_->num_resources()); 1680 EXPECT_EQ(1u, resource_provider_->num_resources());
1667 ASSERT_EQ(1u, returned_to_child.size()); 1681 ASSERT_EQ(1u, returned_to_child.size());
1668 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1682 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1669 EXPECT_NE(0u, returned_to_child[0].sync_point); 1683 EXPECT_TRUE(returned_to_child[0].sync_token.HasData());
1670 } 1684 }
1671 EXPECT_FALSE(returned_to_child[0].lost); 1685 EXPECT_FALSE(returned_to_child[0].lost);
1672 returned_to_child.clear(); 1686 returned_to_child.clear();
1673 1687
1674 // Destroy the parent resource provider. The resource that's left should be 1688 // Destroy the parent resource provider. The resource that's left should be
1675 // lost at this point, and returned. 1689 // lost at this point, and returned.
1676 resource_provider_ = nullptr; 1690 resource_provider_ = nullptr;
1677 ASSERT_EQ(1u, returned_to_child.size()); 1691 ASSERT_EQ(1u, returned_to_child.size());
1678 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1692 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
1679 EXPECT_NE(0u, returned_to_child[0].sync_point); 1693 EXPECT_TRUE(returned_to_child[0].sync_token.HasData());
1680 } 1694 }
1681 EXPECT_TRUE(returned_to_child[0].lost); 1695 EXPECT_TRUE(returned_to_child[0].lost);
1682 } 1696 }
1683 } 1697 }
1684 1698
1685 TEST_P(ResourceProviderTest, DeleteTransferredResources) { 1699 TEST_P(ResourceProviderTest, DeleteTransferredResources) {
1686 gfx::Size size(1, 1); 1700 gfx::Size size(1, 1);
1687 ResourceFormat format = RGBA_8888; 1701 ResourceFormat format = RGBA_8888;
1688 size_t pixel_size = TextureSizeBytes(size, format); 1702 size_t pixel_size = TextureSizeBytes(size, format);
1689 ASSERT_EQ(4U, pixel_size); 1703 ASSERT_EQ(4U, pixel_size);
1690 1704
1691 ResourceId id = child_resource_provider_->CreateResource( 1705 ResourceId id = child_resource_provider_->CreateResource(
1692 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1706 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
1693 uint8_t data[4] = { 1, 2, 3, 4 }; 1707 uint8_t data[4] = { 1, 2, 3, 4 };
1694 child_resource_provider_->CopyToResource(id, data, size); 1708 child_resource_provider_->CopyToResource(id, data, size);
1695 1709
1696 ReturnedResourceArray returned_to_child; 1710 ReturnedResourceArray returned_to_child;
1697 int child_id = 1711 int child_id =
1698 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1712 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1699 { 1713 {
1700 // Transfer some resource to the parent. 1714 // Transfer some resource to the parent.
1701 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1715 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1702 resource_ids_to_transfer.push_back(id); 1716 resource_ids_to_transfer.push_back(id);
1703 TransferableResourceArray list; 1717 TransferableResourceArray list;
1704 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1718 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1705 &list); 1719 &list);
1706 ASSERT_EQ(1u, list.size()); 1720 ASSERT_EQ(1u, list.size());
1707 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1721 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
1708 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1722 EXPECT_TRUE(list[0].mailbox_holder.sync_token.HasData());
1709 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id)); 1723 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id));
1710 resource_provider_->ReceiveFromChild(child_id, list); 1724 resource_provider_->ReceiveFromChild(child_id, list);
1711 ResourceProvider::ResourceIdSet resource_ids_to_receive; 1725 ResourceProvider::ResourceIdSet resource_ids_to_receive;
1712 resource_ids_to_receive.insert(id); 1726 resource_ids_to_receive.insert(id);
1713 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1727 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1714 resource_ids_to_receive); 1728 resource_ids_to_receive);
1715 } 1729 }
1716 1730
1717 // Delete textures in the child, while they are transfered. 1731 // Delete textures in the child, while they are transfered.
1718 child_resource_provider_->DeleteResource(id); 1732 child_resource_provider_->DeleteResource(id);
1719 EXPECT_EQ(1u, child_resource_provider_->num_resources()); 1733 EXPECT_EQ(1u, child_resource_provider_->num_resources());
1720 { 1734 {
1721 EXPECT_EQ(0u, returned_to_child.size()); 1735 EXPECT_EQ(0u, returned_to_child.size());
1722 1736
1723 // Transfer resources back from the parent to the child. Set no resources as 1737 // Transfer resources back from the parent to the child. Set no resources as
1724 // being in use. 1738 // being in use.
1725 ResourceProvider::ResourceIdSet no_resources; 1739 ResourceProvider::ResourceIdSet no_resources;
1726 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1740 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
1727 1741
1728 ASSERT_EQ(1u, returned_to_child.size()); 1742 ASSERT_EQ(1u, returned_to_child.size());
1729 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1743 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
1730 EXPECT_NE(0u, returned_to_child[0].sync_point); 1744 EXPECT_TRUE(returned_to_child[0].sync_token.HasData());
1731 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 1745 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
1732 } 1746 }
1733 EXPECT_EQ(0u, child_resource_provider_->num_resources()); 1747 EXPECT_EQ(0u, child_resource_provider_->num_resources());
1734 } 1748 }
1735 1749
1736 TEST_P(ResourceProviderTest, UnuseTransferredResources) { 1750 TEST_P(ResourceProviderTest, UnuseTransferredResources) {
1737 gfx::Size size(1, 1); 1751 gfx::Size size(1, 1);
1738 ResourceFormat format = RGBA_8888; 1752 ResourceFormat format = RGBA_8888;
1739 size_t pixel_size = TextureSizeBytes(size, format); 1753 size_t pixel_size = TextureSizeBytes(size, format);
1740 ASSERT_EQ(4U, pixel_size); 1754 ASSERT_EQ(4U, pixel_size);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 1957
1944 ASSERT_EQ(1u, list.size()); 1958 ASSERT_EQ(1u, list.size());
1945 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter); 1959 EXPECT_EQ(static_cast<unsigned>(child_filter), list[0].filter);
1946 1960
1947 EXPECT_CALL(*parent_context, 1961 EXPECT_CALL(*parent_context,
1948 createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _)) 1962 createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, _))
1949 .WillOnce(Return(parent_texture_id)); 1963 .WillOnce(Return(parent_texture_id));
1950 1964
1951 parent_resource_provider->ReceiveFromChild(child_id, list); 1965 parent_resource_provider->ReceiveFromChild(child_id, list);
1952 { 1966 {
1953 parent_resource_provider->WaitSyncPointIfNeeded(list[0].id); 1967 parent_resource_provider->WaitSyncTokenIfNeeded(list[0].id);
1954 ResourceProvider::ScopedReadLockGL lock(parent_resource_provider.get(), 1968 ResourceProvider::ScopedReadLockGL lock(parent_resource_provider.get(),
1955 list[0].id); 1969 list[0].id);
1956 } 1970 }
1957 Mock::VerifyAndClearExpectations(parent_context); 1971 Mock::VerifyAndClearExpectations(parent_context);
1958 1972
1959 ResourceProvider::ResourceIdSet resource_ids_to_receive; 1973 ResourceProvider::ResourceIdSet resource_ids_to_receive;
1960 resource_ids_to_receive.insert(id); 1974 resource_ids_to_receive.insert(id);
1961 parent_resource_provider->DeclareUsedResourcesFromChild( 1975 parent_resource_provider->DeclareUsedResourcesFromChild(
1962 child_id, resource_ids_to_receive); 1976 child_id, resource_ids_to_receive);
1963 Mock::VerifyAndClearExpectations(parent_context); 1977 Mock::VerifyAndClearExpectations(parent_context);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2041 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
2028 return; 2042 return;
2029 unsigned texture = context()->createTexture(); 2043 unsigned texture = context()->createTexture();
2030 context()->bindTexture(GL_TEXTURE_2D, texture); 2044 context()->bindTexture(GL_TEXTURE_2D, texture);
2031 uint8_t data[4] = { 1, 2, 3, 4 }; 2045 uint8_t data[4] = { 1, 2, 3, 4 };
2032 context()->texImage2D( 2046 context()->texImage2D(
2033 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); 2047 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data);
2034 gpu::Mailbox mailbox; 2048 gpu::Mailbox mailbox;
2035 context()->genMailboxCHROMIUM(mailbox.name); 2049 context()->genMailboxCHROMIUM(mailbox.name);
2036 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); 2050 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name);
2037 uint32 sync_point = context()->insertSyncPoint(); 2051 gpu::SyncToken sync_token(context()->insertSyncPoint());
2038 2052
2039 // All the logic below assumes that the sync points are all positive. 2053 // All the logic below assumes that the sync token releases are all positive.
2040 EXPECT_LT(0u, sync_point); 2054 EXPECT_LT(0u, sync_token.release_count());
2041 2055
2042 uint32 release_sync_point = 0; 2056 gpu::SyncToken release_sync_token;
2043 bool lost_resource = false; 2057 bool lost_resource = false;
2044 BlockingTaskRunner* main_thread_task_runner = NULL; 2058 BlockingTaskRunner* main_thread_task_runner = NULL;
2045 ReleaseCallbackImpl callback = base::Bind(ReleaseCallback, 2059 ReleaseCallbackImpl callback =
2046 &release_sync_point, 2060 base::Bind(ReleaseCallback, &release_sync_token, &lost_resource,
2047 &lost_resource, 2061 &main_thread_task_runner);
2048 &main_thread_task_runner);
2049 ResourceId resource = resource_provider_->CreateResourceFromTextureMailbox( 2062 ResourceId resource = resource_provider_->CreateResourceFromTextureMailbox(
2050 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), 2063 TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D),
2051 SingleReleaseCallbackImpl::Create(callback)); 2064 SingleReleaseCallbackImpl::Create(callback));
2052 EXPECT_EQ(1u, context()->NumTextures()); 2065 EXPECT_EQ(1u, context()->NumTextures());
2053 EXPECT_EQ(0u, release_sync_point); 2066 EXPECT_FALSE(release_sync_token.HasData());
2054 { 2067 {
2055 // Transfer the resource, expect the sync points to be consistent. 2068 // Transfer the resource, expect the sync points to be consistent.
2056 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2069 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2057 resource_ids_to_transfer.push_back(resource); 2070 resource_ids_to_transfer.push_back(resource);
2058 TransferableResourceArray list; 2071 TransferableResourceArray list;
2059 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 2072 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
2060 ASSERT_EQ(1u, list.size()); 2073 ASSERT_EQ(1u, list.size());
2061 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); 2074 EXPECT_LE(sync_token.release_count(),
2075 list[0].mailbox_holder.sync_token.release_count());
2062 EXPECT_EQ(0, 2076 EXPECT_EQ(0,
2063 memcmp(mailbox.name, 2077 memcmp(mailbox.name,
2064 list[0].mailbox_holder.mailbox.name, 2078 list[0].mailbox_holder.mailbox.name,
2065 sizeof(mailbox.name))); 2079 sizeof(mailbox.name)));
2066 EXPECT_EQ(0u, release_sync_point); 2080 EXPECT_FALSE(release_sync_token.HasData());
2067 2081
2068 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); 2082 context()->waitSyncToken(list[0].mailbox_holder.sync_token.GetConstData());
2069 unsigned other_texture = 2083 unsigned other_texture =
2070 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 2084 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
2071 uint8_t test_data[4] = { 0 }; 2085 uint8_t test_data[4] = { 0 };
2072 context()->GetPixels( 2086 context()->GetPixels(
2073 gfx::Size(1, 1), RGBA_8888, test_data); 2087 gfx::Size(1, 1), RGBA_8888, test_data);
2074 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 2088 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
2075 2089
2076 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, 2090 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D,
2077 mailbox.name); 2091 mailbox.name);
2078 context()->deleteTexture(other_texture); 2092 context()->deleteTexture(other_texture);
2079 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); 2093 list[0].mailbox_holder.sync_token =
2080 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); 2094 gpu::SyncToken(context()->insertSyncPoint());
2081 2095
2082 // Receive the resource, then delete it, expect the sync points to be 2096 // Receive the resource, then delete it, expect the sync points to be
2083 // consistent. 2097 // consistent.
2084 ReturnedResourceArray returned; 2098 ReturnedResourceArray returned;
2085 TransferableResource::ReturnResources(list, &returned); 2099 TransferableResource::ReturnResources(list, &returned);
2086 resource_provider_->ReceiveReturnsFromParent(returned); 2100 resource_provider_->ReceiveReturnsFromParent(returned);
2087 EXPECT_EQ(1u, context()->NumTextures()); 2101 EXPECT_EQ(1u, context()->NumTextures());
2088 EXPECT_EQ(0u, release_sync_point); 2102 EXPECT_FALSE(release_sync_token.HasData());
2089 2103
2090 resource_provider_->DeleteResource(resource); 2104 resource_provider_->DeleteResource(resource);
2091 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); 2105 EXPECT_LE(list[0].mailbox_holder.sync_token.release_count(),
2106 release_sync_token.release_count());
2092 EXPECT_FALSE(lost_resource); 2107 EXPECT_FALSE(lost_resource);
2093 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); 2108 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
2094 } 2109 }
2095 2110
2096 // We're going to do the same thing as above, but testing the case where we 2111 // We're going to do the same thing as above, but testing the case where we
2097 // delete the resource before we receive it back. 2112 // delete the resource before we receive it back.
2098 sync_point = release_sync_point; 2113 sync_token = release_sync_token;
2099 EXPECT_LT(0u, sync_point); 2114 EXPECT_LT(0u, sync_token.release_count());
2100 release_sync_point = 0; 2115 release_sync_token.Clear();
2101 resource = resource_provider_->CreateResourceFromTextureMailbox( 2116 resource = resource_provider_->CreateResourceFromTextureMailbox(
2102 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), 2117 TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D),
2103 SingleReleaseCallbackImpl::Create(callback)); 2118 SingleReleaseCallbackImpl::Create(callback));
2104 EXPECT_EQ(1u, context()->NumTextures()); 2119 EXPECT_EQ(1u, context()->NumTextures());
2105 EXPECT_EQ(0u, release_sync_point); 2120 EXPECT_FALSE(release_sync_token.HasData());
2106 { 2121 {
2107 // Transfer the resource, expect the sync points to be consistent. 2122 // Transfer the resource, expect the sync points to be consistent.
2108 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2123 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2109 resource_ids_to_transfer.push_back(resource); 2124 resource_ids_to_transfer.push_back(resource);
2110 TransferableResourceArray list; 2125 TransferableResourceArray list;
2111 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 2126 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
2112 ASSERT_EQ(1u, list.size()); 2127 ASSERT_EQ(1u, list.size());
2113 EXPECT_LE(sync_point, list[0].mailbox_holder.sync_point); 2128 EXPECT_LE(sync_token.release_count(),
2129 list[0].mailbox_holder.sync_token.release_count());
2114 EXPECT_EQ(0, 2130 EXPECT_EQ(0,
2115 memcmp(mailbox.name, 2131 memcmp(mailbox.name,
2116 list[0].mailbox_holder.mailbox.name, 2132 list[0].mailbox_holder.mailbox.name,
2117 sizeof(mailbox.name))); 2133 sizeof(mailbox.name)));
2118 EXPECT_EQ(0u, release_sync_point); 2134 EXPECT_FALSE(release_sync_token.HasData());
2119 2135
2120 context()->waitSyncPoint(list[0].mailbox_holder.sync_point); 2136 context()->waitSyncToken(list[0].mailbox_holder.sync_token.GetConstData());
2121 unsigned other_texture = 2137 unsigned other_texture =
2122 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 2138 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
2123 uint8_t test_data[4] = { 0 }; 2139 uint8_t test_data[4] = { 0 };
2124 context()->GetPixels( 2140 context()->GetPixels(
2125 gfx::Size(1, 1), RGBA_8888, test_data); 2141 gfx::Size(1, 1), RGBA_8888, test_data);
2126 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data))); 2142 EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
2127 2143
2128 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D, 2144 context()->produceTextureDirectCHROMIUM(other_texture, GL_TEXTURE_2D,
2129 mailbox.name); 2145 mailbox.name);
2130 context()->deleteTexture(other_texture); 2146 context()->deleteTexture(other_texture);
2131 list[0].mailbox_holder.sync_point = context()->insertSyncPoint(); 2147 list[0].mailbox_holder.sync_token =
2132 EXPECT_LT(0u, list[0].mailbox_holder.sync_point); 2148 gpu::SyncToken(context()->insertSyncPoint());
2149 EXPECT_LT(0u, list[0].mailbox_holder.sync_token.release_count());
2133 2150
2134 // Delete the resource, which shouldn't do anything. 2151 // Delete the resource, which shouldn't do anything.
2135 resource_provider_->DeleteResource(resource); 2152 resource_provider_->DeleteResource(resource);
2136 EXPECT_EQ(1u, context()->NumTextures()); 2153 EXPECT_EQ(1u, context()->NumTextures());
2137 EXPECT_EQ(0u, release_sync_point); 2154 EXPECT_FALSE(release_sync_token.HasData());
2138 2155
2139 // Then receive the resource which should release the mailbox, expect the 2156 // Then receive the resource which should release the mailbox, expect the
2140 // sync points to be consistent. 2157 // sync points to be consistent.
2141 ReturnedResourceArray returned; 2158 ReturnedResourceArray returned;
2142 TransferableResource::ReturnResources(list, &returned); 2159 TransferableResource::ReturnResources(list, &returned);
2143 resource_provider_->ReceiveReturnsFromParent(returned); 2160 resource_provider_->ReceiveReturnsFromParent(returned);
2144 EXPECT_LE(list[0].mailbox_holder.sync_point, release_sync_point); 2161 EXPECT_LE(list[0].mailbox_holder.sync_token.release_count(),
2162 release_sync_token.release_count());
2145 EXPECT_FALSE(lost_resource); 2163 EXPECT_FALSE(lost_resource);
2146 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); 2164 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
2147 } 2165 }
2148 2166
2149 context()->waitSyncPoint(release_sync_point); 2167 context()->waitSyncToken(release_sync_token.GetConstData());
2150 texture = 2168 texture =
2151 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 2169 context()->createAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
2152 context()->deleteTexture(texture); 2170 context()->deleteTexture(texture);
2153 } 2171 }
2154 2172
2155 TEST_P(ResourceProviderTest, LostResourceInParent) { 2173 TEST_P(ResourceProviderTest, LostResourceInParent) {
2156 gfx::Size size(1, 1); 2174 gfx::Size size(1, 1);
2157 ResourceFormat format = RGBA_8888; 2175 ResourceFormat format = RGBA_8888;
2158 ResourceId resource = child_resource_provider_->CreateResource( 2176 ResourceId resource = child_resource_provider_->CreateResource(
2159 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 2177 size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 } 2296 }
2279 2297
2280 // The resource should be lost. 2298 // The resource should be lost.
2281 EXPECT_TRUE(child_resource_provider_->IsLost(resource)); 2299 EXPECT_TRUE(child_resource_provider_->IsLost(resource));
2282 2300
2283 // Lost resources stay in use in the parent forever. 2301 // Lost resources stay in use in the parent forever.
2284 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(resource)); 2302 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(resource));
2285 } 2303 }
2286 2304
2287 TEST_P(ResourceProviderTest, LostMailboxInParent) { 2305 TEST_P(ResourceProviderTest, LostMailboxInParent) {
2288 uint32 release_sync_point = 0; 2306 gpu::SyncToken release_sync_token;
2289 bool lost_resource = false; 2307 bool lost_resource = false;
2290 bool release_called = false; 2308 bool release_called = false;
2291 uint32 sync_point = 0; 2309 gpu::SyncToken sync_token;
2292 ResourceId resource = CreateChildMailbox(&release_sync_point, &lost_resource, 2310 ResourceId resource = CreateChildMailbox(&release_sync_token, &lost_resource,
2293 &release_called, &sync_point); 2311 &release_called, &sync_token);
2294 2312
2295 ReturnedResourceArray returned_to_child; 2313 ReturnedResourceArray returned_to_child;
2296 int child_id = 2314 int child_id =
2297 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 2315 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
2298 { 2316 {
2299 // Transfer the resource to the parent. 2317 // Transfer the resource to the parent.
2300 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2318 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2301 resource_ids_to_transfer.push_back(resource); 2319 resource_ids_to_transfer.push_back(resource);
2302 TransferableResourceArray list; 2320 TransferableResourceArray list;
2303 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 2321 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
(...skipping 27 matching lines...) Expand all
2331 } 2349 }
2332 2350
2333 // Delete the resource in the child. Expect the resource to be lost if it's 2351 // Delete the resource in the child. Expect the resource to be lost if it's
2334 // a GL texture. 2352 // a GL texture.
2335 child_resource_provider_->DeleteResource(resource); 2353 child_resource_provider_->DeleteResource(resource);
2336 EXPECT_EQ(lost_resource, 2354 EXPECT_EQ(lost_resource,
2337 GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE); 2355 GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE);
2338 } 2356 }
2339 2357
2340 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { 2358 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) {
2341 uint32 release_sync_point = 0; 2359 gpu::SyncToken release_sync_token;
2342 bool lost_resource = false; 2360 bool lost_resource = false;
2343 bool release_called = false; 2361 bool release_called = false;
2344 uint32 sync_point = 0; 2362 gpu::SyncToken sync_token;
2345 ResourceId resource = CreateChildMailbox(&release_sync_point, &lost_resource, 2363 ResourceId resource = CreateChildMailbox(&release_sync_token, &lost_resource,
2346 &release_called, &sync_point); 2364 &release_called, &sync_token);
2347 2365
2348 ReturnedResourceArray returned_to_child; 2366 ReturnedResourceArray returned_to_child;
2349 int child_id = 2367 int child_id =
2350 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 2368 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
2351 { 2369 {
2352 // Transfer the resource to the parent. 2370 // Transfer the resource to the parent.
2353 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2371 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2354 resource_ids_to_transfer.push_back(resource); 2372 resource_ids_to_transfer.push_back(resource);
2355 TransferableResourceArray list; 2373 TransferableResourceArray list;
2356 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 2374 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 2419 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
2402 returned_to_child.clear(); 2420 returned_to_child.clear();
2403 } 2421 }
2404 2422
2405 // Delete the resource in the child. Expect the resource to be lost. 2423 // Delete the resource in the child. Expect the resource to be lost.
2406 child_resource_provider_->DeleteResource(resource); 2424 child_resource_provider_->DeleteResource(resource);
2407 EXPECT_TRUE(lost_resource); 2425 EXPECT_TRUE(lost_resource);
2408 } 2426 }
2409 2427
2410 TEST_P(ResourceProviderTest, Shutdown) { 2428 TEST_P(ResourceProviderTest, Shutdown) {
2411 uint32 release_sync_point = 0; 2429 gpu::SyncToken release_sync_token;
2412 bool lost_resource = false; 2430 bool lost_resource = false;
2413 bool release_called = false; 2431 bool release_called = false;
2414 uint32 sync_point = 0; 2432 gpu::SyncToken sync_token;
2415 CreateChildMailbox( 2433 CreateChildMailbox(&release_sync_token, &lost_resource, &release_called,
2416 &release_sync_point, &lost_resource, &release_called, &sync_point); 2434 &sync_token);
2417 2435
2418 EXPECT_EQ(0u, release_sync_point); 2436 EXPECT_FALSE(release_sync_token.HasData());
2419 EXPECT_FALSE(lost_resource); 2437 EXPECT_FALSE(lost_resource);
2420 2438
2421 child_resource_provider_ = nullptr; 2439 child_resource_provider_ = nullptr;
2422 2440
2423 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 2441 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) {
2424 EXPECT_LE(sync_point, release_sync_point); 2442 EXPECT_LE(sync_token.release_count(), release_sync_token.release_count());
2425 } 2443 }
2426 EXPECT_TRUE(release_called); 2444 EXPECT_TRUE(release_called);
2427 EXPECT_FALSE(lost_resource); 2445 EXPECT_FALSE(lost_resource);
2428 } 2446 }
2429 2447
2430 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { 2448 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) {
2431 uint32 release_sync_point = 0; 2449 gpu::SyncToken release_sync_token;
2432 bool lost_resource = false; 2450 bool lost_resource = false;
2433 bool release_called = false; 2451 bool release_called = false;
2434 uint32 sync_point = 0; 2452 gpu::SyncToken sync_token;
2435 ResourceId resource = CreateChildMailbox(&release_sync_point, &lost_resource, 2453 ResourceId resource = CreateChildMailbox(&release_sync_token, &lost_resource,
2436 &release_called, &sync_point); 2454 &release_called, &sync_token);
2437 2455
2438 // Transfer the resource, so we can't release it properly on shutdown. 2456 // Transfer the resource, so we can't release it properly on shutdown.
2439 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2457 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2440 resource_ids_to_transfer.push_back(resource); 2458 resource_ids_to_transfer.push_back(resource);
2441 TransferableResourceArray list; 2459 TransferableResourceArray list;
2442 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 2460 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
2443 &list); 2461 &list);
2444 2462
2445 EXPECT_EQ(0u, release_sync_point); 2463 EXPECT_FALSE(release_sync_token.HasData());
2446 EXPECT_FALSE(lost_resource); 2464 EXPECT_FALSE(lost_resource);
2447 2465
2448 child_resource_provider_ = nullptr; 2466 child_resource_provider_ = nullptr;
2449 2467
2450 // Since the resource is in the parent, the child considers it lost. 2468 // Since the resource is in the parent, the child considers it lost.
2451 EXPECT_EQ(0u, release_sync_point); 2469 EXPECT_FALSE(release_sync_token.HasData());
2452 EXPECT_TRUE(lost_resource); 2470 EXPECT_TRUE(lost_resource);
2453 } 2471 }
2454 2472
2455 TEST_P(ResourceProviderTest, LostContext) { 2473 TEST_P(ResourceProviderTest, LostContext) {
2456 // TextureMailbox callbacks only exist for GL textures for now. 2474 // TextureMailbox callbacks only exist for GL textures for now.
2457 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2475 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
2458 return; 2476 return;
2459 unsigned texture = context()->createTexture(); 2477 unsigned texture = context()->createTexture();
2460 context()->bindTexture(GL_TEXTURE_2D, texture); 2478 context()->bindTexture(GL_TEXTURE_2D, texture);
2461 gpu::Mailbox mailbox; 2479 gpu::Mailbox mailbox;
2462 context()->genMailboxCHROMIUM(mailbox.name); 2480 context()->genMailboxCHROMIUM(mailbox.name);
2463 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name); 2481 context()->produceTextureDirectCHROMIUM(texture, GL_TEXTURE_2D, mailbox.name);
2464 uint32 sync_point = context()->insertSyncPoint(); 2482 gpu::SyncToken sync_token(context()->insertSyncPoint());
2465 2483
2466 EXPECT_LT(0u, sync_point); 2484 EXPECT_TRUE(sync_token.HasData());
2467 2485
2468 uint32 release_sync_point = 0; 2486 gpu::SyncToken release_sync_token;
2469 bool lost_resource = false; 2487 bool lost_resource = false;
2470 BlockingTaskRunner* main_thread_task_runner = NULL; 2488 BlockingTaskRunner* main_thread_task_runner = NULL;
2471 scoped_ptr<SingleReleaseCallbackImpl> callback = 2489 scoped_ptr<SingleReleaseCallbackImpl> callback =
2472 SingleReleaseCallbackImpl::Create(base::Bind(ReleaseCallback, 2490 SingleReleaseCallbackImpl::Create(
2473 &release_sync_point, 2491 base::Bind(ReleaseCallback, &release_sync_token, &lost_resource,
2474 &lost_resource, 2492 &main_thread_task_runner));
2475 &main_thread_task_runner));
2476 resource_provider_->CreateResourceFromTextureMailbox( 2493 resource_provider_->CreateResourceFromTextureMailbox(
2477 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), callback.Pass()); 2494 TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D), callback.Pass());
2478 2495
2479 EXPECT_EQ(0u, release_sync_point); 2496 EXPECT_FALSE(release_sync_token.HasData());
2480 EXPECT_FALSE(lost_resource); 2497 EXPECT_FALSE(lost_resource);
2481 EXPECT_EQ(NULL, main_thread_task_runner); 2498 EXPECT_EQ(NULL, main_thread_task_runner);
2482 2499
2483 resource_provider_->DidLoseOutputSurface(); 2500 resource_provider_->DidLoseOutputSurface();
2484 resource_provider_ = nullptr; 2501 resource_provider_ = nullptr;
2485 2502
2486 EXPECT_LE(sync_point, release_sync_point); 2503 EXPECT_LE(sync_token.release_count(), release_sync_token.release_count());
2487 EXPECT_TRUE(lost_resource); 2504 EXPECT_TRUE(lost_resource);
2488 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); 2505 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
2489 } 2506 }
2490 2507
2491 TEST_P(ResourceProviderTest, ScopedSampler) { 2508 TEST_P(ResourceProviderTest, ScopedSampler) {
2492 // Sampling is only supported for GL textures. 2509 // Sampling is only supported for GL textures.
2493 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2510 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
2494 return; 2511 return;
2495 2512
2496 scoped_ptr<TextureStateTrackingContext> context_owned( 2513 scoped_ptr<TextureStateTrackingContext> context_owned(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2725 scoped_ptr<OutputSurface> output_surface( 2742 scoped_ptr<OutputSurface> output_surface(
2726 FakeOutputSurface::CreateSoftware(make_scoped_ptr( 2743 FakeOutputSurface::CreateSoftware(make_scoped_ptr(
2727 new SoftwareOutputDevice))); 2744 new SoftwareOutputDevice)));
2728 CHECK(output_surface->BindToClient(&output_surface_client)); 2745 CHECK(output_surface->BindToClient(&output_surface_client));
2729 2746
2730 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2747 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2731 output_surface.get(), shared_bitmap_manager_.get(), 2748 output_surface.get(), shared_bitmap_manager_.get(),
2732 gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1, 2749 gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1,
2733 use_image_texture_targets_)); 2750 use_image_texture_targets_));
2734 2751
2735 uint32 release_sync_point = 0; 2752 gpu::SyncToken release_sync_token;
2736 bool lost_resource = false; 2753 bool lost_resource = false;
2737 BlockingTaskRunner* main_thread_task_runner = NULL; 2754 BlockingTaskRunner* main_thread_task_runner = NULL;
2738 scoped_ptr<SingleReleaseCallbackImpl> callback = 2755 scoped_ptr<SingleReleaseCallbackImpl> callback =
2739 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, 2756 SingleReleaseCallbackImpl::Create(
2740 &release_sync_point, 2757 base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource,
2741 &lost_resource, 2758 &main_thread_task_runner));
2742 &main_thread_task_runner));
2743 TextureMailbox mailbox(shared_bitmap.get(), size); 2759 TextureMailbox mailbox(shared_bitmap.get(), size);
2744 2760
2745 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( 2761 ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
2746 mailbox, callback.Pass()); 2762 mailbox, callback.Pass());
2747 EXPECT_NE(0u, id); 2763 EXPECT_NE(0u, id);
2748 2764
2749 { 2765 {
2750 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); 2766 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id);
2751 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 2767 const SkBitmap* sk_bitmap = lock.sk_bitmap();
2752 EXPECT_EQ(sk_bitmap->width(), size.width()); 2768 EXPECT_EQ(sk_bitmap->width(), size.width());
2753 EXPECT_EQ(sk_bitmap->height(), size.height()); 2769 EXPECT_EQ(sk_bitmap->height(), size.height());
2754 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef); 2770 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef);
2755 } 2771 }
2756 2772
2757 resource_provider->DeleteResource(id); 2773 resource_provider->DeleteResource(id);
2758 EXPECT_EQ(0u, release_sync_point); 2774 EXPECT_FALSE(release_sync_token.HasData());
2759 EXPECT_FALSE(lost_resource); 2775 EXPECT_FALSE(lost_resource);
2760 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); 2776 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
2761 } 2777 }
2762 2778
2763 class ResourceProviderTestTextureMailboxGLFilters 2779 class ResourceProviderTestTextureMailboxGLFilters
2764 : public ResourceProviderTest { 2780 : public ResourceProviderTest {
2765 public: 2781 public:
2766 static void RunTest(TestSharedBitmapManager* shared_bitmap_manager, 2782 static void RunTest(TestSharedBitmapManager* shared_bitmap_manager,
2767 TestGpuMemoryBufferManager* gpu_memory_buffer_manager, 2783 TestGpuMemoryBufferManager* gpu_memory_buffer_manager,
2768 BlockingTaskRunner* main_thread_task_runner, 2784 BlockingTaskRunner* main_thread_task_runner,
2769 bool mailbox_nearest_neighbor, 2785 bool mailbox_nearest_neighbor,
2770 GLenum sampler_filter) { 2786 GLenum sampler_filter) {
2771 scoped_ptr<TextureStateTrackingContext> context_owned( 2787 scoped_ptr<TextureStateTrackingContext> context_owned(
2772 new TextureStateTrackingContext); 2788 new TextureStateTrackingContext);
2773 TextureStateTrackingContext* context = context_owned.get(); 2789 TextureStateTrackingContext* context = context_owned.get();
2774 2790
2775 FakeOutputSurfaceClient output_surface_client; 2791 FakeOutputSurfaceClient output_surface_client;
2776 scoped_ptr<OutputSurface> output_surface( 2792 scoped_ptr<OutputSurface> output_surface(
2777 FakeOutputSurface::Create3d(context_owned.Pass())); 2793 FakeOutputSurface::Create3d(context_owned.Pass()));
2778 CHECK(output_surface->BindToClient(&output_surface_client)); 2794 CHECK(output_surface->BindToClient(&output_surface_client));
2779 2795
2780 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2796 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2781 output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager, 2797 output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager,
2782 main_thread_task_runner, 0, 1, use_image_texture_targets_)); 2798 main_thread_task_runner, 0, 1, use_image_texture_targets_));
2783 2799
2784 unsigned texture_id = 1; 2800 unsigned texture_id = 1;
2785 uint32 sync_point = 30; 2801 gpu::SyncToken sync_token(30);
2786 unsigned target = GL_TEXTURE_2D; 2802 unsigned target = GL_TEXTURE_2D;
2787 2803
2788 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); 2804 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
2789 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2805 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
2790 EXPECT_CALL(*context, insertSyncPoint()).Times(0); 2806 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
2791 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 2807 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
2792 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); 2808 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
2793 2809
2794 gpu::Mailbox gpu_mailbox; 2810 gpu::Mailbox gpu_mailbox;
2795 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); 2811 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
2796 uint32 release_sync_point = 0; 2812 gpu::SyncToken release_sync_token;
2797 bool lost_resource = false; 2813 bool lost_resource = false;
2798 BlockingTaskRunner* mailbox_task_runner = NULL; 2814 BlockingTaskRunner* mailbox_task_runner = NULL;
2799 scoped_ptr<SingleReleaseCallbackImpl> callback = 2815 scoped_ptr<SingleReleaseCallbackImpl> callback =
2800 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, 2816 SingleReleaseCallbackImpl::Create(
2801 &release_sync_point, 2817 base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource,
2802 &lost_resource, 2818 &mailbox_task_runner));
2803 &mailbox_task_runner));
2804 2819
2805 TextureMailbox mailbox(gpu_mailbox, target, sync_point); 2820 TextureMailbox mailbox(gpu_mailbox, sync_token, target);
2806 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor); 2821 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor);
2807 2822
2808 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( 2823 ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
2809 mailbox, callback.Pass()); 2824 mailbox, callback.Pass());
2810 EXPECT_NE(0u, id); 2825 EXPECT_NE(0u, id);
2811 2826
2812 Mock::VerifyAndClearExpectations(context); 2827 Mock::VerifyAndClearExpectations(context);
2813 2828
2814 { 2829 {
2815 // Mailbox sync point WaitSyncPoint before using the texture. 2830 // Mailbox sync point WaitSyncToken before using the texture.
2816 EXPECT_CALL(*context, waitSyncPoint(sync_point)); 2831 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token)));
2817 resource_provider->WaitSyncPointIfNeeded(id); 2832 resource_provider->WaitSyncTokenIfNeeded(id);
2818 Mock::VerifyAndClearExpectations(context); 2833 Mock::VerifyAndClearExpectations(context);
2819 2834
2820 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) 2835 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _))
2821 .WillOnce(Return(texture_id)); 2836 .WillOnce(Return(texture_id));
2822 EXPECT_CALL(*context, bindTexture(target, texture_id)); 2837 EXPECT_CALL(*context, bindTexture(target, texture_id));
2823 2838
2824 EXPECT_CALL(*context, insertSyncPoint()).Times(0); 2839 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
2825 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 2840 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
2826 2841
2827 // The sampler will reset these if |mailbox_nearest_neighbor| does not 2842 // The sampler will reset these if |mailbox_nearest_neighbor| does not
2828 // match |sampler_filter|. 2843 // match |sampler_filter|.
2829 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) { 2844 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) {
2830 EXPECT_CALL(*context, texParameteri( 2845 EXPECT_CALL(*context, texParameteri(
2831 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter)); 2846 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter));
2832 EXPECT_CALL(*context, texParameteri( 2847 EXPECT_CALL(*context, texParameteri(
2833 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter)); 2848 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter));
2834 } 2849 }
2835 2850
2836 ResourceProvider::ScopedSamplerGL lock( 2851 ResourceProvider::ScopedSamplerGL lock(
2837 resource_provider.get(), id, sampler_filter); 2852 resource_provider.get(), id, sampler_filter);
2838 Mock::VerifyAndClearExpectations(context); 2853 Mock::VerifyAndClearExpectations(context);
2839 2854
2840 // When done with it, a sync point should be inserted, but no produce is 2855 // When done with it, a sync point should be inserted, but no produce is
2841 // necessary. 2856 // necessary.
2842 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); 2857 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
2843 EXPECT_CALL(*context, insertSyncPoint()); 2858 EXPECT_CALL(*context, insertSyncPoint());
2844 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 2859 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
2845 2860
2846 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2861 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
2847 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); 2862 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
2848 } 2863 }
2849 2864
2850 resource_provider->DeleteResource(id); 2865 resource_provider->DeleteResource(id);
2851 EXPECT_EQ(0u, release_sync_point); 2866 EXPECT_FALSE(release_sync_token.HasData());
2852 EXPECT_FALSE(lost_resource); 2867 EXPECT_FALSE(lost_resource);
2853 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); 2868 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner);
2854 } 2869 }
2855 }; 2870 };
2856 2871
2857 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) { 2872 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) {
2858 // Mailboxing is only supported for GL textures. 2873 // Mailboxing is only supported for GL textures.
2859 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2874 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
2860 return; 2875 return;
2861 2876
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 FakeOutputSurfaceClient output_surface_client; 2933 FakeOutputSurfaceClient output_surface_client;
2919 scoped_ptr<OutputSurface> output_surface( 2934 scoped_ptr<OutputSurface> output_surface(
2920 FakeOutputSurface::Create3d(context_owned.Pass())); 2935 FakeOutputSurface::Create3d(context_owned.Pass()));
2921 CHECK(output_surface->BindToClient(&output_surface_client)); 2936 CHECK(output_surface->BindToClient(&output_surface_client));
2922 2937
2923 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2938 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2924 output_surface.get(), shared_bitmap_manager_.get(), 2939 output_surface.get(), shared_bitmap_manager_.get(),
2925 gpu_memory_buffer_manager_.get(), NULL, 0, 1, 2940 gpu_memory_buffer_manager_.get(), NULL, 0, 1,
2926 use_image_texture_targets_)); 2941 use_image_texture_targets_));
2927 2942
2928 uint32 sync_point = 30; 2943 gpu::SyncToken sync_token(30);
2929 unsigned target = GL_TEXTURE_EXTERNAL_OES; 2944 unsigned target = GL_TEXTURE_EXTERNAL_OES;
2930 2945
2931 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); 2946 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
2932 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2947 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
2933 EXPECT_CALL(*context, insertSyncPoint()).Times(0); 2948 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
2934 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 2949 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
2935 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); 2950 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
2936 2951
2937 gpu::Mailbox gpu_mailbox; 2952 gpu::Mailbox gpu_mailbox;
2938 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); 2953 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
2939 scoped_ptr<SingleReleaseCallbackImpl> callback = 2954 scoped_ptr<SingleReleaseCallbackImpl> callback =
2940 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); 2955 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
2941 2956
2942 TextureMailbox mailbox(gpu_mailbox, target, sync_point); 2957 TextureMailbox mailbox(gpu_mailbox, sync_token, target);
2943 2958
2944 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( 2959 ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
2945 mailbox, callback.Pass()); 2960 mailbox, callback.Pass());
2946 EXPECT_NE(0u, id); 2961 EXPECT_NE(0u, id);
2947 2962
2948 Mock::VerifyAndClearExpectations(context); 2963 Mock::VerifyAndClearExpectations(context);
2949 2964
2950 { 2965 {
2951 // Mailbox sync point WaitSyncPoint before using the texture. 2966 // Mailbox sync point WaitSyncToken before using the texture.
2952 EXPECT_CALL(*context, waitSyncPoint(sync_point)); 2967 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token)));
2953 resource_provider->WaitSyncPointIfNeeded(id); 2968 resource_provider->WaitSyncTokenIfNeeded(id);
2954 Mock::VerifyAndClearExpectations(context); 2969 Mock::VerifyAndClearExpectations(context);
2955 2970
2956 unsigned texture_id = 1; 2971 unsigned texture_id = 1;
2957 2972
2958 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _)) 2973 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _))
2959 .WillOnce(Return(texture_id)); 2974 .WillOnce(Return(texture_id));
2960 2975
2961 EXPECT_CALL(*context, insertSyncPoint()).Times(0); 2976 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
2962 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 2977 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
2963 2978
2964 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); 2979 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id);
2965 Mock::VerifyAndClearExpectations(context); 2980 Mock::VerifyAndClearExpectations(context);
2966 2981
2967 // When done with it, a sync point should be inserted, but no produce is 2982 // When done with it, a sync point should be inserted, but no produce is
2968 // necessary. 2983 // necessary.
2969 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); 2984 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
2970 EXPECT_CALL(*context, insertSyncPoint()); 2985 EXPECT_CALL(*context, insertSyncPoint());
2971 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 2986 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
2972 2987
2973 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2988 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
2974 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); 2989 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
2975 } 2990 }
2976 } 2991 }
2977 2992
2978 TEST_P(ResourceProviderTest, 2993 TEST_P(ResourceProviderTest,
2979 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { 2994 TextureMailbox_WaitSyncTokenIfNeeded_WithSyncToken) {
2980 // Mailboxing is only supported for GL textures. 2995 // Mailboxing is only supported for GL textures.
2981 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2996 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
2982 return; 2997 return;
2983 2998
2984 scoped_ptr<TextureStateTrackingContext> context_owned( 2999 scoped_ptr<TextureStateTrackingContext> context_owned(
2985 new TextureStateTrackingContext); 3000 new TextureStateTrackingContext);
2986 TextureStateTrackingContext* context = context_owned.get(); 3001 TextureStateTrackingContext* context = context_owned.get();
2987 3002
2988 FakeOutputSurfaceClient output_surface_client; 3003 FakeOutputSurfaceClient output_surface_client;
2989 scoped_ptr<OutputSurface> output_surface( 3004 scoped_ptr<OutputSurface> output_surface(
2990 FakeOutputSurface::Create3d(context_owned.Pass())); 3005 FakeOutputSurface::Create3d(context_owned.Pass()));
2991 CHECK(output_surface->BindToClient(&output_surface_client)); 3006 CHECK(output_surface->BindToClient(&output_surface_client));
2992 3007
2993 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3008 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2994 output_surface.get(), shared_bitmap_manager_.get(), 3009 output_surface.get(), shared_bitmap_manager_.get(),
2995 gpu_memory_buffer_manager_.get(), NULL, 0, 1, 3010 gpu_memory_buffer_manager_.get(), NULL, 0, 1,
2996 use_image_texture_targets_)); 3011 use_image_texture_targets_));
2997 3012
2998 uint32 sync_point = 30; 3013 gpu::SyncToken sync_token(30);
2999 unsigned target = GL_TEXTURE_2D; 3014 unsigned target = GL_TEXTURE_2D;
3000 3015
3001 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); 3016 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
3002 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 3017 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
3003 EXPECT_CALL(*context, insertSyncPoint()).Times(0); 3018 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
3004 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 3019 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
3005 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); 3020 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
3006 3021
3007 gpu::Mailbox gpu_mailbox; 3022 gpu::Mailbox gpu_mailbox;
3008 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); 3023 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
3009 scoped_ptr<SingleReleaseCallbackImpl> callback = 3024 scoped_ptr<SingleReleaseCallbackImpl> callback =
3010 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); 3025 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
3011 3026
3012 TextureMailbox mailbox(gpu_mailbox, target, sync_point); 3027 TextureMailbox mailbox(gpu_mailbox, sync_token, target);
3013 3028
3014 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( 3029 ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
3015 mailbox, callback.Pass()); 3030 mailbox, callback.Pass());
3016 EXPECT_NE(0u, id); 3031 EXPECT_NE(0u, id);
3017 3032
3018 Mock::VerifyAndClearExpectations(context); 3033 Mock::VerifyAndClearExpectations(context);
3019 3034
3020 { 3035 {
3021 // First call to WaitSyncPointIfNeeded should call waitSyncPoint. 3036 // First call to WaitSyncTokenIfNeeded should call waitSyncToken.
3022 EXPECT_CALL(*context, waitSyncPoint(sync_point)); 3037 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token)));
3023 resource_provider->WaitSyncPointIfNeeded(id); 3038 resource_provider->WaitSyncTokenIfNeeded(id);
3024 Mock::VerifyAndClearExpectations(context); 3039 Mock::VerifyAndClearExpectations(context);
3025 3040
3026 // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint. 3041 // Subsequent calls to WaitSyncTokenIfNeeded shouldn't call waitSyncToken.
3027 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 3042 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
3028 resource_provider->WaitSyncPointIfNeeded(id); 3043 resource_provider->WaitSyncTokenIfNeeded(id);
3029 Mock::VerifyAndClearExpectations(context); 3044 Mock::VerifyAndClearExpectations(context);
3030 } 3045 }
3031 } 3046 }
3032 3047
3033 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) { 3048 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncTokenIfNeeded_NoSyncToken) {
3034 // Mailboxing is only supported for GL textures. 3049 // Mailboxing is only supported for GL textures.
3035 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3050 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
3036 return; 3051 return;
3037 3052
3038 scoped_ptr<TextureStateTrackingContext> context_owned( 3053 scoped_ptr<TextureStateTrackingContext> context_owned(
3039 new TextureStateTrackingContext); 3054 new TextureStateTrackingContext);
3040 TextureStateTrackingContext* context = context_owned.get(); 3055 TextureStateTrackingContext* context = context_owned.get();
3041 3056
3042 FakeOutputSurfaceClient output_surface_client; 3057 FakeOutputSurfaceClient output_surface_client;
3043 scoped_ptr<OutputSurface> output_surface( 3058 scoped_ptr<OutputSurface> output_surface(
3044 FakeOutputSurface::Create3d(context_owned.Pass())); 3059 FakeOutputSurface::Create3d(context_owned.Pass()));
3045 CHECK(output_surface->BindToClient(&output_surface_client)); 3060 CHECK(output_surface->BindToClient(&output_surface_client));
3046 3061
3047 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3062 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3048 output_surface.get(), shared_bitmap_manager_.get(), 3063 output_surface.get(), shared_bitmap_manager_.get(),
3049 gpu_memory_buffer_manager_.get(), NULL, 0, 1, 3064 gpu_memory_buffer_manager_.get(), NULL, 0, 1,
3050 use_image_texture_targets_)); 3065 use_image_texture_targets_));
3051 3066
3052 uint32 sync_point = 0; 3067 gpu::SyncToken sync_token;
3053 unsigned target = GL_TEXTURE_2D; 3068 unsigned target = GL_TEXTURE_2D;
3054 3069
3055 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); 3070 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
3056 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 3071 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
3057 EXPECT_CALL(*context, insertSyncPoint()).Times(0); 3072 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
3058 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0); 3073 EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
3059 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0); 3074 EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
3060 3075
3061 gpu::Mailbox gpu_mailbox; 3076 gpu::Mailbox gpu_mailbox;
3062 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); 3077 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
3063 scoped_ptr<SingleReleaseCallbackImpl> callback = 3078 scoped_ptr<SingleReleaseCallbackImpl> callback =
3064 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); 3079 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
3065 3080
3066 TextureMailbox mailbox(gpu_mailbox, target, sync_point); 3081 TextureMailbox mailbox(gpu_mailbox, sync_token, target);
3067 3082
3068 ResourceId id = resource_provider->CreateResourceFromTextureMailbox( 3083 ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
3069 mailbox, callback.Pass()); 3084 mailbox, callback.Pass());
3070 EXPECT_NE(0u, id); 3085 EXPECT_NE(0u, id);
3071 3086
3072 Mock::VerifyAndClearExpectations(context); 3087 Mock::VerifyAndClearExpectations(context);
3073 3088
3074 { 3089 {
3075 // WaitSyncPointIfNeeded with sync_point == 0 shouldn't call waitSyncPoint. 3090 // WaitSyncTokenIfNeeded with empty sync_token shouldn't call waitSyncToken.
3076 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 3091 EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
3077 resource_provider->WaitSyncPointIfNeeded(id); 3092 resource_provider->WaitSyncTokenIfNeeded(id);
3078 Mock::VerifyAndClearExpectations(context); 3093 Mock::VerifyAndClearExpectations(context);
3079 } 3094 }
3080 } 3095 }
3081 3096
3082 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { 3097 class AllocationTrackingContext3D : public TestWebGraphicsContext3D {
3083 public: 3098 public:
3084 MOCK_METHOD0(NextTextureId, GLuint()); 3099 MOCK_METHOD0(NextTextureId, GLuint());
3085 MOCK_METHOD1(RetireTextureId, void(GLuint id)); 3100 MOCK_METHOD1(RetireTextureId, void(GLuint id));
3086 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); 3101 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture));
3087 MOCK_METHOD5(texStorage2DEXT, 3102 MOCK_METHOD5(texStorage2DEXT,
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
3529 resource_provider->AllocateForTesting(id); 3544 resource_provider->AllocateForTesting(id);
3530 Mock::VerifyAndClearExpectations(context); 3545 Mock::VerifyAndClearExpectations(context);
3531 3546
3532 DCHECK_EQ(10u, context->PeekTextureId()); 3547 DCHECK_EQ(10u, context->PeekTextureId());
3533 resource_provider->DeleteResource(id); 3548 resource_provider->DeleteResource(id);
3534 } 3549 }
3535 } 3550 }
3536 3551
3537 } // namespace 3552 } // namespace
3538 } // namespace cc 3553 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698