OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // contents as well as information about sync points. | 98 // contents as well as information about sync points. |
99 class ContextSharedData { | 99 class ContextSharedData { |
100 public: | 100 public: |
101 static scoped_ptr<ContextSharedData> Create() { | 101 static scoped_ptr<ContextSharedData> Create() { |
102 return make_scoped_ptr(new ContextSharedData()); | 102 return make_scoped_ptr(new ContextSharedData()); |
103 } | 103 } |
104 | 104 |
105 uint32 InsertSyncPoint() { return next_sync_point_++; } | 105 uint32 InsertSyncPoint() { return next_sync_point_++; } |
106 | 106 |
107 void GenMailbox(GLbyte* mailbox) { | 107 void GenMailbox(GLbyte* mailbox) { |
108 memset(mailbox, 0, GL_MAILBOX_SIZE_CHROMIUM); | 108 memset(mailbox, 0, sizeof(GLbyte[64])); |
109 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); | 109 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); |
110 ++next_mailbox_; | 110 ++next_mailbox_; |
111 } | 111 } |
112 | 112 |
113 void ProduceTexture(const GLbyte* mailbox_name, | 113 void ProduceTexture(const GLbyte* mailbox_name, |
114 uint32 sync_point, | 114 uint32 sync_point, |
115 scoped_refptr<TestTexture> texture) { | 115 scoped_refptr<TestTexture> texture) { |
116 unsigned mailbox = 0; | 116 unsigned mailbox = 0; |
117 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); | 117 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); |
118 ASSERT_TRUE(mailbox && mailbox < next_mailbox_); | 118 ASSERT_TRUE(mailbox && mailbox < next_mailbox_); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format); | 315 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format); |
316 const uint8_t* src = static_cast<const uint8_t*>(pixels); | 316 const uint8_t* src = static_cast<const uint8_t*>(pixels); |
317 for (int i = 0; i < height; ++i) { | 317 for (int i = 0; i < height; ++i) { |
318 memcpy(dest, src, in_pitch); | 318 memcpy(dest, src, in_pitch); |
319 dest += out_pitch; | 319 dest += out_pitch; |
320 src += in_pitch; | 320 src += in_pitch; |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 struct PendingProduceTexture { | 324 struct PendingProduceTexture { |
325 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; | 325 GLbyte mailbox[64]; |
326 scoped_refptr<TestTexture> texture; | 326 scoped_refptr<TestTexture> texture; |
327 }; | 327 }; |
328 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; | 328 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; |
329 ContextSharedData* shared_data_; | 329 ContextSharedData* shared_data_; |
330 GLuint last_waited_sync_point_; | 330 GLuint last_waited_sync_point_; |
331 PendingProduceTextureList pending_produce_textures_; | 331 PendingProduceTextureList pending_produce_textures_; |
332 }; | 332 }; |
333 | 333 |
334 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { | 334 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { |
335 delete shared_bitmap->memory(); | 335 delete shared_bitmap->memory(); |
336 } | 336 } |
337 | 337 |
338 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} | 338 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} |
339 | 339 |
340 class TestSharedBitmapManager : public SharedBitmapManager { | 340 class TestSharedBitmapManager : public SharedBitmapManager { |
341 public: | 341 public: |
342 TestSharedBitmapManager() : count_(0) {} | 342 TestSharedBitmapManager() : count_(0) {} |
343 virtual ~TestSharedBitmapManager() {} | 343 virtual ~TestSharedBitmapManager() {} |
344 | 344 |
345 virtual scoped_ptr<SharedBitmap> AllocateSharedBitmap(const gfx::Size& size) | 345 virtual scoped_ptr<SharedBitmap> AllocateSharedBitmap(const gfx::Size& size) |
346 OVERRIDE { | 346 OVERRIDE { |
347 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); | 347 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); |
348 memory->CreateAndMapAnonymous(size.GetArea() * 4); | 348 memory->CreateAndMapAnonymous(size.GetArea() * 4); |
349 int8 name[GL_MAILBOX_SIZE_CHROMIUM] = {0}; | 349 int8 name[64] = { 0 }; |
350 name[0] = count_++; | 350 name[0] = count_++; |
351 SharedBitmapId id; | 351 SharedBitmapId id; |
352 id.SetName(name); | 352 id.SetName(name); |
353 bitmap_map_[id] = memory.get(); | 353 bitmap_map_[id] = memory.get(); |
354 return scoped_ptr<SharedBitmap>( | 354 return scoped_ptr<SharedBitmap>( |
355 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); | 355 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); |
356 } | 356 } |
357 | 357 |
358 virtual scoped_ptr<SharedBitmap> GetSharedBitmapFromId( | 358 virtual scoped_ptr<SharedBitmap> GetSharedBitmapFromId( |
359 const gfx::Size&, | 359 const gfx::Size&, |
360 const SharedBitmapId& id) OVERRIDE { | 360 const SharedBitmapId& id) OVERRIDE { |
361 if (bitmap_map_.find(id) == bitmap_map_.end()) | 361 if (bitmap_map_.find(id) == bitmap_map_.end()) |
362 return scoped_ptr<SharedBitmap>(); | 362 return scoped_ptr<SharedBitmap>(); |
363 return scoped_ptr<SharedBitmap>( | 363 return scoped_ptr<SharedBitmap>( |
364 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); | 364 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); |
365 } | 365 } |
366 | 366 |
367 virtual scoped_ptr<SharedBitmap> GetBitmapForSharedMemory( | 367 virtual scoped_ptr<SharedBitmap> GetBitmapForSharedMemory( |
368 base::SharedMemory* memory) OVERRIDE { | 368 base::SharedMemory* memory) OVERRIDE { |
369 int8 name[GL_MAILBOX_SIZE_CHROMIUM] = {0}; | 369 int8 name[64] = { 0 }; |
370 name[0] = count_++; | 370 name[0] = count_++; |
371 SharedBitmapId id; | 371 SharedBitmapId id; |
372 id.SetName(name); | 372 id.SetName(name); |
373 bitmap_map_[id] = memory; | 373 bitmap_map_[id] = memory; |
374 return scoped_ptr<SharedBitmap>( | 374 return scoped_ptr<SharedBitmap>( |
375 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); | 375 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); |
376 } | 376 } |
377 | 377 |
378 private: | 378 private: |
379 int count_; | 379 int count_; |
(...skipping 2809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3189 resource_provider->AllocateForTesting(id); | 3189 resource_provider->AllocateForTesting(id); |
3190 Mock::VerifyAndClearExpectations(context); | 3190 Mock::VerifyAndClearExpectations(context); |
3191 | 3191 |
3192 DCHECK_EQ(10u, context->PeekTextureId()); | 3192 DCHECK_EQ(10u, context->PeekTextureId()); |
3193 resource_provider->DeleteResource(id); | 3193 resource_provider->DeleteResource(id); |
3194 } | 3194 } |
3195 } | 3195 } |
3196 | 3196 |
3197 } // namespace | 3197 } // namespace |
3198 } // namespace cc | 3198 } // namespace cc |
OLD | NEW |