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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 888 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
889 | 889 |
890 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( | 890 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( |
891 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 891 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
892 uint8_t data2[4] = { 5, 5, 5, 5 }; | 892 uint8_t data2[4] = { 5, 5, 5, 5 }; |
893 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 893 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
894 | 894 |
895 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( | 895 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( |
896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
897 uint8_t data3[4] = { 6, 7, 8, 9 }; | 897 uint8_t data3[4] = { 6, 7, 8, 9 }; |
898 SkBitmap bitmap3; | 898 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |
899 bitmap3.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); | |
900 bitmap3.setPixels(data3); | |
901 SkCanvas* raster_canvas = child_resource_provider_->MapImageRasterBuffer(id3); | 899 SkCanvas* raster_canvas = child_resource_provider_->MapImageRasterBuffer(id3); |
902 raster_canvas->writePixels(bitmap3, 0, 0); | 900 raster_canvas->writePixels(info, data3, info.minRowBytes(), 0, 0); |
903 child_resource_provider_->UnmapImageRasterBuffer(id3); | 901 child_resource_provider_->UnmapImageRasterBuffer(id3); |
904 | 902 |
905 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 903 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
906 shared_memory->CreateAndMapAnonymous(1); | 904 shared_memory->CreateAndMapAnonymous(1); |
907 base::SharedMemory* shared_memory_ptr = shared_memory.get(); | 905 base::SharedMemory* shared_memory_ptr = shared_memory.get(); |
908 ResourceProvider::ResourceId id4 = | 906 ResourceProvider::ResourceId id4 = |
909 child_resource_provider_->CreateResourceFromTextureMailbox( | 907 child_resource_provider_->CreateResourceFromTextureMailbox( |
910 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), | 908 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), |
911 SingleReleaseCallback::Create(base::Bind( | 909 SingleReleaseCallback::Create(base::Bind( |
912 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); | 910 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); |
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2876 const uint32_t kBadBeef = 0xbadbeef; | 2874 const uint32_t kBadBeef = 0xbadbeef; |
2877 | 2875 |
2878 scoped_ptr<ResourceProvider> resource_provider( | 2876 scoped_ptr<ResourceProvider> resource_provider( |
2879 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2877 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2880 | 2878 |
2881 id = resource_provider->CreateResource( | 2879 id = resource_provider->CreateResource( |
2882 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2880 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2883 resource_provider->AcquirePixelRasterBuffer(id); | 2881 resource_provider->AcquirePixelRasterBuffer(id); |
2884 | 2882 |
2885 SkBitmap bitmap; | 2883 SkBitmap bitmap; |
2886 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); | 2884 bitmap.allocN32Pixels(size.width(), size.height()); |
2887 bitmap.allocPixels(); | |
2888 *(bitmap.getAddr32(0, 0)) = kBadBeef; | 2885 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
2889 SkCanvas* canvas = resource_provider->MapPixelRasterBuffer(id); | 2886 SkCanvas* canvas = resource_provider->MapPixelRasterBuffer(id); |
2890 canvas->writePixels(bitmap, 0, 0); | 2887 canvas->writePixels(bitmap, 0, 0); |
2891 resource_provider->UnmapPixelRasterBuffer(id); | 2888 resource_provider->UnmapPixelRasterBuffer(id); |
2892 | 2889 |
2893 resource_provider->BeginSetPixels(id); | 2890 resource_provider->BeginSetPixels(id); |
2894 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2891 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2895 | 2892 |
2896 resource_provider->ReleasePixelRasterBuffer(id); | 2893 resource_provider->ReleasePixelRasterBuffer(id); |
2897 | 2894 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3096 ResourceProvider::ResourceId id = 0; | 3093 ResourceProvider::ResourceId id = 0; |
3097 const uint32_t kBadBeef = 0xbadbeef; | 3094 const uint32_t kBadBeef = 0xbadbeef; |
3098 | 3095 |
3099 scoped_ptr<ResourceProvider> resource_provider( | 3096 scoped_ptr<ResourceProvider> resource_provider( |
3100 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 3097 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
3101 | 3098 |
3102 id = resource_provider->CreateResource( | 3099 id = resource_provider->CreateResource( |
3103 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 3100 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
3104 | 3101 |
3105 SkBitmap bitmap; | 3102 SkBitmap bitmap; |
3106 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); | 3103 bitmap.allocN32Pixels(size.width(), size.height()); |
3107 bitmap.allocPixels(); | |
3108 *(bitmap.getAddr32(0, 0)) = kBadBeef; | 3104 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
3109 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); | 3105 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); |
3110 ASSERT_TRUE(!!canvas); | 3106 ASSERT_TRUE(!!canvas); |
3111 canvas->writePixels(bitmap, 0, 0); | 3107 canvas->writePixels(bitmap, 0, 0); |
3112 resource_provider->UnmapImageRasterBuffer(id); | 3108 resource_provider->UnmapImageRasterBuffer(id); |
3113 | 3109 |
3114 { | 3110 { |
3115 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 3111 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
3116 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 3112 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
3117 EXPECT_EQ(sk_bitmap->width(), size.width()); | 3113 EXPECT_EQ(sk_bitmap->width(), size.width()); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3299 resource_provider->AllocateForTesting(id); | 3295 resource_provider->AllocateForTesting(id); |
3300 Mock::VerifyAndClearExpectations(context); | 3296 Mock::VerifyAndClearExpectations(context); |
3301 | 3297 |
3302 DCHECK_EQ(10u, context->PeekTextureId()); | 3298 DCHECK_EQ(10u, context->PeekTextureId()); |
3303 resource_provider->DeleteResource(id); | 3299 resource_provider->DeleteResource(id); |
3304 } | 3300 } |
3305 } | 3301 } |
3306 | 3302 |
3307 } // namespace | 3303 } // namespace |
3308 } // namespace cc | 3304 } // namespace cc |
OLD | NEW |