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