Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/base/scoped_ptr_deque.h" | 9 #include "cc/base/scoped_ptr_deque.h" |
| 10 #include "cc/base/scoped_ptr_hash_map.h" | 10 #include "cc/base/scoped_ptr_hash_map.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 memcpy(pixels, texture->data.get(), TextureSize(size, format)); | 260 memcpy(pixels, texture->data.get(), TextureSize(size, format)); |
| 261 } | 261 } |
| 262 | 262 |
| 263 WGC3Denum GetTextureFilter() { | 263 WGC3Denum GetTextureFilter() { |
| 264 DCHECK(current_texture_); | 264 DCHECK(current_texture_); |
| 265 Texture* texture = textures_.get(current_texture_); | 265 Texture* texture = textures_.get(current_texture_); |
| 266 DCHECK(texture); | 266 DCHECK(texture); |
| 267 return texture->filter; | 267 return texture->filter; |
| 268 } | 268 } |
| 269 | 269 |
| 270 gfx::Size GetCurrentTextureSize() { | |
| 271 DCHECK(current_texture_); | |
| 272 Texture* texture = textures_.get(current_texture_); | |
| 273 DCHECK(texture); | |
| 274 return texture->size; | |
| 275 } | |
| 276 | |
| 270 int texture_count() { return textures_.size(); } | 277 int texture_count() { return textures_.size(); } |
| 271 | 278 |
| 272 protected: | 279 protected: |
| 273 ResourceProviderContext(const Attributes& attrs, | 280 ResourceProviderContext(const Attributes& attrs, |
| 274 ContextSharedData* shared_data) | 281 ContextSharedData* shared_data) |
| 275 : TestWebGraphicsContext3D(attrs), | 282 : TestWebGraphicsContext3D(attrs), |
| 276 shared_data_(shared_data), | 283 shared_data_(shared_data), |
| 277 current_texture_(0), | 284 current_texture_(0), |
| 278 last_waited_sync_point_(0) {} | 285 last_waited_sync_point_(0) {} |
| 279 | 286 |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 id = resource_provider->CreateResource( | 1143 id = resource_provider->CreateResource( |
| 1137 size, format, ResourceProvider::TextureUsageAny); | 1144 size, format, ResourceProvider::TextureUsageAny); |
| 1138 resource_provider->AcquirePixelBuffer(id); | 1145 resource_provider->AcquirePixelBuffer(id); |
| 1139 resource_provider->BeginSetPixels(id); | 1146 resource_provider->BeginSetPixels(id); |
| 1140 resource_provider->ForceSetPixelsToComplete(id); | 1147 resource_provider->ForceSetPixelsToComplete(id); |
| 1141 resource_provider->AbortSetPixels(id); | 1148 resource_provider->AbortSetPixels(id); |
| 1142 resource_provider->ReleasePixelBuffer(id); | 1149 resource_provider->ReleasePixelBuffer(id); |
| 1143 Mock::VerifyAndClearExpectations(context); | 1150 Mock::VerifyAndClearExpectations(context); |
| 1144 } | 1151 } |
| 1145 | 1152 |
| 1153 void CheckResourceSize( | |
| 1154 ResourceProvider* resource_provider, | |
| 1155 ResourceProviderContext* context, | |
| 1156 ResourceProvider::ResourceId id, | |
| 1157 gfx::Size size) { | |
| 1158 switch (resource_provider->GetResourceType(id)) { | |
| 1159 case ResourceProvider::GLTexture: { | |
| 1160 // Enforce texture allocation. | |
| 1161 ResourceProvider::ScopedWriteLockGL lock(resource_provider, id); | |
| 1162 EXPECT_EQ(context->GetCurrentTextureSize(), size); | |
| 1163 break; | |
| 1164 } | |
| 1165 case ResourceProvider::Bitmap: { | |
| 1166 ResourceProvider::ScopedReadLockSoftware lock(resource_provider, id); | |
| 1167 EXPECT_EQ(lock.sk_bitmap()->width(), size.width()); | |
| 1168 EXPECT_EQ(lock.sk_bitmap()->height(), size.height()); | |
| 1169 | |
| 1170 // Ensure bitmap pixels were allocated during resize. | |
| 1171 lock.sk_bitmap()->lockPixels(); | |
| 1172 EXPECT_TRUE(lock.sk_bitmap()->getPixels()); | |
| 1173 lock.sk_bitmap()->unlockPixels(); | |
| 1174 break; | |
| 1175 } | |
| 1176 default: | |
|
piman
2013/03/22 20:52:34
nit: no need for default clause.
| |
| 1177 NOTREACHED(); | |
| 1178 break; | |
| 1179 } | |
| 1180 } | |
| 1181 | |
| 1182 TEST_P(ResourceProviderTest, ResizeResource) { | |
| 1183 gfx::Size size(1, 2); | |
| 1184 ResourceProvider::ResourceId id = resource_provider_->CreateResource( | |
| 1185 size, | |
| 1186 GL_RGBA, | |
| 1187 ResourceProvider::TextureUsageAny); | |
| 1188 ExpectNumResources(1); | |
| 1189 | |
| 1190 CheckResourceSize(resource_provider_.get(), context(), id, size); | |
| 1191 | |
| 1192 gfx::Size new_size(3, 4); | |
| 1193 resource_provider_->ResizeResource(id, new_size); | |
| 1194 ExpectNumResources(1); | |
| 1195 | |
| 1196 CheckResourceSize(resource_provider_.get(), context(), id, new_size); | |
| 1197 | |
| 1198 resource_provider_->DeleteResource(id); | |
| 1199 ExpectNumResources(0); | |
| 1200 } | |
| 1201 | |
| 1146 INSTANTIATE_TEST_CASE_P( | 1202 INSTANTIATE_TEST_CASE_P( |
| 1147 ResourceProviderTests, | 1203 ResourceProviderTests, |
| 1148 ResourceProviderTest, | 1204 ResourceProviderTest, |
| 1149 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1205 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 1150 | 1206 |
| 1151 } // namespace | 1207 } // namespace |
| 1152 } // namespace cc | 1208 } // namespace cc |
| OLD | NEW |