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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/resource_provider.h" | 7 #include "cc/resource_provider.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "cc/graphics_context.h" | 10 #include "cc/graphics_context.h" |
11 #include "cc/scoped_ptr_deque.h" | 11 #include "cc/scoped_ptr_deque.h" |
12 #include "cc/scoped_ptr_hash_map.h" | 12 #include "cc/scoped_ptr_hash_map.h" |
13 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread | 13 #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread |
14 #include "cc/test/compositor_fake_web_graphics_context_3d.h" | 14 #include "cc/test/compositor_fake_web_graphics_context_3d.h" |
15 #include "cc/test/fake_web_compositor_output_surface.h" | 15 #include "cc/test/fake_web_compositor_output_surface.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/khronos/GLES2/gl2.h" | 17 #include "third_party/khronos/GLES2/gl2.h" |
18 #include "third_party/khronos/GLES2/gl2ext.h" | 18 #include "third_party/khronos/GLES2/gl2ext.h" |
19 #include <public/WebGraphicsContext3D.h> | 19 #include <public/WebGraphicsContext3D.h> |
20 | 20 |
21 using namespace cc; | 21 using namespace cc; |
22 using namespace WebKit; | 22 using namespace WebKit; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 size_t textureSize(const IntSize& size, WGC3Denum format) | 26 size_t textureSize(const gfx::Size& size, WGC3Denum format) |
27 { | 27 { |
28 unsigned int componentsPerPixel = 4; | 28 unsigned int componentsPerPixel = 4; |
29 unsigned int bytesPerComponent = 1; | 29 unsigned int bytesPerComponent = 1; |
30 return size.width() * size.height() * componentsPerPixel * bytesPerComponent
; | 30 return size.width() * size.height() * componentsPerPixel * bytesPerComponent
; |
31 } | 31 } |
32 | 32 |
33 struct Texture { | 33 struct Texture { |
34 Texture(const IntSize& size, WGC3Denum format) | 34 Texture(const gfx::Size& size, WGC3Denum format) |
35 : size(size) | 35 : size(size) |
36 , format(format) | 36 , format(format) |
37 , data(new uint8_t[textureSize(size, format)]) | 37 , data(new uint8_t[textureSize(size, format)]) |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 IntSize size; | 41 gfx::Size size; |
42 WGC3Denum format; | 42 WGC3Denum format; |
43 scoped_array<uint8_t> data; | 43 scoped_array<uint8_t> data; |
44 }; | 44 }; |
45 | 45 |
46 // Shared data between multiple ResourceProviderContext. This contains mailbox | 46 // Shared data between multiple ResourceProviderContext. This contains mailbox |
47 // contents as well as information about sync points. | 47 // contents as well as information about sync points. |
48 class ContextSharedData { | 48 class ContextSharedData { |
49 public: | 49 public: |
50 static scoped_ptr<ContextSharedData> create() { return make_scoped_ptr(new C
ontextSharedData()); } | 50 static scoped_ptr<ContextSharedData> create() { return make_scoped_ptr(new C
ontextSharedData()); } |
51 | 51 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 WGC3Denum format = GL_RGBA; | 147 WGC3Denum format = GL_RGBA; |
148 switch (internalformat) { | 148 switch (internalformat) { |
149 case GL_RGBA8_OES: | 149 case GL_RGBA8_OES: |
150 break; | 150 break; |
151 case GL_BGRA8_EXT: | 151 case GL_BGRA8_EXT: |
152 format = GL_BGRA_EXT; | 152 format = GL_BGRA_EXT; |
153 break; | 153 break; |
154 default: | 154 default: |
155 NOTREACHED(); | 155 NOTREACHED(); |
156 } | 156 } |
157 allocateTexture(IntSize(width, height), format); | 157 allocateTexture(gfx::Size(width, height), format); |
158 } | 158 } |
159 | 159 |
160 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) | 160 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) |
161 { | 161 { |
162 ASSERT_TRUE(m_currentTexture); | 162 ASSERT_TRUE(m_currentTexture); |
163 ASSERT_EQ(target, GL_TEXTURE_2D); | 163 ASSERT_EQ(target, GL_TEXTURE_2D); |
164 ASSERT_FALSE(level); | 164 ASSERT_FALSE(level); |
165 ASSERT_EQ(internalformat, format); | 165 ASSERT_EQ(internalformat, format); |
166 ASSERT_FALSE(border); | 166 ASSERT_FALSE(border); |
167 ASSERT_EQ(type, GL_UNSIGNED_BYTE); | 167 ASSERT_EQ(type, GL_UNSIGNED_BYTE); |
168 allocateTexture(IntSize(width, height), format); | 168 allocateTexture(gfx::Size(width, height), format); |
169 if (pixels) | 169 if (pixels) |
170 setPixels(0, 0, width, height, pixels); | 170 setPixels(0, 0, width, height, pixels); |
171 } | 171 } |
172 | 172 |
173 virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffse
t, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3
Denum type, const void* pixels) | 173 virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffse
t, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3
Denum type, const void* pixels) |
174 { | 174 { |
175 ASSERT_TRUE(m_currentTexture); | 175 ASSERT_TRUE(m_currentTexture); |
176 ASSERT_EQ(target, GL_TEXTURE_2D); | 176 ASSERT_EQ(target, GL_TEXTURE_2D); |
177 ASSERT_FALSE(level); | 177 ASSERT_FALSE(level); |
178 ASSERT_TRUE(m_textures.get(m_currentTexture)); | 178 ASSERT_TRUE(m_textures.get(m_currentTexture)); |
(...skipping 19 matching lines...) Expand all Loading... |
198 m_pendingProduceTextures.append(pending.Pass()); | 198 m_pendingProduceTextures.append(pending.Pass()); |
199 } | 199 } |
200 | 200 |
201 virtual void consumeTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) | 201 virtual void consumeTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) |
202 { | 202 { |
203 ASSERT_TRUE(m_currentTexture); | 203 ASSERT_TRUE(m_currentTexture); |
204 ASSERT_EQ(target, GL_TEXTURE_2D); | 204 ASSERT_EQ(target, GL_TEXTURE_2D); |
205 m_textures.set(m_currentTexture, m_sharedData->consumeTexture(mailbox, m
_lastWaitedSyncPoint)); | 205 m_textures.set(m_currentTexture, m_sharedData->consumeTexture(mailbox, m
_lastWaitedSyncPoint)); |
206 } | 206 } |
207 | 207 |
208 void getPixels(const IntSize& size, WGC3Denum format, uint8_t* pixels) | 208 void getPixels(const gfx::Size& size, WGC3Denum format, uint8_t* pixels) |
209 { | 209 { |
210 ASSERT_TRUE(m_currentTexture); | 210 ASSERT_TRUE(m_currentTexture); |
211 Texture* texture = m_textures.get(m_currentTexture); | 211 Texture* texture = m_textures.get(m_currentTexture); |
212 ASSERT_TRUE(texture); | 212 ASSERT_TRUE(texture); |
213 ASSERT_EQ(texture->size, size); | 213 ASSERT_EQ(texture->size, size); |
214 ASSERT_EQ(texture->format, format); | 214 ASSERT_EQ(texture->format, format); |
215 memcpy(pixels, texture->data.get(), textureSize(size, format)); | 215 memcpy(pixels, texture->data.get(), textureSize(size, format)); |
216 } | 216 } |
217 | 217 |
218 int textureCount() | 218 int textureCount() |
219 { | 219 { |
220 return m_textures.size(); | 220 return m_textures.size(); |
221 } | 221 } |
222 | 222 |
223 protected: | 223 protected: |
224 ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedDa
ta) | 224 ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedDa
ta) |
225 : CompositorFakeWebGraphicsContext3D(attrs) | 225 : CompositorFakeWebGraphicsContext3D(attrs) |
226 , m_sharedData(sharedData) | 226 , m_sharedData(sharedData) |
227 , m_currentTexture(0) | 227 , m_currentTexture(0) |
228 , m_lastWaitedSyncPoint(0) | 228 , m_lastWaitedSyncPoint(0) |
229 { } | 229 { } |
230 | 230 |
231 private: | 231 private: |
232 void allocateTexture(const IntSize& size, WGC3Denum format) | 232 void allocateTexture(const gfx::Size& size, WGC3Denum format) |
233 { | 233 { |
234 ASSERT_TRUE(m_currentTexture); | 234 ASSERT_TRUE(m_currentTexture); |
235 m_textures.set(m_currentTexture, make_scoped_ptr(new Texture(size, forma
t))); | 235 m_textures.set(m_currentTexture, make_scoped_ptr(new Texture(size, forma
t))); |
236 } | 236 } |
237 | 237 |
238 void setPixels(int xoffset, int yoffset, int width, int height, const void*
pixels) | 238 void setPixels(int xoffset, int yoffset, int width, int height, const void*
pixels) |
239 { | 239 { |
240 ASSERT_TRUE(m_currentTexture); | 240 ASSERT_TRUE(m_currentTexture); |
241 Texture* texture = m_textures.get(m_currentTexture); | 241 Texture* texture = m_textures.get(m_currentTexture); |
242 ASSERT_TRUE(texture); | 242 ASSERT_TRUE(texture); |
243 ASSERT_TRUE(xoffset >= 0 && xoffset+width <= texture->size.width()); | 243 ASSERT_TRUE(xoffset >= 0 && xoffset+width <= texture->size.width()); |
244 ASSERT_TRUE(yoffset >= 0 && yoffset+height <= texture->size.height()); | 244 ASSERT_TRUE(yoffset >= 0 && yoffset+height <= texture->size.height()); |
245 ASSERT_TRUE(pixels); | 245 ASSERT_TRUE(pixels); |
246 size_t inPitch = textureSize(IntSize(width, 1), texture->format); | 246 size_t inPitch = textureSize(gfx::Size(width, 1), texture->format); |
247 size_t outPitch = textureSize(IntSize(texture->size.width(), 1), texture
->format); | 247 size_t outPitch = textureSize(gfx::Size(texture->size.width(), 1), textu
re->format); |
248 uint8_t* dest = texture->data.get() + yoffset * outPitch + textureSize(I
ntSize(xoffset, 1), texture->format); | 248 uint8_t* dest = texture->data.get() + yoffset * outPitch + textureSize(g
fx::Size(xoffset, 1), texture->format); |
249 const uint8_t* src = static_cast<const uint8_t*>(pixels); | 249 const uint8_t* src = static_cast<const uint8_t*>(pixels); |
250 for (int i = 0; i < height; ++i) { | 250 for (int i = 0; i < height; ++i) { |
251 memcpy(dest, src, inPitch); | 251 memcpy(dest, src, inPitch); |
252 dest += outPitch; | 252 dest += outPitch; |
253 src += inPitch; | 253 src += inPitch; |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 typedef ScopedPtrHashMap<WebGLId, Texture> TextureMap; | 257 typedef ScopedPtrHashMap<WebGLId, Texture> TextureMap; |
258 struct PendingProduceTexture { | 258 struct PendingProduceTexture { |
(...skipping 13 matching lines...) Expand all Loading... |
272 ResourceProviderTest() | 272 ResourceProviderTest() |
273 : m_sharedData(ContextSharedData::create()) | 273 : m_sharedData(ContextSharedData::create()) |
274 , m_context(FakeWebCompositorOutputSurface::create(ResourceProviderConte
xt::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<Web
Kit::WebGraphicsContext3D>())) | 274 , m_context(FakeWebCompositorOutputSurface::create(ResourceProviderConte
xt::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<Web
Kit::WebGraphicsContext3D>())) |
275 , m_resourceProvider(ResourceProvider::create(m_context.get())) | 275 , m_resourceProvider(ResourceProvider::create(m_context.get())) |
276 { | 276 { |
277 m_resourceProvider->setDefaultResourceType(GetParam()); | 277 m_resourceProvider->setDefaultResourceType(GetParam()); |
278 } | 278 } |
279 | 279 |
280 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_context->context3D()); } | 280 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_context->context3D()); } |
281 | 281 |
282 void getResourcePixels(ResourceProvider::ResourceId id, const IntSize& size,
WGC3Denum format, uint8_t* pixels) | 282 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz
e, WGC3Denum format, uint8_t* pixels) |
283 { | 283 { |
284 if (GetParam() == ResourceProvider::GLTexture) { | 284 if (GetParam() == ResourceProvider::GLTexture) { |
285 ResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get(),
id); | 285 ResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get(),
id); |
286 ASSERT_NE(0U, lockGL.textureId()); | 286 ASSERT_NE(0U, lockGL.textureId()); |
287 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); | 287 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); |
288 context()->getPixels(size, format, pixels); | 288 context()->getPixels(size, format, pixels); |
289 } else if (GetParam() == ResourceProvider::Bitmap) { | 289 } else if (GetParam() == ResourceProvider::Bitmap) { |
290 ResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourceProv
ider.get(), id); | 290 ResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourceProv
ider.get(), id); |
291 memcpy(pixels, lockSoftware.skBitmap()->getPixels(), lockSoftware.sk
Bitmap()->getSize()); | 291 memcpy(pixels, lockSoftware.skBitmap()->getPixels(), lockSoftware.sk
Bitmap()->getSize()); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 void expectNumResources(int count) | 295 void expectNumResources(int count) |
296 { | 296 { |
297 EXPECT_EQ(count, static_cast<int>(m_resourceProvider->numResources())); | 297 EXPECT_EQ(count, static_cast<int>(m_resourceProvider->numResources())); |
298 if (GetParam() == ResourceProvider::GLTexture) | 298 if (GetParam() == ResourceProvider::GLTexture) |
299 EXPECT_EQ(count, context()->textureCount()); | 299 EXPECT_EQ(count, context()->textureCount()); |
300 } | 300 } |
301 | 301 |
302 protected: | 302 protected: |
303 DebugScopedSetImplThread implThread; | 303 DebugScopedSetImplThread implThread; |
304 scoped_ptr<ContextSharedData> m_sharedData; | 304 scoped_ptr<ContextSharedData> m_sharedData; |
305 scoped_ptr<GraphicsContext> m_context; | 305 scoped_ptr<GraphicsContext> m_context; |
306 scoped_ptr<ResourceProvider> m_resourceProvider; | 306 scoped_ptr<ResourceProvider> m_resourceProvider; |
307 }; | 307 }; |
308 | 308 |
309 TEST_P(ResourceProviderTest, Basic) | 309 TEST_P(ResourceProviderTest, Basic) |
310 { | 310 { |
311 IntSize size(1, 1); | 311 gfx::Size size(1, 1); |
312 WGC3Denum format = GL_RGBA; | 312 WGC3Denum format = GL_RGBA; |
313 int pool = 1; | 313 int pool = 1; |
314 size_t pixelSize = textureSize(size, format); | 314 size_t pixelSize = textureSize(size, format); |
315 ASSERT_EQ(4U, pixelSize); | 315 ASSERT_EQ(4U, pixelSize); |
316 | 316 |
317 ResourceProvider::ResourceId id = m_resourceProvider->createResource(pool, s
ize, format, ResourceProvider::TextureUsageAny); | 317 ResourceProvider::ResourceId id = m_resourceProvider->createResource(pool, s
ize, format, ResourceProvider::TextureUsageAny); |
318 expectNumResources(1); | 318 expectNumResources(1); |
319 | 319 |
320 uint8_t data[4] = {1, 2, 3, 4}; | 320 uint8_t data[4] = {1, 2, 3, 4}; |
321 IntRect rect(IntPoint(), size); | 321 gfx::Rect rect(gfx::Point(), size); |
322 m_resourceProvider->upload(id, data, rect, rect, IntSize()); | 322 m_resourceProvider->upload(id, data, rect, rect, gfx::Vector2d()); |
323 | 323 |
324 uint8_t result[4] = {0}; | 324 uint8_t result[4] = {0}; |
325 getResourcePixels(id, size, format, result); | 325 getResourcePixels(id, size, format, result); |
326 EXPECT_EQ(0, memcmp(data, result, pixelSize)); | 326 EXPECT_EQ(0, memcmp(data, result, pixelSize)); |
327 | 327 |
328 m_resourceProvider->deleteResource(id); | 328 m_resourceProvider->deleteResource(id); |
329 expectNumResources(0); | 329 expectNumResources(0); |
330 } | 330 } |
331 | 331 |
332 TEST_P(ResourceProviderTest, DeleteOwnedResources) | 332 TEST_P(ResourceProviderTest, DeleteOwnedResources) |
333 { | 333 { |
334 IntSize size(1, 1); | 334 gfx::Size size(1, 1); |
335 WGC3Denum format = GL_RGBA; | 335 WGC3Denum format = GL_RGBA; |
336 int pool = 1; | 336 int pool = 1; |
337 | 337 |
338 const int count = 3; | 338 const int count = 3; |
339 for (int i = 0; i < count; ++i) | 339 for (int i = 0; i < count; ++i) |
340 m_resourceProvider->createResource(pool, size, format, ResourceProvider:
:TextureUsageAny); | 340 m_resourceProvider->createResource(pool, size, format, ResourceProvider:
:TextureUsageAny); |
341 expectNumResources(3); | 341 expectNumResources(3); |
342 | 342 |
343 m_resourceProvider->deleteOwnedResources(pool+1); | 343 m_resourceProvider->deleteOwnedResources(pool+1); |
344 expectNumResources(3); | 344 expectNumResources(3); |
345 | 345 |
346 m_resourceProvider->deleteOwnedResources(pool); | 346 m_resourceProvider->deleteOwnedResources(pool); |
347 expectNumResources(0); | 347 expectNumResources(0); |
348 } | 348 } |
349 | 349 |
350 TEST_P(ResourceProviderTest, Upload) | 350 TEST_P(ResourceProviderTest, Upload) |
351 { | 351 { |
352 IntSize size(2, 2); | 352 gfx::Size size(2, 2); |
353 WGC3Denum format = GL_RGBA; | 353 WGC3Denum format = GL_RGBA; |
354 int pool = 1; | 354 int pool = 1; |
355 size_t pixelSize = textureSize(size, format); | 355 size_t pixelSize = textureSize(size, format); |
356 ASSERT_EQ(16U, pixelSize); | 356 ASSERT_EQ(16U, pixelSize); |
357 | 357 |
358 ResourceProvider::ResourceId id = m_resourceProvider->createResource(pool, s
ize, format, ResourceProvider::TextureUsageAny); | 358 ResourceProvider::ResourceId id = m_resourceProvider->createResource(pool, s
ize, format, ResourceProvider::TextureUsageAny); |
359 | 359 |
360 uint8_t image[16] = {0}; | 360 uint8_t image[16] = {0}; |
361 IntRect imageRect(IntPoint(), size); | 361 gfx::Rect imageRect(gfx::Point(), size); |
362 m_resourceProvider->upload(id, image, imageRect, imageRect, IntSize()); | 362 m_resourceProvider->upload(id, image, imageRect, imageRect, gfx::Vector2d())
; |
363 | 363 |
364 for (uint8_t i = 0 ; i < pixelSize; ++i) | 364 for (uint8_t i = 0 ; i < pixelSize; ++i) |
365 image[i] = i; | 365 image[i] = i; |
366 | 366 |
367 uint8_t result[16] = {0}; | 367 uint8_t result[16] = {0}; |
368 { | 368 { |
369 IntRect sourceRect(0, 0, 1, 1); | 369 gfx::Rect sourceRect(0, 0, 1, 1); |
370 IntSize destOffset(0, 0); | 370 gfx::Vector2d destOffset(0, 0); |
371 m_resourceProvider->upload(id, image, imageRect, sourceRect, destOffset)
; | 371 m_resourceProvider->upload(id, image, imageRect, sourceRect, destOffset)
; |
372 | 372 |
373 uint8_t expected[16] = {0, 1, 2, 3, 0, 0, 0, 0, | 373 uint8_t expected[16] = {0, 1, 2, 3, 0, 0, 0, 0, |
374 0, 0, 0, 0, 0, 0, 0, 0}; | 374 0, 0, 0, 0, 0, 0, 0, 0}; |
375 getResourcePixels(id, size, format, result); | 375 getResourcePixels(id, size, format, result); |
376 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); | 376 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); |
377 } | 377 } |
378 { | 378 { |
379 IntRect sourceRect(0, 0, 1, 1); | 379 gfx::Rect sourceRect(0, 0, 1, 1); |
380 IntSize destOffset(1, 1); | 380 gfx::Vector2d destOffset(1, 1); |
381 m_resourceProvider->upload(id, image, imageRect, sourceRect, destOffset)
; | 381 m_resourceProvider->upload(id, image, imageRect, sourceRect, destOffset)
; |
382 | 382 |
383 uint8_t expected[16] = {0, 1, 2, 3, 0, 0, 0, 0, | 383 uint8_t expected[16] = {0, 1, 2, 3, 0, 0, 0, 0, |
384 0, 0, 0, 0, 0, 1, 2, 3}; | 384 0, 0, 0, 0, 0, 1, 2, 3}; |
385 getResourcePixels(id, size, format, result); | 385 getResourcePixels(id, size, format, result); |
386 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); | 386 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); |
387 } | 387 } |
388 { | 388 { |
389 IntRect sourceRect(1, 0, 1, 1); | 389 gfx::Rect sourceRect(1, 0, 1, 1); |
390 IntSize destOffset(0, 1); | 390 gfx::Vector2d destOffset(0, 1); |
391 m_resourceProvider->upload(id, image, imageRect, sourceRect, destOffset)
; | 391 m_resourceProvider->upload(id, image, imageRect, sourceRect, destOffset)
; |
392 | 392 |
393 uint8_t expected[16] = {0, 1, 2, 3, 0, 0, 0, 0, | 393 uint8_t expected[16] = {0, 1, 2, 3, 0, 0, 0, 0, |
394 4, 5, 6, 7, 0, 1, 2, 3}; | 394 4, 5, 6, 7, 0, 1, 2, 3}; |
395 getResourcePixels(id, size, format, result); | 395 getResourcePixels(id, size, format, result); |
396 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); | 396 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); |
397 } | 397 } |
398 { | 398 { |
399 IntRect offsetImageRect(IntPoint(100, 100), size); | 399 gfx::Rect offsetImageRect(gfx::Point(100, 100), size); |
400 IntRect sourceRect(100, 100, 1, 1); | 400 gfx::Rect sourceRect(100, 100, 1, 1); |
401 IntSize destOffset(1, 0); | 401 gfx::Vector2d destOffset(1, 0); |
402 m_resourceProvider->upload(id, image, offsetImageRect, sourceRect, destO
ffset); | 402 m_resourceProvider->upload(id, image, offsetImageRect, sourceRect, destO
ffset); |
403 | 403 |
404 uint8_t expected[16] = {0, 1, 2, 3, 0, 1, 2, 3, | 404 uint8_t expected[16] = {0, 1, 2, 3, 0, 1, 2, 3, |
405 4, 5, 6, 7, 0, 1, 2, 3}; | 405 4, 5, 6, 7, 0, 1, 2, 3}; |
406 getResourcePixels(id, size, format, result); | 406 getResourcePixels(id, size, format, result); |
407 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); | 407 EXPECT_EQ(0, memcmp(expected, result, pixelSize)); |
408 } | 408 } |
409 | 409 |
410 | 410 |
411 m_resourceProvider->deleteResource(id); | 411 m_resourceProvider->deleteResource(id); |
412 } | 412 } |
413 | 413 |
414 TEST_P(ResourceProviderTest, TransferResources) | 414 TEST_P(ResourceProviderTest, TransferResources) |
415 { | 415 { |
416 // Resource transfer is only supported with GL textures for now. | 416 // Resource transfer is only supported with GL textures for now. |
417 if (GetParam() != ResourceProvider::GLTexture) | 417 if (GetParam() != ResourceProvider::GLTexture) |
418 return; | 418 return; |
419 | 419 |
420 scoped_ptr<GraphicsContext> childContext(FakeWebCompositorOutputSurface::cre
ate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphi
csContext3D>())); | 420 scoped_ptr<GraphicsContext> childContext(FakeWebCompositorOutputSurface::cre
ate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphi
csContext3D>())); |
421 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childContext.get())); | 421 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childContext.get())); |
422 | 422 |
423 IntSize size(1, 1); | 423 gfx::Size size(1, 1); |
424 WGC3Denum format = GL_RGBA; | 424 WGC3Denum format = GL_RGBA; |
425 int pool = 1; | 425 int pool = 1; |
426 size_t pixelSize = textureSize(size, format); | 426 size_t pixelSize = textureSize(size, format); |
427 ASSERT_EQ(4U, pixelSize); | 427 ASSERT_EQ(4U, pixelSize); |
428 | 428 |
429 ResourceProvider::ResourceId id1 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); | 429 ResourceProvider::ResourceId id1 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); |
430 uint8_t data1[4] = {1, 2, 3, 4}; | 430 uint8_t data1[4] = {1, 2, 3, 4}; |
431 IntRect rect(IntPoint(), size); | 431 gfx::Rect rect(gfx::Point(), size); |
432 childResourceProvider->upload(id1, data1, rect, rect, IntSize()); | 432 childResourceProvider->upload(id1, data1, rect, rect, gfx::Vector2d()); |
433 | 433 |
434 ResourceProvider::ResourceId id2 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); | 434 ResourceProvider::ResourceId id2 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); |
435 uint8_t data2[4] = {5, 5, 5, 5}; | 435 uint8_t data2[4] = {5, 5, 5, 5}; |
436 childResourceProvider->upload(id2, data2, rect, rect, IntSize()); | 436 childResourceProvider->upload(id2, data2, rect, rect, gfx::Vector2d()); |
437 | 437 |
438 int childPool = 2; | 438 int childPool = 2; |
439 int childId = m_resourceProvider->createChild(childPool); | 439 int childId = m_resourceProvider->createChild(childPool); |
440 | 440 |
441 { | 441 { |
442 // Transfer some resources to the parent. | 442 // Transfer some resources to the parent. |
443 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | 443 ResourceProvider::ResourceIdArray resourceIdsToTransfer; |
444 resourceIdsToTransfer.push_back(id1); | 444 resourceIdsToTransfer.push_back(id1); |
445 resourceIdsToTransfer.push_back(id2); | 445 resourceIdsToTransfer.push_back(id2); |
446 ResourceProvider::TransferableResourceList list = childResourceProvider-
>prepareSendToParent(resourceIdsToTransfer); | 446 ResourceProvider::TransferableResourceList list = childResourceProvider-
>prepareSendToParent(resourceIdsToTransfer); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 530 |
531 TEST_P(ResourceProviderTest, DeleteTransferredResources) | 531 TEST_P(ResourceProviderTest, DeleteTransferredResources) |
532 { | 532 { |
533 // Resource transfer is only supported with GL textures for now. | 533 // Resource transfer is only supported with GL textures for now. |
534 if (GetParam() != ResourceProvider::GLTexture) | 534 if (GetParam() != ResourceProvider::GLTexture) |
535 return; | 535 return; |
536 | 536 |
537 scoped_ptr<GraphicsContext> childContext(FakeWebCompositorOutputSurface::cre
ate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphi
csContext3D>())); | 537 scoped_ptr<GraphicsContext> childContext(FakeWebCompositorOutputSurface::cre
ate(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphi
csContext3D>())); |
538 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childContext.get())); | 538 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childContext.get())); |
539 | 539 |
540 IntSize size(1, 1); | 540 gfx::Size size(1, 1); |
541 WGC3Denum format = GL_RGBA; | 541 WGC3Denum format = GL_RGBA; |
542 int pool = 1; | 542 int pool = 1; |
543 size_t pixelSize = textureSize(size, format); | 543 size_t pixelSize = textureSize(size, format); |
544 ASSERT_EQ(4U, pixelSize); | 544 ASSERT_EQ(4U, pixelSize); |
545 | 545 |
546 ResourceProvider::ResourceId id = childResourceProvider->createResource(pool
, size, format, ResourceProvider::TextureUsageAny); | 546 ResourceProvider::ResourceId id = childResourceProvider->createResource(pool
, size, format, ResourceProvider::TextureUsageAny); |
547 uint8_t data[4] = {1, 2, 3, 4}; | 547 uint8_t data[4] = {1, 2, 3, 4}; |
548 IntRect rect(IntPoint(), size); | 548 gfx::Rect rect(gfx::Point(), size); |
549 childResourceProvider->upload(id, data, rect, rect, IntSize()); | 549 childResourceProvider->upload(id, data, rect, rect, gfx::Vector2d()); |
550 | 550 |
551 int childPool = 2; | 551 int childPool = 2; |
552 int childId = m_resourceProvider->createChild(childPool); | 552 int childId = m_resourceProvider->createChild(childPool); |
553 | 553 |
554 { | 554 { |
555 // Transfer some resource to the parent. | 555 // Transfer some resource to the parent. |
556 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | 556 ResourceProvider::ResourceIdArray resourceIdsToTransfer; |
557 resourceIdsToTransfer.push_back(id); | 557 resourceIdsToTransfer.push_back(id); |
558 ResourceProvider::TransferableResourceList list = childResourceProvider-
>prepareSendToParent(resourceIdsToTransfer); | 558 ResourceProvider::TransferableResourceList list = childResourceProvider-
>prepareSendToParent(resourceIdsToTransfer); |
559 EXPECT_NE(0u, list.syncPoint); | 559 EXPECT_NE(0u, list.syncPoint); |
(...skipping 20 matching lines...) Expand all Loading... |
580 } | 580 } |
581 EXPECT_EQ(0u, childResourceProvider->numResources()); | 581 EXPECT_EQ(0u, childResourceProvider->numResources()); |
582 } | 582 } |
583 | 583 |
584 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 584 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
585 ResourceProviderTest, | 585 ResourceProviderTest, |
586 ::testing::Values(ResourceProvider::GLTexture, | 586 ::testing::Values(ResourceProvider::GLTexture, |
587 ResourceProvider::Bitmap)); | 587 ResourceProvider::Bitmap)); |
588 | 588 |
589 } // namespace | 589 } // namespace |
OLD | NEW |