Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: cc/resources/resource_provider_unittest.cc

Issue 105103004: Convert cc resource system over to GLES2Interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/resource_update_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "cc/base/scoped_ptr_deque.h" 14 #include "cc/base/scoped_ptr_deque.h"
15 #include "cc/output/output_surface.h" 15 #include "cc/output/output_surface.h"
16 #include "cc/resources/returned_resource.h" 16 #include "cc/resources/returned_resource.h"
17 #include "cc/resources/shared_bitmap_manager.h" 17 #include "cc/resources/shared_bitmap_manager.h"
18 #include "cc/resources/single_release_callback.h" 18 #include "cc/resources/single_release_callback.h"
19 #include "cc/test/fake_output_surface.h" 19 #include "cc/test/fake_output_surface.h"
20 #include "cc/test/fake_output_surface_client.h" 20 #include "cc/test/fake_output_surface_client.h"
21 #include "cc/test/test_texture.h" 21 #include "cc/test/test_texture.h"
22 #include "cc/test/test_web_graphics_context_3d.h" 22 #include "cc/test/test_web_graphics_context_3d.h"
23 #include "gpu/GLES2/gl2extchromium.h" 23 #include "gpu/GLES2/gl2extchromium.h"
24 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
27 #include "third_party/khronos/GLES2/gl2.h" 26 #include "third_party/khronos/GLES2/gl2.h"
28 #include "third_party/khronos/GLES2/gl2ext.h" 27 #include "third_party/khronos/GLES2/gl2ext.h"
29 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
30 29
31 using testing::Mock; 30 using testing::Mock;
32 using testing::NiceMock; 31 using testing::NiceMock;
33 using testing::Return; 32 using testing::Return;
34 using testing::SetArgPointee; 33 using testing::SetArgPointee;
35 using testing::StrictMock; 34 using testing::StrictMock;
36 using testing::_; 35 using testing::_;
37 using blink::WGC3Dbyte;
38 using blink::WGC3Denum;
39 using blink::WGC3Dint;
40 using blink::WGC3Dsizei;
41 using blink::WGC3Duint;
42 using blink::WebGLId;
43 36
44 namespace cc { 37 namespace cc {
45 namespace { 38 namespace {
46 39
47 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} 40 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {}
48 41
49 static void SharedMemoryReleaseCallback(scoped_ptr<base::SharedMemory> memory, 42 static void SharedMemoryReleaseCallback(scoped_ptr<base::SharedMemory> memory,
50 unsigned sync_point, 43 unsigned sync_point,
51 bool lost_resource) {} 44 bool lost_resource) {}
52 45
(...skipping 23 matching lines...) Expand all
76 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); 69 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
77 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); 70 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea()));
78 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); 71 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory());
79 CHECK(pixels); 72 CHECK(pixels);
80 std::fill_n(pixels, size.GetArea(), value); 73 std::fill_n(pixels, size.GetArea(), value);
81 return shared_memory.Pass(); 74 return shared_memory.Pass();
82 } 75 }
83 76
84 class TextureStateTrackingContext : public TestWebGraphicsContext3D { 77 class TextureStateTrackingContext : public TestWebGraphicsContext3D {
85 public: 78 public:
86 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); 79 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture));
87 MOCK_METHOD3(texParameteri, 80 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param));
88 void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
89 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point)); 81 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point));
90 MOCK_METHOD0(insertSyncPoint, unsigned(void)); 82 MOCK_METHOD0(insertSyncPoint, unsigned(void));
91 MOCK_METHOD2(produceTextureCHROMIUM, void(WGC3Denum target, 83 MOCK_METHOD2(produceTextureCHROMIUM,
92 const WGC3Dbyte* mailbox)); 84 void(GLenum target, const GLbyte* mailbox));
93 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target, 85 MOCK_METHOD2(consumeTextureCHROMIUM,
94 const WGC3Dbyte* mailbox)); 86 void(GLenum target, const GLbyte* mailbox));
95 87
96 // Force all textures to be consecutive numbers starting at "1", 88 // Force all textures to be consecutive numbers starting at "1",
97 // so we easily can test for them. 89 // so we easily can test for them.
98 virtual blink::WebGLId NextTextureId() OVERRIDE { 90 virtual GLuint NextTextureId() OVERRIDE {
99 base::AutoLock lock(namespace_->lock); 91 base::AutoLock lock(namespace_->lock);
100 return namespace_->next_texture_id++; 92 return namespace_->next_texture_id++;
101 } 93 }
102 virtual void RetireTextureId(blink::WebGLId) OVERRIDE { 94 virtual void RetireTextureId(GLuint) OVERRIDE {}
103 }
104 }; 95 };
105 96
106 // Shared data between multiple ResourceProviderContext. This contains mailbox 97 // Shared data between multiple ResourceProviderContext. This contains mailbox
107 // contents as well as information about sync points. 98 // contents as well as information about sync points.
108 class ContextSharedData { 99 class ContextSharedData {
109 public: 100 public:
110 static scoped_ptr<ContextSharedData> Create() { 101 static scoped_ptr<ContextSharedData> Create() {
111 return make_scoped_ptr(new ContextSharedData()); 102 return make_scoped_ptr(new ContextSharedData());
112 } 103 }
113 104
114 unsigned InsertSyncPoint() { return next_sync_point_++; } 105 unsigned InsertSyncPoint() { return next_sync_point_++; }
115 106
116 void GenMailbox(WGC3Dbyte* mailbox) { 107 void GenMailbox(GLbyte* mailbox) {
117 memset(mailbox, 0, sizeof(WGC3Dbyte[64])); 108 memset(mailbox, 0, sizeof(GLbyte[64]));
118 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_)); 109 memcpy(mailbox, &next_mailbox_, sizeof(next_mailbox_));
119 ++next_mailbox_; 110 ++next_mailbox_;
120 } 111 }
121 112
122 void ProduceTexture(const WGC3Dbyte* mailbox_name, 113 void ProduceTexture(const GLbyte* mailbox_name,
123 unsigned sync_point, 114 unsigned sync_point,
124 scoped_refptr<TestTexture> texture) { 115 scoped_refptr<TestTexture> texture) {
125 unsigned mailbox = 0; 116 unsigned mailbox = 0;
126 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); 117 memcpy(&mailbox, mailbox_name, sizeof(mailbox));
127 ASSERT_TRUE(mailbox && mailbox < next_mailbox_); 118 ASSERT_TRUE(mailbox && mailbox < next_mailbox_);
128 textures_[mailbox] = texture; 119 textures_[mailbox] = texture;
129 ASSERT_LT(sync_point_for_mailbox_[mailbox], sync_point); 120 ASSERT_LT(sync_point_for_mailbox_[mailbox], sync_point);
130 sync_point_for_mailbox_[mailbox] = sync_point; 121 sync_point_for_mailbox_[mailbox] = sync_point;
131 } 122 }
132 123
133 scoped_refptr<TestTexture> ConsumeTexture(const WGC3Dbyte* mailbox_name, 124 scoped_refptr<TestTexture> ConsumeTexture(const GLbyte* mailbox_name,
134 unsigned sync_point) { 125 unsigned sync_point) {
135 unsigned mailbox = 0; 126 unsigned mailbox = 0;
136 memcpy(&mailbox, mailbox_name, sizeof(mailbox)); 127 memcpy(&mailbox, mailbox_name, sizeof(mailbox));
137 DCHECK(mailbox && mailbox < next_mailbox_); 128 DCHECK(mailbox && mailbox < next_mailbox_);
138 129
139 // If the latest sync point the context has waited on is before the sync 130 // If the latest sync point the context has waited on is before the sync
140 // point for when the mailbox was set, pretend we never saw that 131 // point for when the mailbox was set, pretend we never saw that
141 // ProduceTexture. 132 // ProduceTexture.
142 if (sync_point_for_mailbox_[mailbox] > sync_point) { 133 if (sync_point_for_mailbox_[mailbox] > sync_point) {
143 NOTREACHED(); 134 NOTREACHED();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 (*it)->mailbox, sync_point, (*it)->texture); 166 (*it)->mailbox, sync_point, (*it)->texture);
176 } 167 }
177 pending_produce_textures_.clear(); 168 pending_produce_textures_.clear();
178 return sync_point; 169 return sync_point;
179 } 170 }
180 171
181 virtual void waitSyncPoint(unsigned sync_point) OVERRIDE { 172 virtual void waitSyncPoint(unsigned sync_point) OVERRIDE {
182 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); 173 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_);
183 } 174 }
184 175
185 virtual void texStorage2DEXT(WGC3Denum target, 176 virtual void texStorage2DEXT(GLenum target,
186 WGC3Dint levels, 177 GLint levels,
187 WGC3Duint internalformat, 178 GLuint internalformat,
188 WGC3Dint width, 179 GLint width,
189 WGC3Dint height) OVERRIDE { 180 GLint height) OVERRIDE {
190 CheckTextureIsBound(target); 181 CheckTextureIsBound(target);
191 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 182 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
192 ASSERT_EQ(1, levels); 183 ASSERT_EQ(1, levels);
193 WGC3Denum format = GL_RGBA; 184 GLenum format = GL_RGBA;
194 switch (internalformat) { 185 switch (internalformat) {
195 case GL_RGBA8_OES: 186 case GL_RGBA8_OES:
196 break; 187 break;
197 case GL_BGRA8_EXT: 188 case GL_BGRA8_EXT:
198 format = GL_BGRA_EXT; 189 format = GL_BGRA_EXT;
199 break; 190 break;
200 default: 191 default:
201 NOTREACHED(); 192 NOTREACHED();
202 } 193 }
203 AllocateTexture(gfx::Size(width, height), format); 194 AllocateTexture(gfx::Size(width, height), format);
204 } 195 }
205 196
206 virtual void texImage2D(WGC3Denum target, 197 virtual void texImage2D(GLenum target,
207 WGC3Dint level, 198 GLint level,
208 WGC3Denum internalformat, 199 GLenum internalformat,
209 WGC3Dsizei width, 200 GLsizei width,
210 WGC3Dsizei height, 201 GLsizei height,
211 WGC3Dint border, 202 GLint border,
212 WGC3Denum format, 203 GLenum format,
213 WGC3Denum type, 204 GLenum type,
214 const void* pixels) OVERRIDE { 205 const void* pixels) OVERRIDE {
215 CheckTextureIsBound(target); 206 CheckTextureIsBound(target);
216 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 207 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
217 ASSERT_FALSE(level); 208 ASSERT_FALSE(level);
218 ASSERT_EQ(internalformat, format); 209 ASSERT_EQ(internalformat, format);
219 ASSERT_FALSE(border); 210 ASSERT_FALSE(border);
220 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); 211 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type);
221 AllocateTexture(gfx::Size(width, height), format); 212 AllocateTexture(gfx::Size(width, height), format);
222 if (pixels) 213 if (pixels)
223 SetPixels(0, 0, width, height, pixels); 214 SetPixels(0, 0, width, height, pixels);
224 } 215 }
225 216
226 virtual void texSubImage2D(WGC3Denum target, 217 virtual void texSubImage2D(GLenum target,
227 WGC3Dint level, 218 GLint level,
228 WGC3Dint xoffset, 219 GLint xoffset,
229 WGC3Dint yoffset, 220 GLint yoffset,
230 WGC3Dsizei width, 221 GLsizei width,
231 WGC3Dsizei height, 222 GLsizei height,
232 WGC3Denum format, 223 GLenum format,
233 WGC3Denum type, 224 GLenum type,
234 const void* pixels) OVERRIDE { 225 const void* pixels) OVERRIDE {
235 CheckTextureIsBound(target); 226 CheckTextureIsBound(target);
236 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); 227 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
237 ASSERT_FALSE(level); 228 ASSERT_FALSE(level);
238 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); 229 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type);
239 { 230 {
240 base::AutoLock lock_for_texture_access(namespace_->lock); 231 base::AutoLock lock_for_texture_access(namespace_->lock);
241 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); 232 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format);
242 } 233 }
243 ASSERT_TRUE(pixels); 234 ASSERT_TRUE(pixels);
244 SetPixels(xoffset, yoffset, width, height, pixels); 235 SetPixels(xoffset, yoffset, width, height, pixels);
245 } 236 }
246 237
247 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) OVERRIDE { 238 virtual void genMailboxCHROMIUM(GLbyte* mailbox) OVERRIDE {
248 return shared_data_->GenMailbox(mailbox); 239 return shared_data_->GenMailbox(mailbox);
249 } 240 }
250 241
251 virtual void produceTextureCHROMIUM(WGC3Denum target, 242 virtual void produceTextureCHROMIUM(GLenum target,
252 const WGC3Dbyte* mailbox) OVERRIDE { 243 const GLbyte* mailbox) OVERRIDE {
253 CheckTextureIsBound(target); 244 CheckTextureIsBound(target);
254 245
255 // Delay moving the texture into the mailbox until the next 246 // Delay moving the texture into the mailbox until the next
256 // InsertSyncPoint, so that it is not visible to other contexts that 247 // InsertSyncPoint, so that it is not visible to other contexts that
257 // haven't waited on that sync point. 248 // haven't waited on that sync point.
258 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); 249 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture);
259 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); 250 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox));
260 base::AutoLock lock_for_texture_access(namespace_->lock); 251 base::AutoLock lock_for_texture_access(namespace_->lock);
261 pending->texture = BoundTexture(target); 252 pending->texture = BoundTexture(target);
262 pending_produce_textures_.push_back(pending.Pass()); 253 pending_produce_textures_.push_back(pending.Pass());
263 } 254 }
264 255
265 virtual void consumeTextureCHROMIUM(WGC3Denum target, 256 virtual void consumeTextureCHROMIUM(GLenum target,
266 const WGC3Dbyte* mailbox) OVERRIDE { 257 const GLbyte* mailbox) OVERRIDE {
267 CheckTextureIsBound(target); 258 CheckTextureIsBound(target);
268 base::AutoLock lock_for_texture_access(namespace_->lock); 259 base::AutoLock lock_for_texture_access(namespace_->lock);
269 scoped_refptr<TestTexture> texture = 260 scoped_refptr<TestTexture> texture =
270 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); 261 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_);
271 namespace_->textures.Replace(BoundTextureId(target), texture); 262 namespace_->textures.Replace(BoundTextureId(target), texture);
272 } 263 }
273 264
274 void GetPixels(gfx::Size size, ResourceFormat format, uint8_t* pixels) { 265 void GetPixels(gfx::Size size, ResourceFormat format, uint8_t* pixels) {
275 CheckTextureIsBound(GL_TEXTURE_2D); 266 CheckTextureIsBound(GL_TEXTURE_2D);
276 base::AutoLock lock_for_texture_access(namespace_->lock); 267 base::AutoLock lock_for_texture_access(namespace_->lock);
277 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D); 268 scoped_refptr<TestTexture> texture = BoundTexture(GL_TEXTURE_2D);
278 ASSERT_EQ(texture->size, size); 269 ASSERT_EQ(texture->size, size);
279 ASSERT_EQ(texture->format, format); 270 ASSERT_EQ(texture->format, format);
280 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format)); 271 memcpy(pixels, texture->data.get(), TextureSizeBytes(size, format));
281 } 272 }
282 273
283 protected: 274 protected:
284 explicit ResourceProviderContext(ContextSharedData* shared_data) 275 explicit ResourceProviderContext(ContextSharedData* shared_data)
285 : shared_data_(shared_data), 276 : shared_data_(shared_data),
286 last_waited_sync_point_(0) {} 277 last_waited_sync_point_(0) {}
287 278
288 private: 279 private:
289 void AllocateTexture(gfx::Size size, WGC3Denum format) { 280 void AllocateTexture(gfx::Size size, GLenum format) {
290 CheckTextureIsBound(GL_TEXTURE_2D); 281 CheckTextureIsBound(GL_TEXTURE_2D);
291 ResourceFormat texture_format = RGBA_8888; 282 ResourceFormat texture_format = RGBA_8888;
292 switch (format) { 283 switch (format) {
293 case GL_RGBA: 284 case GL_RGBA:
294 texture_format = RGBA_8888; 285 texture_format = RGBA_8888;
295 break; 286 break;
296 case GL_BGRA_EXT: 287 case GL_BGRA_EXT:
297 texture_format = BGRA_8888; 288 texture_format = BGRA_8888;
298 break; 289 break;
299 } 290 }
(...skipping 20 matching lines...) Expand all
320 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format); 311 TextureSizeBytes(gfx::Size(xoffset, 1), texture->format);
321 const uint8_t* src = static_cast<const uint8_t*>(pixels); 312 const uint8_t* src = static_cast<const uint8_t*>(pixels);
322 for (int i = 0; i < height; ++i) { 313 for (int i = 0; i < height; ++i) {
323 memcpy(dest, src, in_pitch); 314 memcpy(dest, src, in_pitch);
324 dest += out_pitch; 315 dest += out_pitch;
325 src += in_pitch; 316 src += in_pitch;
326 } 317 }
327 } 318 }
328 319
329 struct PendingProduceTexture { 320 struct PendingProduceTexture {
330 WGC3Dbyte mailbox[64]; 321 GLbyte mailbox[64];
331 scoped_refptr<TestTexture> texture; 322 scoped_refptr<TestTexture> texture;
332 }; 323 };
333 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList; 324 typedef ScopedPtrDeque<PendingProduceTexture> PendingProduceTextureList;
334 ContextSharedData* shared_data_; 325 ContextSharedData* shared_data_;
335 unsigned last_waited_sync_point_; 326 unsigned last_waited_sync_point_;
336 PendingProduceTextureList pending_produce_textures_; 327 PendingProduceTextureList pending_produce_textures_;
337 }; 328 };
338 329
339 void FreeSharedBitmap(SharedBitmap* shared_bitmap) { 330 void FreeSharedBitmap(SharedBitmap* shared_bitmap) {
340 delete shared_bitmap->memory(); 331 delete shared_bitmap->memory();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 const ReturnedResourceArray& returned) { 459 const ReturnedResourceArray& returned) {
469 array->insert(array->end(), returned.begin(), returned.end()); 460 array->insert(array->end(), returned.begin(), returned.end());
470 } 461 }
471 462
472 static ReturnCallback GetReturnCallback(ReturnedResourceArray* array) { 463 static ReturnCallback GetReturnCallback(ReturnedResourceArray* array) {
473 return base::Bind(&ResourceProviderTest::CollectResources, array); 464 return base::Bind(&ResourceProviderTest::CollectResources, array);
474 } 465 }
475 466
476 static void SetResourceFilter(ResourceProvider* resource_provider, 467 static void SetResourceFilter(ResourceProvider* resource_provider,
477 ResourceProvider::ResourceId id, 468 ResourceProvider::ResourceId id,
478 WGC3Denum filter) { 469 GLenum filter) {
479 ResourceProvider::ScopedSamplerGL sampler( 470 ResourceProvider::ScopedSamplerGL sampler(
480 resource_provider, id, GL_TEXTURE_2D, filter); 471 resource_provider, id, GL_TEXTURE_2D, filter);
481 } 472 }
482 473
483 ResourceProviderContext* context() { return context3d_; } 474 ResourceProviderContext* context() { return context3d_; }
484 475
485 ResourceProvider::ResourceId CreateChildMailbox(unsigned* release_sync_point, 476 ResourceProvider::ResourceId CreateChildMailbox(unsigned* release_sync_point,
486 bool* lost_resource, 477 bool* lost_resource,
487 bool* release_called, 478 bool* release_called,
488 unsigned* sync_point) { 479 unsigned* sync_point) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 640 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
650 uint8_t data1[4] = { 1, 2, 3, 4 }; 641 uint8_t data1[4] = { 1, 2, 3, 4 };
651 gfx::Rect rect(size); 642 gfx::Rect rect(size);
652 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 643 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
653 644
654 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 645 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
655 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 646 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
656 uint8_t data2[4] = { 5, 5, 5, 5 }; 647 uint8_t data2[4] = { 5, 5, 5, 5 };
657 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 648 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
658 649
659 WebGLId external_texture_id = child_context_->createExternalTexture(); 650 GLuint external_texture_id = child_context_->createExternalTexture();
660 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); 651 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id);
661 652
662 gpu::Mailbox external_mailbox; 653 gpu::Mailbox external_mailbox;
663 child_context_->genMailboxCHROMIUM(external_mailbox.name); 654 child_context_->genMailboxCHROMIUM(external_mailbox.name);
664 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, 655 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES,
665 external_mailbox.name); 656 external_mailbox.name);
666 const unsigned external_sync_point = child_context_->insertSyncPoint(); 657 const unsigned external_sync_point = child_context_->insertSyncPoint();
667 ResourceProvider::ResourceId id3 = 658 ResourceProvider::ResourceId id3 =
668 child_resource_provider_->CreateResourceFromTextureMailbox( 659 child_resource_provider_->CreateResourceFromTextureMailbox(
669 TextureMailbox( 660 TextureMailbox(
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after
2370 EXPECT_CALL(*context, insertSyncPoint()); 2361 EXPECT_CALL(*context, insertSyncPoint());
2371 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); 2362 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0);
2372 2363
2373 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2364 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0);
2374 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); 2365 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0);
2375 } 2366 }
2376 } 2367 }
2377 2368
2378 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { 2369 class AllocationTrackingContext3D : public TestWebGraphicsContext3D {
2379 public: 2370 public:
2380 MOCK_METHOD0(NextTextureId, WebGLId()); 2371 MOCK_METHOD0(NextTextureId, GLuint());
2381 MOCK_METHOD1(RetireTextureId, void(WebGLId id)); 2372 MOCK_METHOD1(RetireTextureId, void(GLuint id));
2382 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); 2373 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture));
2383 MOCK_METHOD5(texStorage2DEXT, 2374 MOCK_METHOD5(texStorage2DEXT,
2384 void(WGC3Denum target, 2375 void(GLenum target,
2385 WGC3Dint levels, 2376 GLint levels,
2386 WGC3Duint internalformat, 2377 GLuint internalformat,
2387 WGC3Dint width, 2378 GLint width,
2388 WGC3Dint height)); 2379 GLint height));
2389 MOCK_METHOD9(texImage2D, 2380 MOCK_METHOD9(texImage2D,
2390 void(WGC3Denum target, 2381 void(GLenum target,
2391 WGC3Dint level, 2382 GLint level,
2392 WGC3Denum internalformat, 2383 GLenum internalformat,
2393 WGC3Dsizei width, 2384 GLsizei width,
2394 WGC3Dsizei height, 2385 GLsizei height,
2395 WGC3Dint border, 2386 GLint border,
2396 WGC3Denum format, 2387 GLenum format,
2397 WGC3Denum type, 2388 GLenum type,
2398 const void* pixels)); 2389 const void* pixels));
2399 MOCK_METHOD9(texSubImage2D, 2390 MOCK_METHOD9(texSubImage2D,
2400 void(WGC3Denum target, 2391 void(GLenum target,
2401 WGC3Dint level, 2392 GLint level,
2402 WGC3Dint xoffset, 2393 GLint xoffset,
2403 WGC3Dint yoffset, 2394 GLint yoffset,
2404 WGC3Dsizei width, 2395 GLsizei width,
2405 WGC3Dsizei height, 2396 GLsizei height,
2406 WGC3Denum format, 2397 GLenum format,
2407 WGC3Denum type, 2398 GLenum type,
2408 const void* pixels)); 2399 const void* pixels));
2409 MOCK_METHOD9(asyncTexImage2DCHROMIUM, 2400 MOCK_METHOD9(asyncTexImage2DCHROMIUM,
2410 void(WGC3Denum target, 2401 void(GLenum target,
2411 WGC3Dint level, 2402 GLint level,
2412 WGC3Denum internalformat, 2403 GLenum internalformat,
2413 WGC3Dsizei width, 2404 GLsizei width,
2414 WGC3Dsizei height, 2405 GLsizei height,
2415 WGC3Dint border, 2406 GLint border,
2416 WGC3Denum format, 2407 GLenum format,
2417 WGC3Denum type, 2408 GLenum type,
2418 const void* pixels)); 2409 const void* pixels));
2419 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, 2410 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM,
2420 void(WGC3Denum target, 2411 void(GLenum target,
2421 WGC3Dint level, 2412 GLint level,
2422 WGC3Dint xoffset, 2413 GLint xoffset,
2423 WGC3Dint yoffset, 2414 GLint yoffset,
2424 WGC3Dsizei width, 2415 GLsizei width,
2425 WGC3Dsizei height, 2416 GLsizei height,
2426 WGC3Denum format, 2417 GLenum format,
2427 WGC3Denum type, 2418 GLenum type,
2428 const void* pixels)); 2419 const void* pixels));
2429 MOCK_METHOD8(compressedTexImage2D, 2420 MOCK_METHOD8(compressedTexImage2D,
2430 void(WGC3Denum target, 2421 void(GLenum target,
2431 WGC3Dint level, 2422 GLint level,
2432 WGC3Denum internalformat, 2423 GLenum internalformat,
2433 WGC3Dsizei width, 2424 GLsizei width,
2434 WGC3Dsizei height, 2425 GLsizei height,
2435 WGC3Dint border, 2426 GLint border,
2436 WGC3Dsizei image_size, 2427 GLsizei image_size,
2437 const void* data)); 2428 const void* data));
2438 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(WGC3Denum)); 2429 MOCK_METHOD1(waitAsyncTexImage2DCHROMIUM, void(GLenum));
2439 MOCK_METHOD3(createImageCHROMIUM, WGC3Duint(WGC3Dsizei, WGC3Dsizei, 2430 MOCK_METHOD3(createImageCHROMIUM, GLuint(GLsizei, GLsizei, GLenum));
2440 WGC3Denum)); 2431 MOCK_METHOD1(destroyImageCHROMIUM, void(GLuint));
2441 MOCK_METHOD1(destroyImageCHROMIUM, void(WGC3Duint)); 2432 MOCK_METHOD2(mapImageCHROMIUM, void*(GLuint, GLenum));
2442 MOCK_METHOD2(mapImageCHROMIUM, void*(WGC3Duint, WGC3Denum)); 2433 MOCK_METHOD3(getImageParameterivCHROMIUM, void(GLuint, GLenum, GLint*));
2443 MOCK_METHOD3(getImageParameterivCHROMIUM, void(WGC3Duint, WGC3Denum, 2434 MOCK_METHOD1(unmapImageCHROMIUM, void(GLuint));
2444 GLint*)); 2435 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(GLenum, GLint));
2445 MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint)); 2436 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(GLenum, GLint));
2446 MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
2447 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
2448 2437
2449 // We're mocking bindTexture, so we override 2438 // We're mocking bindTexture, so we override
2450 // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the 2439 // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the
2451 // currently bound texture. 2440 // currently bound texture.
2452 virtual void texParameteri(blink::WGC3Denum target, 2441 virtual void texParameteri(GLenum target, GLenum pname, GLint param) {}
2453 blink::WGC3Denum pname,
2454 blink::WGC3Dint param) {}
2455 }; 2442 };
2456 2443
2457 TEST_P(ResourceProviderTest, TextureAllocation) { 2444 TEST_P(ResourceProviderTest, TextureAllocation) {
2458 // Only for GL textures. 2445 // Only for GL textures.
2459 if (GetParam() != ResourceProvider::GLTexture) 2446 if (GetParam() != ResourceProvider::GLTexture)
2460 return; 2447 return;
2461 scoped_ptr<AllocationTrackingContext3D> context_owned( 2448 scoped_ptr<AllocationTrackingContext3D> context_owned(
2462 new StrictMock<AllocationTrackingContext3D>); 2449 new StrictMock<AllocationTrackingContext3D>);
2463 AllocationTrackingContext3D* context = context_owned.get(); 2450 AllocationTrackingContext3D* context = context_owned.get();
2464 2451
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
3016 resource_provider->DeleteResource(id); 3003 resource_provider->DeleteResource(id);
3017 } 3004 }
3018 3005
3019 INSTANTIATE_TEST_CASE_P( 3006 INSTANTIATE_TEST_CASE_P(
3020 ResourceProviderTests, 3007 ResourceProviderTests,
3021 ResourceProviderTest, 3008 ResourceProviderTest,
3022 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); 3009 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap));
3023 3010
3024 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { 3011 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D {
3025 public: 3012 public:
3026 virtual blink::WebGLId NextTextureId() OVERRIDE { 3013 virtual GLuint NextTextureId() OVERRIDE {
3027 base::AutoLock lock(namespace_->lock); 3014 base::AutoLock lock(namespace_->lock);
3028 return namespace_->next_texture_id++; 3015 return namespace_->next_texture_id++;
3029 } 3016 }
3030 virtual void RetireTextureId(blink::WebGLId) OVERRIDE { 3017 virtual void RetireTextureId(GLuint) OVERRIDE {}
3031 } 3018 GLuint PeekTextureId() {
3032 blink::WebGLId PeekTextureId() {
3033 base::AutoLock lock(namespace_->lock); 3019 base::AutoLock lock(namespace_->lock);
3034 return namespace_->next_texture_id; 3020 return namespace_->next_texture_id;
3035 } 3021 }
3036 }; 3022 };
3037 3023
3038 TEST(ResourceProviderTest, TextureAllocationChunkSize) { 3024 TEST(ResourceProviderTest, TextureAllocationChunkSize) {
3039 scoped_ptr<TextureIdAllocationTrackingContext> context_owned( 3025 scoped_ptr<TextureIdAllocationTrackingContext> context_owned(
3040 new TextureIdAllocationTrackingContext); 3026 new TextureIdAllocationTrackingContext);
3041 TextureIdAllocationTrackingContext* context = context_owned.get(); 3027 TextureIdAllocationTrackingContext* context = context_owned.get();
3042 3028
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3080 resource_provider->AllocateForTesting(id); 3066 resource_provider->AllocateForTesting(id);
3081 Mock::VerifyAndClearExpectations(context); 3067 Mock::VerifyAndClearExpectations(context);
3082 3068
3083 DCHECK_EQ(10u, context->PeekTextureId()); 3069 DCHECK_EQ(10u, context->PeekTextureId());
3084 resource_provider->DeleteResource(id); 3070 resource_provider->DeleteResource(id);
3085 } 3071 }
3086 } 3072 }
3087 3073
3088 } // namespace 3074 } // namespace
3089 } // namespace cc 3075 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/resource_update_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698