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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 WGC3Dint xoffset, | 210 WGC3Dint xoffset, |
211 WGC3Dint yoffset, | 211 WGC3Dint yoffset, |
212 WGC3Dsizei width, | 212 WGC3Dsizei width, |
213 WGC3Dsizei height, | 213 WGC3Dsizei height, |
214 WGC3Denum format, | 214 WGC3Denum format, |
215 WGC3Denum type, | 215 WGC3Denum type, |
216 const void* pixels) OVERRIDE { | 216 const void* pixels) OVERRIDE { |
217 ASSERT_TRUE(current_texture_); | 217 ASSERT_TRUE(current_texture_); |
218 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 218 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
219 ASSERT_FALSE(level); | 219 ASSERT_FALSE(level); |
220 ASSERT_TRUE(textures_[current_texture_]); | 220 ASSERT_TRUE(textures_[current_texture_].get()); |
221 ASSERT_EQ(textures_[current_texture_]->format, format); | 221 ASSERT_EQ(textures_[current_texture_]->format, format); |
222 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 222 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
223 ASSERT_TRUE(pixels); | 223 ASSERT_TRUE(pixels); |
224 SetPixels(xoffset, yoffset, width, height, pixels); | 224 SetPixels(xoffset, yoffset, width, height, pixels); |
225 } | 225 } |
226 | 226 |
227 virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value) | 227 virtual void texParameteri(WGC3Denum target, WGC3Denum param, WGC3Dint value) |
228 OVERRIDE { | 228 OVERRIDE { |
229 ASSERT_TRUE(current_texture_); | 229 ASSERT_TRUE(current_texture_); |
230 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 230 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
231 scoped_refptr<Texture> texture = textures_[current_texture_]; | 231 scoped_refptr<Texture> texture = textures_[current_texture_]; |
232 ASSERT_TRUE(texture); | 232 ASSERT_TRUE(texture.get()); |
233 if (param != GL_TEXTURE_MIN_FILTER) | 233 if (param != GL_TEXTURE_MIN_FILTER) |
234 return; | 234 return; |
235 texture->filter = value; | 235 texture->filter = value; |
236 } | 236 } |
237 | 237 |
238 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) OVERRIDE { | 238 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) OVERRIDE { |
239 return shared_data_->GenMailbox(mailbox); | 239 return shared_data_->GenMailbox(mailbox); |
240 } | 240 } |
241 | 241 |
242 virtual void produceTextureCHROMIUM(WGC3Denum target, | 242 virtual void produceTextureCHROMIUM(WGC3Denum target, |
(...skipping 14 matching lines...) Expand all Loading... |
257 const WGC3Dbyte* mailbox) OVERRIDE { | 257 const WGC3Dbyte* mailbox) OVERRIDE { |
258 ASSERT_TRUE(current_texture_); | 258 ASSERT_TRUE(current_texture_); |
259 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 259 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
260 textures_[current_texture_] = shared_data_->ConsumeTexture( | 260 textures_[current_texture_] = shared_data_->ConsumeTexture( |
261 mailbox, last_waited_sync_point_); | 261 mailbox, last_waited_sync_point_); |
262 } | 262 } |
263 | 263 |
264 void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) { | 264 void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) { |
265 ASSERT_TRUE(current_texture_); | 265 ASSERT_TRUE(current_texture_); |
266 scoped_refptr<Texture> texture = textures_[current_texture_]; | 266 scoped_refptr<Texture> texture = textures_[current_texture_]; |
267 ASSERT_TRUE(texture); | 267 ASSERT_TRUE(texture.get()); |
268 ASSERT_EQ(texture->size, size); | 268 ASSERT_EQ(texture->size, size); |
269 ASSERT_EQ(texture->format, format); | 269 ASSERT_EQ(texture->format, format); |
270 memcpy(pixels, texture->data.get(), TextureSize(size, format)); | 270 memcpy(pixels, texture->data.get(), TextureSize(size, format)); |
271 } | 271 } |
272 | 272 |
273 WGC3Denum GetTextureFilter() { | 273 WGC3Denum GetTextureFilter() { |
274 DCHECK(current_texture_); | 274 DCHECK(current_texture_); |
275 scoped_refptr<Texture> texture = textures_[current_texture_]; | 275 scoped_refptr<Texture> texture = textures_[current_texture_]; |
276 DCHECK(texture); | 276 DCHECK(texture.get()); |
277 return texture->filter; | 277 return texture->filter; |
278 } | 278 } |
279 | 279 |
280 int texture_count() { return textures_.size(); } | 280 int texture_count() { return textures_.size(); } |
281 | 281 |
282 protected: | 282 protected: |
283 ResourceProviderContext(const Attributes& attrs, | 283 ResourceProviderContext(const Attributes& attrs, |
284 ContextSharedData* shared_data) | 284 ContextSharedData* shared_data) |
285 : TestWebGraphicsContext3D(attrs), | 285 : TestWebGraphicsContext3D(attrs), |
286 shared_data_(shared_data), | 286 shared_data_(shared_data), |
287 current_texture_(0), | 287 current_texture_(0), |
288 last_waited_sync_point_(0) {} | 288 last_waited_sync_point_(0) {} |
289 | 289 |
290 private: | 290 private: |
291 void AllocateTexture(gfx::Size size, WGC3Denum format) { | 291 void AllocateTexture(gfx::Size size, WGC3Denum format) { |
292 ASSERT_TRUE(current_texture_); | 292 ASSERT_TRUE(current_texture_); |
293 scoped_refptr<Texture> texture = textures_[current_texture_]; | 293 scoped_refptr<Texture> texture = textures_[current_texture_]; |
294 ASSERT_TRUE(texture); | 294 ASSERT_TRUE(texture.get()); |
295 texture->Reallocate(size, format); | 295 texture->Reallocate(size, format); |
296 } | 296 } |
297 | 297 |
298 void SetPixels(int xoffset, | 298 void SetPixels(int xoffset, |
299 int yoffset, | 299 int yoffset, |
300 int width, | 300 int width, |
301 int height, | 301 int height, |
302 const void* pixels) { | 302 const void* pixels) { |
303 ASSERT_TRUE(current_texture_); | 303 ASSERT_TRUE(current_texture_); |
304 scoped_refptr<Texture> texture = textures_[current_texture_]; | 304 scoped_refptr<Texture> texture = textures_[current_texture_]; |
305 ASSERT_TRUE(texture); | 305 ASSERT_TRUE(texture.get()); |
306 ASSERT_TRUE(texture->data.get()); | 306 ASSERT_TRUE(texture->data.get()); |
307 ASSERT_TRUE(xoffset >= 0 && xoffset + width <= texture->size.width()); | 307 ASSERT_TRUE(xoffset >= 0 && xoffset + width <= texture->size.width()); |
308 ASSERT_TRUE(yoffset >= 0 && yoffset + height <= texture->size.height()); | 308 ASSERT_TRUE(yoffset >= 0 && yoffset + height <= texture->size.height()); |
309 ASSERT_TRUE(pixels); | 309 ASSERT_TRUE(pixels); |
310 size_t in_pitch = TextureSize(gfx::Size(width, 1), texture->format); | 310 size_t in_pitch = TextureSize(gfx::Size(width, 1), texture->format); |
311 size_t out_pitch = | 311 size_t out_pitch = |
312 TextureSize(gfx::Size(texture->size.width(), 1), texture->format); | 312 TextureSize(gfx::Size(texture->size.width(), 1), texture->format); |
313 uint8_t* dest = texture->data.get() + yoffset * out_pitch + | 313 uint8_t* dest = texture->data.get() + yoffset * out_pitch + |
314 TextureSize(gfx::Size(xoffset, 1), texture->format); | 314 TextureSize(gfx::Size(xoffset, 1), texture->format); |
315 const uint8_t* src = static_cast<const uint8_t*>(pixels); | 315 const uint8_t* src = static_cast<const uint8_t*>(pixels); |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 .RetiresOnSaturation(); | 1554 .RetiresOnSaturation(); |
1555 } | 1555 } |
1556 | 1556 |
1557 INSTANTIATE_TEST_CASE_P( | 1557 INSTANTIATE_TEST_CASE_P( |
1558 ResourceProviderTests, | 1558 ResourceProviderTests, |
1559 ResourceProviderTest, | 1559 ResourceProviderTest, |
1560 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1560 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
1561 | 1561 |
1562 } // namespace | 1562 } // namespace |
1563 } // namespace cc | 1563 } // namespace cc |
OLD | NEW |