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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 unsigned* release_sync_point, | 57 unsigned* release_sync_point, |
58 bool* lost_resource_result, | 58 bool* lost_resource_result, |
59 unsigned sync_point, | 59 unsigned sync_point, |
60 bool lost_resource) { | 60 bool lost_resource) { |
61 *release_called = true; | 61 *release_called = true; |
62 *release_sync_point = sync_point; | 62 *release_sync_point = sync_point; |
63 *lost_resource_result = lost_resource; | 63 *lost_resource_result = lost_resource; |
64 } | 64 } |
65 | 65 |
66 static scoped_ptr<base::SharedMemory> CreateAndFillSharedMemory( | 66 static scoped_ptr<base::SharedMemory> CreateAndFillSharedMemory( |
67 gfx::Size size, | 67 const gfx::Size& size, |
68 uint32_t value) { | 68 uint32_t value) { |
69 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); | 69 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); |
70 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); | 70 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); |
71 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); | 71 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); |
72 CHECK(pixels); | 72 CHECK(pixels); |
73 std::fill_n(pixels, size.GetArea(), value); | 73 std::fill_n(pixels, size.GetArea(), value); |
74 return shared_memory.Pass(); | 74 return shared_memory.Pass(); |
75 } | 75 } |
76 | 76 |
77 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 77 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 virtual void consumeTextureCHROMIUM(GLenum target, | 258 virtual void consumeTextureCHROMIUM(GLenum target, |
259 const GLbyte* mailbox) OVERRIDE { | 259 const GLbyte* mailbox) OVERRIDE { |
260 CheckTextureIsBound(target); | 260 CheckTextureIsBound(target); |
261 base::AutoLock lock_for_texture_access(namespace_->lock); | 261 base::AutoLock lock_for_texture_access(namespace_->lock); |
262 scoped_refptr<TestTexture> texture = | 262 scoped_refptr<TestTexture> texture = |
263 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); | 263 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); |
264 namespace_->textures.Replace(BoundTextureId(target), texture); | 264 namespace_->textures.Replace(BoundTextureId(target), texture); |
265 } | 265 } |
266 | 266 |
267 void GetPixels(gfx::Size size, ResourceFormat format, uint8_t* pixels) { | 267 void GetPixels(const gfx::Size& size, |
| 268 ResourceFormat format, |
| 269 uint8_t* pixels) { |
268 CheckTextureIsBound(GL_TEXTURE_2D); | 270 CheckTextureIsBound(GL_TEXTURE_2D); |
269 base::AutoLock lock_for_texture_access(namespace_->lock); | 271 base::AutoLock lock_for_texture_access(namespace_->lock); |
270 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); | 272 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); |
271 ASSERT_EQ(texture->size, size); | 273 ASSERT_EQ(texture->size, size); |
272 ASSERT_EQ(texture->format, format); | 274 ASSERT_EQ(texture->format, format); |
273 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format)); | 275 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format)); |
274 } | 276 } |
275 | 277 |
276 protected: | 278 protected: |
277 explicit ResourceProviderContext(ContextSharedData* shared_data) | 279 explicit ResourceProviderContext(ContextSharedData* shared_data) |
278 : shared_data_(shared_data), | 280 : shared_data_(shared_data), |
279 last_waited_sync_point_(0) {} | 281 last_waited_sync_point_(0) {} |
280 | 282 |
281 private: | 283 private: |
282 void AllocateTexture(gfx::Size size, GLenum format) { | 284 void AllocateTexture(const gfx::Size& size, GLenum format) { |
283 CheckTextureIsBound(GL_TEXTURE_2D); | 285 CheckTextureIsBound(GL_TEXTURE_2D); |
284 ResourceFormat texture_format = RGBA_8888; | 286 ResourceFormat texture_format = RGBA_8888; |
285 switch (format) { | 287 switch (format) { |
286 case GL_RGBA: | 288 case GL_RGBA: |
287 texture_format = RGBA_8888; | 289 texture_format = RGBA_8888; |
288 break; | 290 break; |
289 case GL_BGRA_EXT: | 291 case GL_BGRA_EXT: |
290 texture_format = BGRA_8888; | 292 texture_format = BGRA_8888; |
291 break; | 293 break; |
292 } | 294 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 delete shared_bitmap->memory(); | 335 delete shared_bitmap->memory(); |
334 } | 336 } |
335 | 337 |
336 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} | 338 void IgnoreSharedBitmap(SharedBitmap* shared_bitmap) {} |
337 | 339 |
338 class TestSharedBitmapManager : public SharedBitmapManager { | 340 class TestSharedBitmapManager : public SharedBitmapManager { |
339 public: | 341 public: |
340 TestSharedBitmapManager() : count_(0) {} | 342 TestSharedBitmapManager() : count_(0) {} |
341 virtual ~TestSharedBitmapManager() {} | 343 virtual ~TestSharedBitmapManager() {} |
342 | 344 |
343 virtual scoped_ptr<SharedBitmap> AllocateSharedBitmap(gfx::Size size) | 345 virtual scoped_ptr<SharedBitmap> AllocateSharedBitmap(const gfx::Size& size) |
344 OVERRIDE { | 346 OVERRIDE { |
345 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); | 347 scoped_ptr<base::SharedMemory> memory(new base::SharedMemory); |
346 memory->CreateAndMapAnonymous(size.GetArea() * 4); | 348 memory->CreateAndMapAnonymous(size.GetArea() * 4); |
347 int8 name[64] = { 0 }; | 349 int8 name[64] = { 0 }; |
348 name[0] = count_++; | 350 name[0] = count_++; |
349 SharedBitmapId id; | 351 SharedBitmapId id; |
350 id.SetName(name); | 352 id.SetName(name); |
351 bitmap_map_[id] = memory.get(); | 353 bitmap_map_[id] = memory.get(); |
352 return scoped_ptr<SharedBitmap>( | 354 return scoped_ptr<SharedBitmap>( |
353 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); | 355 new SharedBitmap(memory.release(), id, base::Bind(&FreeSharedBitmap))); |
354 } | 356 } |
355 | 357 |
356 virtual scoped_ptr<SharedBitmap> GetSharedBitmapFromId( | 358 virtual scoped_ptr<SharedBitmap> GetSharedBitmapFromId( |
357 gfx::Size, | 359 const gfx::Size&, |
358 const SharedBitmapId& id) OVERRIDE { | 360 const SharedBitmapId& id) OVERRIDE { |
359 if (bitmap_map_.find(id) == bitmap_map_.end()) | 361 if (bitmap_map_.find(id) == bitmap_map_.end()) |
360 return scoped_ptr<SharedBitmap>(); | 362 return scoped_ptr<SharedBitmap>(); |
361 return scoped_ptr<SharedBitmap>( | 363 return scoped_ptr<SharedBitmap>( |
362 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); | 364 new SharedBitmap(bitmap_map_[id], id, base::Bind(&IgnoreSharedBitmap))); |
363 } | 365 } |
364 | 366 |
365 virtual scoped_ptr<SharedBitmap> GetBitmapForSharedMemory( | 367 virtual scoped_ptr<SharedBitmap> GetBitmapForSharedMemory( |
366 base::SharedMemory* memory) OVERRIDE { | 368 base::SharedMemory* memory) OVERRIDE { |
367 int8 name[64] = { 0 }; | 369 int8 name[64] = { 0 }; |
368 name[0] = count_++; | 370 name[0] = count_++; |
369 SharedBitmapId id; | 371 SharedBitmapId id; |
370 id.SetName(name); | 372 id.SetName(name); |
371 bitmap_map_[id] = memory; | 373 bitmap_map_[id] = memory; |
372 return scoped_ptr<SharedBitmap>( | 374 return scoped_ptr<SharedBitmap>( |
373 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); | 375 new SharedBitmap(memory, id, base::Bind(&IgnoreSharedBitmap))); |
374 } | 376 } |
375 | 377 |
376 private: | 378 private: |
377 int count_; | 379 int count_; |
378 std::map<SharedBitmapId, base::SharedMemory*> bitmap_map_; | 380 std::map<SharedBitmapId, base::SharedMemory*> bitmap_map_; |
379 }; | 381 }; |
380 | 382 |
381 void GetResourcePixels(ResourceProvider* resource_provider, | 383 void GetResourcePixels(ResourceProvider* resource_provider, |
382 ResourceProviderContext* context, | 384 ResourceProviderContext* context, |
383 ResourceProvider::ResourceId id, | 385 ResourceProvider::ResourceId id, |
384 gfx::Size size, | 386 const gfx::Size& size, |
385 ResourceFormat format, | 387 ResourceFormat format, |
386 uint8_t* pixels) { | 388 uint8_t* pixels) { |
387 switch (resource_provider->default_resource_type()) { | 389 switch (resource_provider->default_resource_type()) { |
388 case ResourceProvider::GLTexture: { | 390 case ResourceProvider::GLTexture: { |
389 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); | 391 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); |
390 ASSERT_NE(0U, lock_gl.texture_id()); | 392 ASSERT_NE(0U, lock_gl.texture_id()); |
391 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); | 393 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); |
392 context->GetPixels(size, format, pixels); | 394 context->GetPixels(size, format, pixels); |
393 break; | 395 break; |
394 } | 396 } |
(...skipping 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3159 resource_provider->AllocateForTesting(id); | 3161 resource_provider->AllocateForTesting(id); |
3160 Mock::VerifyAndClearExpectations(context); | 3162 Mock::VerifyAndClearExpectations(context); |
3161 | 3163 |
3162 DCHECK_EQ(10u, context->PeekTextureId()); | 3164 DCHECK_EQ(10u, context->PeekTextureId()); |
3163 resource_provider->DeleteResource(id); | 3165 resource_provider->DeleteResource(id); |
3164 } | 3166 } |
3165 } | 3167 } |
3166 | 3168 |
3167 } // namespace | 3169 } // namespace |
3168 } // namespace cc | 3170 } // namespace cc |
OLD | NEW |