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

Side by Side Diff: cc/resource_provider.cc

Issue 11048044: cc: Switch to Chromium DCHECKs and LOGs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 years, 2 months 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
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 "config.h" 5 #include "config.h"
6 6
7 #include "CCResourceProvider.h" 7 #include "CCResourceProvider.h"
8 #ifdef LOG 8 #ifdef LOG
9 #undef LOG 9 #undef LOG
10 #endif 10 #endif
(...skipping 21 matching lines...) Expand all
32 static GC3Denum textureToStorageFormat(GC3Denum textureFormat) 32 static GC3Denum textureToStorageFormat(GC3Denum textureFormat)
33 { 33 {
34 GC3Denum storageFormat = Extensions3D::RGBA8_OES; 34 GC3Denum storageFormat = Extensions3D::RGBA8_OES;
35 switch (textureFormat) { 35 switch (textureFormat) {
36 case GraphicsContext3D::RGBA: 36 case GraphicsContext3D::RGBA:
37 break; 37 break;
38 case Extensions3D::BGRA_EXT: 38 case Extensions3D::BGRA_EXT:
39 storageFormat = Extensions3DChromium::BGRA8_EXT; 39 storageFormat = Extensions3DChromium::BGRA8_EXT;
40 break; 40 break;
41 default: 41 default:
42 ASSERT_NOT_REACHED(); 42 NOTREACHED();
43 break; 43 break;
44 } 44 }
45 45
46 return storageFormat; 46 return storageFormat;
47 } 47 }
48 48
49 static bool isTextureFormatSupportedForStorage(GC3Denum format) 49 static bool isTextureFormatSupportedForStorage(GC3Denum format)
50 { 50 {
51 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX T); 51 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX T);
52 } 52 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 { 124 {
125 WebGraphicsContext3D* context3d = m_context->context3D(); 125 WebGraphicsContext3D* context3d = m_context->context3D();
126 if (!context3d || !context3d->makeContextCurrent()) 126 if (!context3d || !context3d->makeContextCurrent())
127 return; 127 return;
128 m_textureUploader.clear(); 128 m_textureUploader.clear();
129 m_textureCopier.clear(); 129 m_textureCopier.clear();
130 } 130 }
131 131
132 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() 132 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D()
133 { 133 {
134 ASSERT(CCProxy::isImplThread()); 134 CC_DCHECK(CCProxy::isImplThread());
135 return m_context->context3D(); 135 return m_context->context3D();
136 } 136 }
137 137
138 bool CCResourceProvider::inUseByConsumer(ResourceId id) 138 bool CCResourceProvider::inUseByConsumer(ResourceId id)
139 { 139 {
140 ASSERT(CCProxy::isImplThread()); 140 CC_DCHECK(CCProxy::isImplThread());
141 ResourceMap::iterator it = m_resources.find(id); 141 ResourceMap::iterator it = m_resources.find(id);
142 CHECK(it != m_resources.end()); 142 CHECK(it != m_resources.end());
143 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 143 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
144 Resource* resource = &it->value; 144 Resource* resource = &it->value;
145 #else 145 #else
146 Resource* resource = &it->second; 146 Resource* resource = &it->second;
147 #endif 147 #endif
148 return !!resource->lockForReadCount || resource->exported; 148 return !!resource->lockForReadCount || resource->exported;
149 } 149 }
150 150
151 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons t IntSize& size, GC3Denum format, TextureUsageHint hint) 151 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons t IntSize& size, GC3Denum format, TextureUsageHint hint)
152 { 152 {
153 switch (m_defaultResourceType) { 153 switch (m_defaultResourceType) {
154 case GLTexture: 154 case GLTexture:
155 return createGLTexture(pool, size, format, hint); 155 return createGLTexture(pool, size, format, hint);
156 case Bitmap: 156 case Bitmap:
157 ASSERT(format == GraphicsContext3D::RGBA); 157 CC_DCHECK(format == GraphicsContext3D::RGBA);
158 return createBitmap(pool, size); 158 return createBitmap(pool, size);
159 } 159 }
160 160
161 CRASH(); 161 CRASH();
162 return 0; 162 return 0;
163 } 163 }
164 164
165 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con st IntSize& size, GC3Denum format, TextureUsageHint hint) 165 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con st IntSize& size, GC3Denum format, TextureUsageHint hint)
166 { 166 {
167 ASSERT(CCProxy::isImplThread()); 167 CC_DCHECK(CCProxy::isImplThread());
168 unsigned textureId = 0; 168 unsigned textureId = 0;
169 WebGraphicsContext3D* context3d = m_context->context3D(); 169 WebGraphicsContext3D* context3d = m_context->context3D();
170 ASSERT(context3d); 170 CC_DCHECK(context3d);
171 GLC(context3d, textureId = context3d->createTexture()); 171 GLC(context3d, textureId = context3d->createTexture());
172 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture Id)); 172 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture Id));
173 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); 173 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
174 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); 174 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); 175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
176 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); 176 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
177 177
178 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 178 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
179 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE R_ATTACHMENT_ANGLE)); 179 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE R_ATTACHMENT_ANGLE));
180 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { 180 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
181 GC3Denum storageFormat = textureToStorageFormat(format); 181 GC3Denum storageFormat = textureToStorageFormat(format);
182 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D, 1, storageFormat, size.width(), size.height())); 182 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D, 1, storageFormat, size.width(), size.height()));
183 } else 183 } else
184 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE, 0)); 184 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE, 0));
185 ResourceId id = m_nextId++; 185 ResourceId id = m_nextId++;
186 Resource resource(textureId, pool, size, format); 186 Resource resource(textureId, pool, size, format);
187 m_resources.add(id, resource); 187 m_resources.add(id, resource);
188 return id; 188 return id;
189 } 189 }
190 190
191 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const IntSize& size) 191 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const IntSize& size)
192 { 192 {
193 ASSERT(CCProxy::isImplThread()); 193 CC_DCHECK(CCProxy::isImplThread());
194 194
195 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 195 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
196 196
197 ResourceId id = m_nextId++; 197 ResourceId id = m_nextId++;
198 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); 198 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA);
199 m_resources.add(id, resource); 199 m_resources.add(id, resource);
200 return id; 200 return id;
201 } 201 }
202 202
203 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex ture(unsigned textureId) 203 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex ture(unsigned textureId)
204 { 204 {
205 ASSERT(CCProxy::isImplThread()); 205 CC_DCHECK(CCProxy::isImplThread());
206 ASSERT(m_context->context3D()); 206 CC_DCHECK(m_context->context3D());
207 ResourceId id = m_nextId++; 207 ResourceId id = m_nextId++;
208 Resource resource(textureId, 0, IntSize(), 0); 208 Resource resource(textureId, 0, IntSize(), 0);
209 resource.external = true; 209 resource.external = true;
210 m_resources.add(id, resource); 210 m_resources.add(id, resource);
211 return id; 211 return id;
212 } 212 }
213 213
214 void CCResourceProvider::deleteResource(ResourceId id) 214 void CCResourceProvider::deleteResource(ResourceId id)
215 { 215 {
216 ASSERT(CCProxy::isImplThread()); 216 CC_DCHECK(CCProxy::isImplThread());
217 ResourceMap::iterator it = m_resources.find(id); 217 ResourceMap::iterator it = m_resources.find(id);
218 CHECK(it != m_resources.end()); 218 CHECK(it != m_resources.end());
219 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 219 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
220 Resource* resource = &it->value; 220 Resource* resource = &it->value;
221 #else 221 #else
222 Resource* resource = &it->second; 222 Resource* resource = &it->second;
223 #endif 223 #endif
224 ASSERT(!resource->lockedForWrite); 224 CC_DCHECK(!resource->lockedForWrite);
225 ASSERT(!resource->lockForReadCount); 225 CC_DCHECK(!resource->lockForReadCount);
226 ASSERT(!resource->markedForDeletion); 226 CC_DCHECK(!resource->markedForDeletion);
227 227
228 if (resource->exported) { 228 if (resource->exported) {
229 resource->markedForDeletion = true; 229 resource->markedForDeletion = true;
230 return; 230 return;
231 } else 231 } else
232 deleteResourceInternal(it); 232 deleteResourceInternal(it);
233 } 233 }
234 234
235 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it) 235 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it)
236 { 236 {
237 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 237 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
238 Resource* resource = &it->value; 238 Resource* resource = &it->value;
239 #else 239 #else
240 Resource* resource = &it->second; 240 Resource* resource = &it->second;
241 #endif 241 #endif
242 if (resource->glId && !resource->external) { 242 if (resource->glId && !resource->external) {
243 WebGraphicsContext3D* context3d = m_context->context3D(); 243 WebGraphicsContext3D* context3d = m_context->context3D();
244 ASSERT(context3d); 244 CC_DCHECK(context3d);
245 GLC(context3d, context3d->deleteTexture(resource->glId)); 245 GLC(context3d, context3d->deleteTexture(resource->glId));
246 } 246 }
247 if (resource->pixels) 247 if (resource->pixels)
248 delete resource->pixels; 248 delete resource->pixels;
249 249
250 m_resources.remove(it); 250 m_resources.remove(it);
251 } 251 }
252 252
253 void CCResourceProvider::deleteOwnedResources(int pool) 253 void CCResourceProvider::deleteOwnedResources(int pool)
254 { 254 {
255 ASSERT(CCProxy::isImplThread()); 255 CC_DCHECK(CCProxy::isImplThread());
256 ResourceIdArray toDelete; 256 ResourceIdArray toDelete;
257 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end() ; ++it) { 257 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end() ; ++it) {
258 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 258 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
259 if (it->value.pool == pool && !it->value.external && !it->value.markedFo rDeletion) 259 if (it->value.pool == pool && !it->value.external && !it->value.markedFo rDeletion)
260 toDelete.append(it->key); 260 toDelete.append(it->key);
261 #else 261 #else
262 if (it->second.pool == pool && !it->second.external && !it->value.marked ForDeletion) 262 if (it->second.pool == pool && !it->second.external && !it->value.marked ForDeletion)
263 toDelete.append(it->first); 263 toDelete.append(it->first);
264 #endif 264 #endif
265 } 265 }
266 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end(); ++it) 266 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end(); ++it)
267 deleteResource(*it); 267 deleteResource(*it);
268 } 268 }
269 269
270 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) 270 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id)
271 { 271 {
272 ResourceMap::iterator it = m_resources.find(id); 272 ResourceMap::iterator it = m_resources.find(id);
273 CHECK(it != m_resources.end()); 273 CHECK(it != m_resources.end());
274 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 274 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
275 Resource* resource = &it->value; 275 Resource* resource = &it->value;
276 #else 276 #else
277 Resource* resource = &it->second; 277 Resource* resource = &it->second;
278 #endif 278 #endif
279 return resource->type; 279 return resource->type;
280 } 280 }
281 281
282 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) 282 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset)
283 { 283 {
284 ASSERT(CCProxy::isImplThread()); 284 CC_DCHECK(CCProxy::isImplThread());
285 ResourceMap::iterator it = m_resources.find(id); 285 ResourceMap::iterator it = m_resources.find(id);
286 CHECK(it != m_resources.end()); 286 CHECK(it != m_resources.end());
287 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 287 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
288 Resource* resource = &it->value; 288 Resource* resource = &it->value;
289 #else 289 #else
290 Resource* resource = &it->second; 290 Resource* resource = &it->second;
291 #endif 291 #endif
292 ASSERT(!resource->lockedForWrite); 292 CC_DCHECK(!resource->lockedForWrite);
293 ASSERT(!resource->lockForReadCount); 293 CC_DCHECK(!resource->lockForReadCount);
294 ASSERT(!resource->external); 294 CC_DCHECK(!resource->external);
295 ASSERT(!resource->exported); 295 CC_DCHECK(!resource->exported);
296 296
297 if (resource->glId) { 297 if (resource->glId) {
298 WebGraphicsContext3D* context3d = m_context->context3D(); 298 WebGraphicsContext3D* context3d = m_context->context3D();
299 ASSERT(context3d); 299 CC_DCHECK(context3d);
300 ASSERT(m_texSubImage.get()); 300 CC_DCHECK(m_texSubImage.get());
301 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); 301 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId);
302 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, resource ->format, context3d); 302 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, resource ->format, context3d);
303 } 303 }
304 304
305 if (resource->pixels) { 305 if (resource->pixels) {
306 SkBitmap srcFull; 306 SkBitmap srcFull;
307 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height()); 307 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height());
308 srcFull.setPixels(const_cast<uint8_t*>(image)); 308 srcFull.setPixels(const_cast<uint8_t*>(image));
309 SkBitmap srcSubset; 309 SkBitmap srcSubset;
310 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); 310 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height());
311 skSourceRect.offset(-imageRect.x(), -imageRect.y()); 311 skSourceRect.offset(-imageRect.x(), -imageRect.y());
312 srcFull.extractSubset(&srcSubset, skSourceRect); 312 srcFull.extractSubset(&srcSubset, skSourceRect);
313 313
314 ScopedWriteLockSoftware lock(this, id); 314 ScopedWriteLockSoftware lock(this, id);
315 SkCanvas* dest = lock.skCanvas(); 315 SkCanvas* dest = lock.skCanvas();
316 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); 316 dest->writePixels(srcSubset, destOffset.width(), destOffset.height());
317 } 317 }
318 } 318 }
319 319
320 void CCResourceProvider::flush() 320 void CCResourceProvider::flush()
321 { 321 {
322 ASSERT(CCProxy::isImplThread()); 322 CC_DCHECK(CCProxy::isImplThread());
323 WebGraphicsContext3D* context3d = m_context->context3D(); 323 WebGraphicsContext3D* context3d = m_context->context3D();
324 if (context3d) 324 if (context3d)
325 context3d->flush(); 325 context3d->flush();
326 } 326 }
327 327
328 bool CCResourceProvider::shallowFlushIfSupported() 328 bool CCResourceProvider::shallowFlushIfSupported()
329 { 329 {
330 ASSERT(CCProxy::isImplThread()); 330 CC_DCHECK(CCProxy::isImplThread());
331 WebGraphicsContext3D* context3d = m_context->context3D(); 331 WebGraphicsContext3D* context3d = m_context->context3D();
332 if (!context3d || !m_useShallowFlush) 332 if (!context3d || !m_useShallowFlush)
333 return false; 333 return false;
334 334
335 context3d->shallowFlushCHROMIUM(); 335 context3d->shallowFlushCHROMIUM();
336 return true; 336 return true;
337 } 337 }
338 338
339 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i d) 339 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i d)
340 { 340 {
341 ASSERT(CCProxy::isImplThread()); 341 CC_DCHECK(CCProxy::isImplThread());
342 ResourceMap::iterator it = m_resources.find(id); 342 ResourceMap::iterator it = m_resources.find(id);
343 CHECK(it != m_resources.end()); 343 CHECK(it != m_resources.end());
344 344
345 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 345 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
346 Resource* resource = &it->value; 346 Resource* resource = &it->value;
347 #else 347 #else
348 Resource* resource = &it->second; 348 Resource* resource = &it->second;
349 #endif 349 #endif
350 ASSERT(!resource->lockedForWrite); 350 CC_DCHECK(!resource->lockedForWrite);
351 ASSERT(!resource->exported); 351 CC_DCHECK(!resource->exported);
352 resource->lockForReadCount++; 352 resource->lockForReadCount++;
353 return resource; 353 return resource;
354 } 354 }
355 355
356 void CCResourceProvider::unlockForRead(ResourceId id) 356 void CCResourceProvider::unlockForRead(ResourceId id)
357 { 357 {
358 ASSERT(CCProxy::isImplThread()); 358 CC_DCHECK(CCProxy::isImplThread());
359 ResourceMap::iterator it = m_resources.find(id); 359 ResourceMap::iterator it = m_resources.find(id);
360 CHECK(it != m_resources.end()); 360 CHECK(it != m_resources.end());
361 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 361 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
362 Resource* resource = &it->value; 362 Resource* resource = &it->value;
363 #else 363 #else
364 Resource* resource = &it->second; 364 Resource* resource = &it->second;
365 #endif 365 #endif
366 ASSERT(resource->lockForReadCount > 0); 366 CC_DCHECK(resource->lockForReadCount > 0);
367 ASSERT(!resource->exported); 367 CC_DCHECK(!resource->exported);
368 resource->lockForReadCount--; 368 resource->lockForReadCount--;
369 } 369 }
370 370
371 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId id) 371 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId id)
372 { 372 {
373 ASSERT(CCProxy::isImplThread()); 373 CC_DCHECK(CCProxy::isImplThread());
374 ResourceMap::iterator it = m_resources.find(id); 374 ResourceMap::iterator it = m_resources.find(id);
375 CHECK(it != m_resources.end()); 375 CHECK(it != m_resources.end());
376 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 376 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
377 Resource* resource = &it->value; 377 Resource* resource = &it->value;
378 #else 378 #else
379 Resource* resource = &it->second; 379 Resource* resource = &it->second;
380 #endif 380 #endif
381 ASSERT(!resource->lockedForWrite); 381 CC_DCHECK(!resource->lockedForWrite);
382 ASSERT(!resource->lockForReadCount); 382 CC_DCHECK(!resource->lockForReadCount);
383 ASSERT(!resource->exported); 383 CC_DCHECK(!resource->exported);
384 ASSERT(!resource->external); 384 CC_DCHECK(!resource->external);
385 resource->lockedForWrite = true; 385 resource->lockedForWrite = true;
386 return resource; 386 return resource;
387 } 387 }
388 388
389 void CCResourceProvider::unlockForWrite(ResourceId id) 389 void CCResourceProvider::unlockForWrite(ResourceId id)
390 { 390 {
391 ASSERT(CCProxy::isImplThread()); 391 CC_DCHECK(CCProxy::isImplThread());
392 ResourceMap::iterator it = m_resources.find(id); 392 ResourceMap::iterator it = m_resources.find(id);
393 CHECK(it != m_resources.end()); 393 CHECK(it != m_resources.end());
394 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 394 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
395 Resource* resource = &it->value; 395 Resource* resource = &it->value;
396 #else 396 #else
397 Resource* resource = &it->second; 397 Resource* resource = &it->second;
398 #endif 398 #endif
399 ASSERT(resource->lockedForWrite); 399 CC_DCHECK(resource->lockedForWrite);
400 ASSERT(!resource->exported); 400 CC_DCHECK(!resource->exported);
401 ASSERT(!resource->external); 401 CC_DCHECK(!resource->external);
402 resource->lockedForWrite = false; 402 resource->lockedForWrite = false;
403 } 403 }
404 404
405 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou rceProvider, CCResourceProvider::ResourceId resourceId) 405 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou rceProvider, CCResourceProvider::ResourceId resourceId)
406 : m_resourceProvider(resourceProvider) 406 : m_resourceProvider(resourceProvider)
407 , m_resourceId(resourceId) 407 , m_resourceId(resourceId)
408 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) 408 , m_textureId(resourceProvider->lockForRead(resourceId)->glId)
409 { 409 {
410 ASSERT(m_textureId); 410 CC_DCHECK(m_textureId);
411 } 411 }
412 412
413 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() 413 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL()
414 { 414 {
415 m_resourceProvider->unlockForRead(m_resourceId); 415 m_resourceProvider->unlockForRead(m_resourceId);
416 } 416 }
417 417
418 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res ourceProvider, CCResourceProvider::ResourceId resourceId) 418 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res ourceProvider, CCResourceProvider::ResourceId resourceId)
419 : m_resourceProvider(resourceProvider) 419 : m_resourceProvider(resourceProvider)
420 , m_resourceId(resourceId) 420 , m_resourceId(resourceId)
421 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) 421 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId)
422 { 422 {
423 ASSERT(m_textureId); 423 CC_DCHECK(m_textureId);
424 } 424 }
425 425
426 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() 426 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL()
427 { 427 {
428 m_resourceProvider->unlockForWrite(m_resourceId); 428 m_resourceProvider->unlockForWrite(m_resourceId);
429 } 429 }
430 430
431 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const Resource* resource) 431 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const Resource* resource)
432 { 432 {
433 ASSERT(resource->pixels); 433 CC_DCHECK(resource->pixels);
434 ASSERT(resource->format == GraphicsContext3D::RGBA); 434 CC_DCHECK(resource->format == GraphicsContext3D::RGBA);
435 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res ource->size.height()); 435 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res ource->size.height());
436 skBitmap->setPixels(resource->pixels); 436 skBitmap->setPixels(resource->pixels);
437 } 437 }
438 438
439 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro vider* resourceProvider, CCResourceProvider::ResourceId resourceId) 439 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro vider* resourceProvider, CCResourceProvider::ResourceId resourceId)
440 : m_resourceProvider(resourceProvider) 440 : m_resourceProvider(resourceProvider)
441 , m_resourceId(resourceId) 441 , m_resourceId(resourceId)
442 { 442 {
443 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid er->lockForRead(resourceId)); 443 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid er->lockForRead(resourceId));
444 } 444 }
(...skipping 23 matching lines...) Expand all
468 , m_defaultResourceType(GLTexture) 468 , m_defaultResourceType(GLTexture)
469 , m_useTextureStorageExt(false) 469 , m_useTextureStorageExt(false)
470 , m_useTextureUsageHint(false) 470 , m_useTextureUsageHint(false)
471 , m_useShallowFlush(false) 471 , m_useShallowFlush(false)
472 , m_maxTextureSize(0) 472 , m_maxTextureSize(0)
473 { 473 {
474 } 474 }
475 475
476 bool CCResourceProvider::initialize() 476 bool CCResourceProvider::initialize()
477 { 477 {
478 ASSERT(CCProxy::isImplThread()); 478 CC_DCHECK(CCProxy::isImplThread());
479 WebGraphicsContext3D* context3d = m_context->context3D(); 479 WebGraphicsContext3D* context3d = m_context->context3D();
480 if (!context3d) { 480 if (!context3d) {
481 m_maxTextureSize = INT_MAX / 2; 481 m_maxTextureSize = INT_MAX / 2;
482 m_textureUploader = UnthrottledTextureUploader::create(); 482 m_textureUploader = UnthrottledTextureUploader::create();
483 return true; 483 return true;
484 } 484 }
485 if (!context3d->makeContextCurrent()) 485 if (!context3d->makeContextCurrent())
486 return false; 486 return false;
487 487
488 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon text3D::EXTENSIONS)); 488 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon text3D::EXTENSIONS));
(...skipping 17 matching lines...) Expand all
506 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); 506 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub));
507 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform ); 507 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform );
508 508
509 m_textureUploader = ThrottledTextureUploader::create(context3d); 509 m_textureUploader = ThrottledTextureUploader::create(context3d);
510 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, & m_maxTextureSize)); 510 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, & m_maxTextureSize));
511 return true; 511 return true;
512 } 512 }
513 513
514 int CCResourceProvider::createChild(int pool) 514 int CCResourceProvider::createChild(int pool)
515 { 515 {
516 ASSERT(CCProxy::isImplThread()); 516 CC_DCHECK(CCProxy::isImplThread());
517 Child childInfo; 517 Child childInfo;
518 childInfo.pool = pool; 518 childInfo.pool = pool;
519 int child = m_nextChild++; 519 int child = m_nextChild++;
520 m_children.add(child, childInfo); 520 m_children.add(child, childInfo);
521 return child; 521 return child;
522 } 522 }
523 523
524 void CCResourceProvider::destroyChild(int child) 524 void CCResourceProvider::destroyChild(int child)
525 { 525 {
526 ASSERT(CCProxy::isImplThread()); 526 CC_DCHECK(CCProxy::isImplThread());
527 ChildMap::iterator it = m_children.find(child); 527 ChildMap::iterator it = m_children.find(child);
528 ASSERT(it != m_children.end()); 528 CC_DCHECK(it != m_children.end());
529 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 529 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
530 deleteOwnedResources(it->value.pool); 530 deleteOwnedResources(it->value.pool);
531 #else 531 #else
532 deleteOwnedResources(it->second.pool); 532 deleteOwnedResources(it->second.pool);
533 #endif 533 #endif
534 m_children.remove(it); 534 m_children.remove(it);
535 trimMailboxDeque(); 535 trimMailboxDeque();
536 } 536 }
537 537
538 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap (int child) const 538 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap (int child) const
539 { 539 {
540 ASSERT(CCProxy::isImplThread()); 540 CC_DCHECK(CCProxy::isImplThread());
541 ChildMap::const_iterator it = m_children.find(child); 541 ChildMap::const_iterator it = m_children.find(child);
542 ASSERT(it != m_children.end()); 542 CC_DCHECK(it != m_children.end());
543 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 543 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
544 return it->value.childToParentMap; 544 return it->value.childToParentMap;
545 #else 545 #else
546 return it->second.childToParentMap; 546 return it->second.childToParentMap;
547 #endif 547 #endif
548 } 548 }
549 549
550 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa rent(const ResourceIdArray& resources) 550 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa rent(const ResourceIdArray& resources)
551 { 551 {
552 ASSERT(CCProxy::isImplThread()); 552 CC_DCHECK(CCProxy::isImplThread());
553 TransferableResourceList list; 553 TransferableResourceList list;
554 list.syncPoint = 0; 554 list.syncPoint = 0;
555 WebGraphicsContext3D* context3d = m_context->context3D(); 555 WebGraphicsContext3D* context3d = m_context->context3D();
556 if (!context3d || !context3d->makeContextCurrent()) { 556 if (!context3d || !context3d->makeContextCurrent()) {
557 // FIXME: Implement this path for software compositing. 557 // FIXME: Implement this path for software compositing.
558 return list; 558 return list;
559 } 559 }
560 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 560 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
561 TransferableResource resource; 561 TransferableResource resource;
562 if (transferResource(context3d, *it, &resource)) { 562 if (transferResource(context3d, *it, &resource)) {
563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
564 m_resources.find(*it)->value.exported = true; 564 m_resources.find(*it)->value.exported = true;
565 #else 565 #else
566 m_resources.find(*it)->second.exported = true; 566 m_resources.find(*it)->second.exported = true;
567 #endif 567 #endif
568 list.resources.append(resource); 568 list.resources.append(resource);
569 } 569 }
570 } 570 }
571 if (list.resources.size()) 571 if (list.resources.size())
572 list.syncPoint = context3d->insertSyncPoint(); 572 list.syncPoint = context3d->insertSyncPoint();
573 return list; 573 return list;
574 } 574 }
575 575
576 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh ild(int child, const ResourceIdArray& resources) 576 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh ild(int child, const ResourceIdArray& resources)
577 { 577 {
578 ASSERT(CCProxy::isImplThread()); 578 CC_DCHECK(CCProxy::isImplThread());
579 TransferableResourceList list; 579 TransferableResourceList list;
580 list.syncPoint = 0; 580 list.syncPoint = 0;
581 WebGraphicsContext3D* context3d = m_context->context3D(); 581 WebGraphicsContext3D* context3d = m_context->context3D();
582 if (!context3d || !context3d->makeContextCurrent()) { 582 if (!context3d || !context3d->makeContextCurrent()) {
583 // FIXME: Implement this path for software compositing. 583 // FIXME: Implement this path for software compositing.
584 return list; 584 return list;
585 } 585 }
586 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 586 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
587 Child& childInfo = m_children.find(child)->value; 587 Child& childInfo = m_children.find(child)->value;
588 #else 588 #else
589 Child& childInfo = m_children.find(child)->second; 589 Child& childInfo = m_children.find(child)->second;
590 #endif 590 #endif
591 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 591 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
592 TransferableResource resource; 592 TransferableResource resource;
593 if (!transferResource(context3d, *it, &resource)) 593 if (!transferResource(context3d, *it, &resource))
594 ASSERT_NOT_REACHED(); 594 NOTREACHED();
595 resource.id = childInfo.parentToChildMap.get(*it); 595 resource.id = childInfo.parentToChildMap.get(*it);
596 childInfo.parentToChildMap.remove(*it); 596 childInfo.parentToChildMap.remove(*it);
597 childInfo.childToParentMap.remove(resource.id); 597 childInfo.childToParentMap.remove(resource.id);
598 list.resources.append(resource); 598 list.resources.append(resource);
599 deleteResource(*it); 599 deleteResource(*it);
600 } 600 }
601 if (list.resources.size()) 601 if (list.resources.size())
602 list.syncPoint = context3d->insertSyncPoint(); 602 list.syncPoint = context3d->insertSyncPoint();
603 return list; 603 return list;
604 } 604 }
605 605
606 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL ist& resources) 606 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL ist& resources)
607 { 607 {
608 ASSERT(CCProxy::isImplThread()); 608 CC_DCHECK(CCProxy::isImplThread());
609 WebGraphicsContext3D* context3d = m_context->context3D(); 609 WebGraphicsContext3D* context3d = m_context->context3D();
610 if (!context3d || !context3d->makeContextCurrent()) { 610 if (!context3d || !context3d->makeContextCurrent()) {
611 // FIXME: Implement this path for software compositing. 611 // FIXME: Implement this path for software compositing.
612 return; 612 return;
613 } 613 }
614 if (resources.syncPoint) { 614 if (resources.syncPoint) {
615 // NOTE: If the parent is a browser and the child a renderer, the parent 615 // NOTE: If the parent is a browser and the child a renderer, the parent
616 // is not supposed to have its context wait, because that could induce 616 // is not supposed to have its context wait, because that could induce
617 // deadlocks and/or security issues. The caller is responsible for 617 // deadlocks and/or security issues. The caller is responsible for
618 // waiting asynchronously, and resetting syncPoint before calling this. 618 // waiting asynchronously, and resetting syncPoint before calling this.
(...skipping 15 matching lines...) Expand all
634 Resource resource(textureId, childInfo.pool, it->size, it->format); 634 Resource resource(textureId, childInfo.pool, it->size, it->format);
635 m_resources.add(id, resource); 635 m_resources.add(id, resource);
636 m_mailboxes.append(it->mailbox); 636 m_mailboxes.append(it->mailbox);
637 childInfo.parentToChildMap.add(id, it->id); 637 childInfo.parentToChildMap.add(id, it->id);
638 childInfo.childToParentMap.add(it->id, id); 638 childInfo.childToParentMap.add(it->id, id);
639 } 639 }
640 } 640 }
641 641
642 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou rces) 642 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou rces)
643 { 643 {
644 ASSERT(CCProxy::isImplThread()); 644 CC_DCHECK(CCProxy::isImplThread());
645 WebGraphicsContext3D* context3d = m_context->context3D(); 645 WebGraphicsContext3D* context3d = m_context->context3D();
646 if (!context3d || !context3d->makeContextCurrent()) { 646 if (!context3d || !context3d->makeContextCurrent()) {
647 // FIXME: Implement this path for software compositing. 647 // FIXME: Implement this path for software compositing.
648 return; 648 return;
649 } 649 }
650 if (resources.syncPoint) 650 if (resources.syncPoint)
651 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); 651 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint));
652 for (Vector<TransferableResource>::const_iterator it = resources.resources.b egin(); it != resources.resources.end(); ++it) { 652 for (Vector<TransferableResource>::const_iterator it = resources.resources.b egin(); it != resources.resources.end(); ++it) {
653 ResourceMap::iterator mapIterator = m_resources.find(it->id); 653 ResourceMap::iterator mapIterator = m_resources.find(it->id);
654 ASSERT(mapIterator != m_resources.end()); 654 CC_DCHECK(mapIterator != m_resources.end());
655 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 655 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
656 Resource* resource = &mapIterator->value; 656 Resource* resource = &mapIterator->value;
657 #else 657 #else
658 Resource* resource = &mapIterator->second; 658 Resource* resource = &mapIterator->second;
659 #endif 659 #endif
660 ASSERT(resource->exported); 660 CC_DCHECK(resource->exported);
661 resource->exported = false; 661 resource->exported = false;
662 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res ource->glId)); 662 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res ource->glId));
663 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT URE_2D, it->mailbox.name)); 663 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT URE_2D, it->mailbox.name));
664 m_mailboxes.append(it->mailbox); 664 m_mailboxes.append(it->mailbox);
665 if (resource->markedForDeletion) 665 if (resource->markedForDeletion)
666 deleteResourceInternal(mapIterator); 666 deleteResourceInternal(mapIterator);
667 } 667 }
668 } 668 }
669 669
670 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc eId id, TransferableResource* resource) 670 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc eId id, TransferableResource* resource)
671 { 671 {
672 ASSERT(CCProxy::isImplThread()); 672 CC_DCHECK(CCProxy::isImplThread());
673 ResourceMap::const_iterator it = m_resources.find(id); 673 ResourceMap::const_iterator it = m_resources.find(id);
674 CHECK(it != m_resources.end()); 674 CHECK(it != m_resources.end());
675 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 675 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
676 const Resource* source = &it->value; 676 const Resource* source = &it->value;
677 #else 677 #else
678 const Resource* source = &it->second; 678 const Resource* source = &it->second;
679 #endif 679 #endif
680 ASSERT(!source->lockedForWrite); 680 CC_DCHECK(!source->lockedForWrite);
681 ASSERT(!source->lockForReadCount); 681 CC_DCHECK(!source->lockForReadCount);
682 ASSERT(!source->external); 682 CC_DCHECK(!source->external);
683 if (source->exported) 683 if (source->exported)
684 return false; 684 return false;
685 resource->id = id; 685 resource->id = id;
686 resource->format = source->format; 686 resource->format = source->format;
687 resource->size = source->size; 687 resource->size = source->size;
688 if (!m_mailboxes.isEmpty()) 688 if (!m_mailboxes.isEmpty())
689 resource->mailbox = m_mailboxes.takeFirst(); 689 resource->mailbox = m_mailboxes.takeFirst();
690 else 690 else
691 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); 691 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name));
692 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI d)); 692 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI d));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 if (ContainsKey(childPoolSet, it->second.pool)) 726 if (ContainsKey(childPoolSet, it->second.pool))
727 #endif 727 #endif
728 ++maxMailboxCount; 728 ++maxMailboxCount;
729 } 729 }
730 } 730 }
731 while (m_mailboxes.size() > maxMailboxCount) 731 while (m_mailboxes.size() > maxMailboxCount)
732 m_mailboxes.removeFirst(); 732 m_mailboxes.removeFirst();
733 } 733 }
734 734
735 } 735 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698