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 "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 Loading... |
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 { | 121 { |
122 WebGraphicsContext3D* context3d = m_context->context3D(); | 122 WebGraphicsContext3D* context3d = m_context->context3D(); |
123 if (!context3d || !context3d->makeContextCurrent()) | 123 if (!context3d || !context3d->makeContextCurrent()) |
124 return; | 124 return; |
125 m_textureUploader.clear(); | 125 m_textureUploader.clear(); |
126 m_textureCopier.clear(); | 126 m_textureCopier.clear(); |
127 } | 127 } |
128 | 128 |
129 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() | 129 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() |
130 { | 130 { |
131 ASSERT(CCProxy::isImplThread()); | 131 DCHECK(CCProxy::isImplThread()); |
132 return m_context->context3D(); | 132 return m_context->context3D(); |
133 } | 133 } |
134 | 134 |
135 bool CCResourceProvider::inUseByConsumer(ResourceId id) | 135 bool CCResourceProvider::inUseByConsumer(ResourceId id) |
136 { | 136 { |
137 ASSERT(CCProxy::isImplThread()); | 137 DCHECK(CCProxy::isImplThread()); |
138 ResourceMap::iterator it = m_resources.find(id); | 138 ResourceMap::iterator it = m_resources.find(id); |
139 CHECK(it != m_resources.end()); | 139 CHECK(it != m_resources.end()); |
140 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 140 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
141 Resource* resource = &it->value; | 141 Resource* resource = &it->value; |
142 #else | 142 #else |
143 Resource* resource = &it->second; | 143 Resource* resource = &it->second; |
144 #endif | 144 #endif |
145 return !!resource->lockForReadCount || resource->exported; | 145 return !!resource->lockForReadCount || resource->exported; |
146 } | 146 } |
147 | 147 |
148 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) | 148 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) |
149 { | 149 { |
150 switch (m_defaultResourceType) { | 150 switch (m_defaultResourceType) { |
151 case GLTexture: | 151 case GLTexture: |
152 return createGLTexture(pool, size, format, hint); | 152 return createGLTexture(pool, size, format, hint); |
153 case Bitmap: | 153 case Bitmap: |
154 ASSERT(format == GraphicsContext3D::RGBA); | 154 DCHECK(format == GraphicsContext3D::RGBA); |
155 return createBitmap(pool, size); | 155 return createBitmap(pool, size); |
156 } | 156 } |
157 | 157 |
158 CRASH(); | 158 CRASH(); |
159 return 0; | 159 return 0; |
160 } | 160 } |
161 | 161 |
162 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con
st IntSize& size, GC3Denum format, TextureUsageHint hint) | 162 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con
st IntSize& size, GC3Denum format, TextureUsageHint hint) |
163 { | 163 { |
164 ASSERT(CCProxy::isImplThread()); | 164 DCHECK(CCProxy::isImplThread()); |
165 unsigned textureId = 0; | 165 unsigned textureId = 0; |
166 WebGraphicsContext3D* context3d = m_context->context3D(); | 166 WebGraphicsContext3D* context3d = m_context->context3D(); |
167 ASSERT(context3d); | 167 DCHECK(context3d); |
168 GLC(context3d, textureId = context3d->createTexture()); | 168 GLC(context3d, textureId = context3d->createTexture()); |
169 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); | 169 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); |
170 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); | 170 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); |
171 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); | 171 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); |
172 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); | 172 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); |
173 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); | 173 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); |
174 | 174 |
175 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 175 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
176 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); | 176 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); |
177 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 177 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
178 GC3Denum storageFormat = textureToStorageFormat(format); | 178 GC3Denum storageFormat = textureToStorageFormat(format); |
179 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); | 179 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); |
180 } else | 180 } else |
181 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); | 181 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); |
182 ResourceId id = m_nextId++; | 182 ResourceId id = m_nextId++; |
183 Resource resource(textureId, pool, size, format); | 183 Resource resource(textureId, pool, size, format); |
184 m_resources.add(id, resource); | 184 m_resources.add(id, resource); |
185 return id; | 185 return id; |
186 } | 186 } |
187 | 187 |
188 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) | 188 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) |
189 { | 189 { |
190 ASSERT(CCProxy::isImplThread()); | 190 DCHECK(CCProxy::isImplThread()); |
191 | 191 |
192 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 192 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
193 | 193 |
194 ResourceId id = m_nextId++; | 194 ResourceId id = m_nextId++; |
195 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); | 195 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); |
196 m_resources.add(id, resource); | 196 m_resources.add(id, resource); |
197 return id; | 197 return id; |
198 } | 198 } |
199 | 199 |
200 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) | 200 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) |
201 { | 201 { |
202 ASSERT(CCProxy::isImplThread()); | 202 DCHECK(CCProxy::isImplThread()); |
203 ASSERT(m_context->context3D()); | 203 DCHECK(m_context->context3D()); |
204 ResourceId id = m_nextId++; | 204 ResourceId id = m_nextId++; |
205 Resource resource(textureId, 0, IntSize(), 0); | 205 Resource resource(textureId, 0, IntSize(), 0); |
206 resource.external = true; | 206 resource.external = true; |
207 m_resources.add(id, resource); | 207 m_resources.add(id, resource); |
208 return id; | 208 return id; |
209 } | 209 } |
210 | 210 |
211 void CCResourceProvider::deleteResource(ResourceId id) | 211 void CCResourceProvider::deleteResource(ResourceId id) |
212 { | 212 { |
213 ASSERT(CCProxy::isImplThread()); | 213 DCHECK(CCProxy::isImplThread()); |
214 ResourceMap::iterator it = m_resources.find(id); | 214 ResourceMap::iterator it = m_resources.find(id); |
215 CHECK(it != m_resources.end()); | 215 CHECK(it != m_resources.end()); |
216 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 216 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
217 Resource* resource = &it->value; | 217 Resource* resource = &it->value; |
218 #else | 218 #else |
219 Resource* resource = &it->second; | 219 Resource* resource = &it->second; |
220 #endif | 220 #endif |
221 ASSERT(!resource->lockedForWrite); | 221 DCHECK(!resource->lockedForWrite); |
222 ASSERT(!resource->lockForReadCount); | 222 DCHECK(!resource->lockForReadCount); |
223 | 223 |
224 if (resource->glId && !resource->external) { | 224 if (resource->glId && !resource->external) { |
225 WebGraphicsContext3D* context3d = m_context->context3D(); | 225 WebGraphicsContext3D* context3d = m_context->context3D(); |
226 ASSERT(context3d); | 226 DCHECK(context3d); |
227 GLC(context3d, context3d->deleteTexture(resource->glId)); | 227 GLC(context3d, context3d->deleteTexture(resource->glId)); |
228 } | 228 } |
229 if (resource->pixels) | 229 if (resource->pixels) |
230 delete resource->pixels; | 230 delete resource->pixels; |
231 | 231 |
232 m_resources.remove(it); | 232 m_resources.remove(it); |
233 } | 233 } |
234 | 234 |
235 void CCResourceProvider::deleteOwnedResources(int pool) | 235 void CCResourceProvider::deleteOwnedResources(int pool) |
236 { | 236 { |
237 ASSERT(CCProxy::isImplThread()); | 237 DCHECK(CCProxy::isImplThread()); |
238 ResourceIdArray toDelete; | 238 ResourceIdArray toDelete; |
239 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 239 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
240 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 240 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
241 if (it->value.pool == pool && !it->value.external) | 241 if (it->value.pool == pool && !it->value.external) |
242 toDelete.append(it->key); | 242 toDelete.append(it->key); |
243 #else | 243 #else |
244 if (it->second.pool == pool && !it->second.external) | 244 if (it->second.pool == pool && !it->second.external) |
245 toDelete.append(it->first); | 245 toDelete.append(it->first); |
246 #endif | 246 #endif |
247 } | 247 } |
248 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 248 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
249 deleteResource(*it); | 249 deleteResource(*it); |
250 } | 250 } |
251 | 251 |
252 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) | 252 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) |
253 { | 253 { |
254 ResourceMap::iterator it = m_resources.find(id); | 254 ResourceMap::iterator it = m_resources.find(id); |
255 CHECK(it != m_resources.end()); | 255 CHECK(it != m_resources.end()); |
256 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 256 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
257 Resource* resource = &it->value; | 257 Resource* resource = &it->value; |
258 #else | 258 #else |
259 Resource* resource = &it->second; | 259 Resource* resource = &it->second; |
260 #endif | 260 #endif |
261 return resource->type; | 261 return resource->type; |
262 } | 262 } |
263 | 263 |
264 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 264 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
265 { | 265 { |
266 ASSERT(CCProxy::isImplThread()); | 266 DCHECK(CCProxy::isImplThread()); |
267 ResourceMap::iterator it = m_resources.find(id); | 267 ResourceMap::iterator it = m_resources.find(id); |
268 CHECK(it != m_resources.end()); | 268 CHECK(it != m_resources.end()); |
269 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 269 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
270 Resource* resource = &it->value; | 270 Resource* resource = &it->value; |
271 #else | 271 #else |
272 Resource* resource = &it->second; | 272 Resource* resource = &it->second; |
273 #endif | 273 #endif |
274 ASSERT(!resource->lockedForWrite); | 274 DCHECK(!resource->lockedForWrite); |
275 ASSERT(!resource->lockForReadCount); | 275 DCHECK(!resource->lockForReadCount); |
276 ASSERT(!resource->external); | 276 DCHECK(!resource->external); |
277 | 277 |
278 if (resource->glId) { | 278 if (resource->glId) { |
279 WebGraphicsContext3D* context3d = m_context->context3D(); | 279 WebGraphicsContext3D* context3d = m_context->context3D(); |
280 ASSERT(context3d); | 280 DCHECK(context3d); |
281 ASSERT(m_texSubImage.get()); | 281 DCHECK(m_texSubImage.get()); |
282 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); | 282 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); |
283 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, resource
->format, context3d); | 283 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, resource
->format, context3d); |
284 } | 284 } |
285 | 285 |
286 if (resource->pixels) { | 286 if (resource->pixels) { |
287 SkBitmap srcFull; | 287 SkBitmap srcFull; |
288 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); | 288 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); |
289 srcFull.setPixels(const_cast<uint8_t*>(image)); | 289 srcFull.setPixels(const_cast<uint8_t*>(image)); |
290 SkBitmap srcSubset; | 290 SkBitmap srcSubset; |
291 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); | 291 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); |
292 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 292 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
293 srcFull.extractSubset(&srcSubset, skSourceRect); | 293 srcFull.extractSubset(&srcSubset, skSourceRect); |
294 | 294 |
295 ScopedWriteLockSoftware lock(this, id); | 295 ScopedWriteLockSoftware lock(this, id); |
296 SkCanvas* dest = lock.skCanvas(); | 296 SkCanvas* dest = lock.skCanvas(); |
297 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); | 297 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 void CCResourceProvider::flush() | 301 void CCResourceProvider::flush() |
302 { | 302 { |
303 ASSERT(CCProxy::isImplThread()); | 303 DCHECK(CCProxy::isImplThread()); |
304 WebGraphicsContext3D* context3d = m_context->context3D(); | 304 WebGraphicsContext3D* context3d = m_context->context3D(); |
305 if (context3d) | 305 if (context3d) |
306 context3d->flush(); | 306 context3d->flush(); |
307 } | 307 } |
308 | 308 |
309 bool CCResourceProvider::shallowFlushIfSupported() | 309 bool CCResourceProvider::shallowFlushIfSupported() |
310 { | 310 { |
311 ASSERT(CCProxy::isImplThread()); | 311 DCHECK(CCProxy::isImplThread()); |
312 WebGraphicsContext3D* context3d = m_context->context3D(); | 312 WebGraphicsContext3D* context3d = m_context->context3D(); |
313 if (!context3d || !m_useShallowFlush) | 313 if (!context3d || !m_useShallowFlush) |
314 return false; | 314 return false; |
315 | 315 |
316 context3d->shallowFlushCHROMIUM(); | 316 context3d->shallowFlushCHROMIUM(); |
317 return true; | 317 return true; |
318 } | 318 } |
319 | 319 |
320 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) | 320 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) |
321 { | 321 { |
322 ASSERT(CCProxy::isImplThread()); | 322 DCHECK(CCProxy::isImplThread()); |
323 ResourceMap::iterator it = m_resources.find(id); | 323 ResourceMap::iterator it = m_resources.find(id); |
324 CHECK(it != m_resources.end()); | 324 CHECK(it != m_resources.end()); |
325 | 325 |
326 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 326 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
327 Resource* resource = &it->value; | 327 Resource* resource = &it->value; |
328 #else | 328 #else |
329 Resource* resource = &it->second; | 329 Resource* resource = &it->second; |
330 #endif | 330 #endif |
331 ASSERT(!resource->lockedForWrite); | 331 DCHECK(!resource->lockedForWrite); |
332 resource->lockForReadCount++; | 332 resource->lockForReadCount++; |
333 return resource; | 333 return resource; |
334 } | 334 } |
335 | 335 |
336 void CCResourceProvider::unlockForRead(ResourceId id) | 336 void CCResourceProvider::unlockForRead(ResourceId id) |
337 { | 337 { |
338 ASSERT(CCProxy::isImplThread()); | 338 DCHECK(CCProxy::isImplThread()); |
339 ResourceMap::iterator it = m_resources.find(id); | 339 ResourceMap::iterator it = m_resources.find(id); |
340 CHECK(it != m_resources.end()); | 340 CHECK(it != m_resources.end()); |
341 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 341 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
342 Resource* resource = &it->value; | 342 Resource* resource = &it->value; |
343 #else | 343 #else |
344 Resource* resource = &it->second; | 344 Resource* resource = &it->second; |
345 #endif | 345 #endif |
346 ASSERT(resource->lockForReadCount > 0); | 346 DCHECK(resource->lockForReadCount > 0); |
347 resource->lockForReadCount--; | 347 resource->lockForReadCount--; |
348 } | 348 } |
349 | 349 |
350 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) | 350 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) |
351 { | 351 { |
352 ASSERT(CCProxy::isImplThread()); | 352 DCHECK(CCProxy::isImplThread()); |
353 ResourceMap::iterator it = m_resources.find(id); | 353 ResourceMap::iterator it = m_resources.find(id); |
354 CHECK(it != m_resources.end()); | 354 CHECK(it != m_resources.end()); |
355 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 355 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
356 Resource* resource = &it->value; | 356 Resource* resource = &it->value; |
357 #else | 357 #else |
358 Resource* resource = &it->second; | 358 Resource* resource = &it->second; |
359 #endif | 359 #endif |
360 ASSERT(!resource->lockedForWrite); | 360 DCHECK(!resource->lockedForWrite); |
361 ASSERT(!resource->lockForReadCount); | 361 DCHECK(!resource->lockForReadCount); |
362 ASSERT(!resource->external); | 362 DCHECK(!resource->external); |
363 resource->lockedForWrite = true; | 363 resource->lockedForWrite = true; |
364 return resource; | 364 return resource; |
365 } | 365 } |
366 | 366 |
367 void CCResourceProvider::unlockForWrite(ResourceId id) | 367 void CCResourceProvider::unlockForWrite(ResourceId id) |
368 { | 368 { |
369 ASSERT(CCProxy::isImplThread()); | 369 DCHECK(CCProxy::isImplThread()); |
370 ResourceMap::iterator it = m_resources.find(id); | 370 ResourceMap::iterator it = m_resources.find(id); |
371 CHECK(it != m_resources.end()); | 371 CHECK(it != m_resources.end()); |
372 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 372 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
373 Resource* resource = &it->value; | 373 Resource* resource = &it->value; |
374 #else | 374 #else |
375 Resource* resource = &it->second; | 375 Resource* resource = &it->second; |
376 #endif | 376 #endif |
377 ASSERT(resource->lockedForWrite); | 377 DCHECK(resource->lockedForWrite); |
378 ASSERT(!resource->external); | 378 DCHECK(!resource->external); |
379 resource->lockedForWrite = false; | 379 resource->lockedForWrite = false; |
380 } | 380 } |
381 | 381 |
382 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) | 382 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) |
383 : m_resourceProvider(resourceProvider) | 383 : m_resourceProvider(resourceProvider) |
384 , m_resourceId(resourceId) | 384 , m_resourceId(resourceId) |
385 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) | 385 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) |
386 { | 386 { |
387 ASSERT(m_textureId); | 387 DCHECK(m_textureId); |
388 } | 388 } |
389 | 389 |
390 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() | 390 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() |
391 { | 391 { |
392 m_resourceProvider->unlockForRead(m_resourceId); | 392 m_resourceProvider->unlockForRead(m_resourceId); |
393 } | 393 } |
394 | 394 |
395 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res
ourceProvider, CCResourceProvider::ResourceId resourceId) | 395 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res
ourceProvider, CCResourceProvider::ResourceId resourceId) |
396 : m_resourceProvider(resourceProvider) | 396 : m_resourceProvider(resourceProvider) |
397 , m_resourceId(resourceId) | 397 , m_resourceId(resourceId) |
398 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) | 398 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) |
399 { | 399 { |
400 ASSERT(m_textureId); | 400 DCHECK(m_textureId); |
401 } | 401 } |
402 | 402 |
403 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() | 403 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() |
404 { | 404 { |
405 m_resourceProvider->unlockForWrite(m_resourceId); | 405 m_resourceProvider->unlockForWrite(m_resourceId); |
406 } | 406 } |
407 | 407 |
408 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const
Resource* resource) | 408 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const
Resource* resource) |
409 { | 409 { |
410 ASSERT(resource->pixels); | 410 DCHECK(resource->pixels); |
411 ASSERT(resource->format == GraphicsContext3D::RGBA); | 411 DCHECK(resource->format == GraphicsContext3D::RGBA); |
412 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res
ource->size.height()); | 412 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res
ource->size.height()); |
413 skBitmap->setPixels(resource->pixels); | 413 skBitmap->setPixels(resource->pixels); |
414 } | 414 } |
415 | 415 |
416 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro
vider* resourceProvider, CCResourceProvider::ResourceId resourceId) | 416 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro
vider* resourceProvider, CCResourceProvider::ResourceId resourceId) |
417 : m_resourceProvider(resourceProvider) | 417 : m_resourceProvider(resourceProvider) |
418 , m_resourceId(resourceId) | 418 , m_resourceId(resourceId) |
419 { | 419 { |
420 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForRead(resourceId)); | 420 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForRead(resourceId)); |
421 } | 421 } |
(...skipping 23 matching lines...) Expand all Loading... |
445 , m_defaultResourceType(GLTexture) | 445 , m_defaultResourceType(GLTexture) |
446 , m_useTextureStorageExt(false) | 446 , m_useTextureStorageExt(false) |
447 , m_useTextureUsageHint(false) | 447 , m_useTextureUsageHint(false) |
448 , m_useShallowFlush(false) | 448 , m_useShallowFlush(false) |
449 , m_maxTextureSize(0) | 449 , m_maxTextureSize(0) |
450 { | 450 { |
451 } | 451 } |
452 | 452 |
453 bool CCResourceProvider::initialize() | 453 bool CCResourceProvider::initialize() |
454 { | 454 { |
455 ASSERT(CCProxy::isImplThread()); | 455 DCHECK(CCProxy::isImplThread()); |
456 WebGraphicsContext3D* context3d = m_context->context3D(); | 456 WebGraphicsContext3D* context3d = m_context->context3D(); |
457 if (!context3d) { | 457 if (!context3d) { |
458 m_maxTextureSize = INT_MAX / 2; | 458 m_maxTextureSize = INT_MAX / 2; |
459 m_textureUploader = UnthrottledTextureUploader::create(); | 459 m_textureUploader = UnthrottledTextureUploader::create(); |
460 return true; | 460 return true; |
461 } | 461 } |
462 if (!context3d->makeContextCurrent()) | 462 if (!context3d->makeContextCurrent()) |
463 return false; | 463 return false; |
464 | 464 |
465 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); | 465 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); |
(...skipping 17 matching lines...) Expand all Loading... |
483 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); | 483 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); |
484 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 484 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
485 | 485 |
486 m_textureUploader = ThrottledTextureUploader::create(context3d); | 486 m_textureUploader = ThrottledTextureUploader::create(context3d); |
487 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); | 487 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); |
488 return true; | 488 return true; |
489 } | 489 } |
490 | 490 |
491 int CCResourceProvider::createChild(int pool) | 491 int CCResourceProvider::createChild(int pool) |
492 { | 492 { |
493 ASSERT(CCProxy::isImplThread()); | 493 DCHECK(CCProxy::isImplThread()); |
494 Child childInfo; | 494 Child childInfo; |
495 childInfo.pool = pool; | 495 childInfo.pool = pool; |
496 int child = m_nextChild++; | 496 int child = m_nextChild++; |
497 m_children.add(child, childInfo); | 497 m_children.add(child, childInfo); |
498 return child; | 498 return child; |
499 } | 499 } |
500 | 500 |
501 void CCResourceProvider::destroyChild(int child) | 501 void CCResourceProvider::destroyChild(int child) |
502 { | 502 { |
503 ASSERT(CCProxy::isImplThread()); | 503 DCHECK(CCProxy::isImplThread()); |
504 ChildMap::iterator it = m_children.find(child); | 504 ChildMap::iterator it = m_children.find(child); |
505 ASSERT(it != m_children.end()); | 505 DCHECK(it != m_children.end()); |
506 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 506 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
507 deleteOwnedResources(it->value.pool); | 507 deleteOwnedResources(it->value.pool); |
508 #else | 508 #else |
509 deleteOwnedResources(it->second.pool); | 509 deleteOwnedResources(it->second.pool); |
510 #endif | 510 #endif |
511 m_children.remove(it); | 511 m_children.remove(it); |
512 trimMailboxDeque(); | 512 trimMailboxDeque(); |
513 } | 513 } |
514 | 514 |
515 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const | 515 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const |
516 { | 516 { |
517 ASSERT(CCProxy::isImplThread()); | 517 DCHECK(CCProxy::isImplThread()); |
518 ChildMap::const_iterator it = m_children.find(child); | 518 ChildMap::const_iterator it = m_children.find(child); |
519 ASSERT(it != m_children.end()); | 519 DCHECK(it != m_children.end()); |
520 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 520 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
521 return it->value.childToParentMap; | 521 return it->value.childToParentMap; |
522 #else | 522 #else |
523 return it->second.childToParentMap; | 523 return it->second.childToParentMap; |
524 #endif | 524 #endif |
525 } | 525 } |
526 | 526 |
527 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) | 527 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) |
528 { | 528 { |
529 ASSERT(CCProxy::isImplThread()); | 529 DCHECK(CCProxy::isImplThread()); |
530 TransferableResourceList list; | 530 TransferableResourceList list; |
531 list.syncPoint = 0; | 531 list.syncPoint = 0; |
532 WebGraphicsContext3D* context3d = m_context->context3D(); | 532 WebGraphicsContext3D* context3d = m_context->context3D(); |
533 if (!context3d || !context3d->makeContextCurrent()) { | 533 if (!context3d || !context3d->makeContextCurrent()) { |
534 // FIXME: Implement this path for software compositing. | 534 // FIXME: Implement this path for software compositing. |
535 return list; | 535 return list; |
536 } | 536 } |
537 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 537 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
538 TransferableResource resource; | 538 TransferableResource resource; |
539 if (transferResource(context3d, *it, &resource)) { | 539 if (transferResource(context3d, *it, &resource)) { |
540 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 540 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
541 m_resources.find(*it)->value.exported = true; | 541 m_resources.find(*it)->value.exported = true; |
542 #else | 542 #else |
543 m_resources.find(*it)->second.exported = true; | 543 m_resources.find(*it)->second.exported = true; |
544 #endif | 544 #endif |
545 list.resources.append(resource); | 545 list.resources.append(resource); |
546 } | 546 } |
547 } | 547 } |
548 if (list.resources.size()) | 548 if (list.resources.size()) |
549 list.syncPoint = context3d->insertSyncPoint(); | 549 list.syncPoint = context3d->insertSyncPoint(); |
550 return list; | 550 return list; |
551 } | 551 } |
552 | 552 |
553 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) | 553 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) |
554 { | 554 { |
555 ASSERT(CCProxy::isImplThread()); | 555 DCHECK(CCProxy::isImplThread()); |
556 TransferableResourceList list; | 556 TransferableResourceList list; |
557 list.syncPoint = 0; | 557 list.syncPoint = 0; |
558 WebGraphicsContext3D* context3d = m_context->context3D(); | 558 WebGraphicsContext3D* context3d = m_context->context3D(); |
559 if (!context3d || !context3d->makeContextCurrent()) { | 559 if (!context3d || !context3d->makeContextCurrent()) { |
560 // FIXME: Implement this path for software compositing. | 560 // FIXME: Implement this path for software compositing. |
561 return list; | 561 return list; |
562 } | 562 } |
563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
564 Child& childInfo = m_children.find(child)->value; | 564 Child& childInfo = m_children.find(child)->value; |
565 #else | 565 #else |
566 Child& childInfo = m_children.find(child)->second; | 566 Child& childInfo = m_children.find(child)->second; |
567 #endif | 567 #endif |
568 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 568 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
569 TransferableResource resource; | 569 TransferableResource resource; |
570 if (!transferResource(context3d, *it, &resource)) | 570 if (!transferResource(context3d, *it, &resource)) |
571 ASSERT_NOT_REACHED(); | 571 NOTREACHED(); |
572 resource.id = childInfo.parentToChildMap.get(*it); | 572 resource.id = childInfo.parentToChildMap.get(*it); |
573 childInfo.parentToChildMap.remove(*it); | 573 childInfo.parentToChildMap.remove(*it); |
574 childInfo.childToParentMap.remove(resource.id); | 574 childInfo.childToParentMap.remove(resource.id); |
575 list.resources.append(resource); | 575 list.resources.append(resource); |
576 deleteResource(*it); | 576 deleteResource(*it); |
577 } | 577 } |
578 if (list.resources.size()) | 578 if (list.resources.size()) |
579 list.syncPoint = context3d->insertSyncPoint(); | 579 list.syncPoint = context3d->insertSyncPoint(); |
580 return list; | 580 return list; |
581 } | 581 } |
582 | 582 |
583 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) | 583 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) |
584 { | 584 { |
585 ASSERT(CCProxy::isImplThread()); | 585 DCHECK(CCProxy::isImplThread()); |
586 WebGraphicsContext3D* context3d = m_context->context3D(); | 586 WebGraphicsContext3D* context3d = m_context->context3D(); |
587 if (!context3d || !context3d->makeContextCurrent()) { | 587 if (!context3d || !context3d->makeContextCurrent()) { |
588 // FIXME: Implement this path for software compositing. | 588 // FIXME: Implement this path for software compositing. |
589 return; | 589 return; |
590 } | 590 } |
591 if (resources.syncPoint) { | 591 if (resources.syncPoint) { |
592 // NOTE: If the parent is a browser and the child a renderer, the parent | 592 // NOTE: If the parent is a browser and the child a renderer, the parent |
593 // is not supposed to have its context wait, because that could induce | 593 // is not supposed to have its context wait, because that could induce |
594 // deadlocks and/or security issues. The caller is responsible for | 594 // deadlocks and/or security issues. The caller is responsible for |
595 // waiting asynchronously, and resetting syncPoint before calling this. | 595 // waiting asynchronously, and resetting syncPoint before calling this. |
(...skipping 15 matching lines...) Expand all Loading... |
611 Resource resource(textureId, childInfo.pool, it->size, it->format); | 611 Resource resource(textureId, childInfo.pool, it->size, it->format); |
612 m_resources.add(id, resource); | 612 m_resources.add(id, resource); |
613 m_mailboxes.append(it->mailbox); | 613 m_mailboxes.append(it->mailbox); |
614 childInfo.parentToChildMap.add(id, it->id); | 614 childInfo.parentToChildMap.add(id, it->id); |
615 childInfo.childToParentMap.add(it->id, id); | 615 childInfo.childToParentMap.add(it->id, id); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) | 619 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) |
620 { | 620 { |
621 ASSERT(CCProxy::isImplThread()); | 621 DCHECK(CCProxy::isImplThread()); |
622 WebGraphicsContext3D* context3d = m_context->context3D(); | 622 WebGraphicsContext3D* context3d = m_context->context3D(); |
623 if (!context3d || !context3d->makeContextCurrent()) { | 623 if (!context3d || !context3d->makeContextCurrent()) { |
624 // FIXME: Implement this path for software compositing. | 624 // FIXME: Implement this path for software compositing. |
625 return; | 625 return; |
626 } | 626 } |
627 if (resources.syncPoint) | 627 if (resources.syncPoint) |
628 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 628 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
629 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 629 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { |
630 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 630 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
631 Resource* resource = &m_resources.find(it->id)->value; | 631 Resource* resource = &m_resources.find(it->id)->value; |
632 #else | 632 #else |
633 Resource* resource = &m_resources.find(it->id)->second; | 633 Resource* resource = &m_resources.find(it->id)->second; |
634 #endif | 634 #endif |
635 ASSERT(resource->exported); | 635 DCHECK(resource->exported); |
636 resource->exported = false; | 636 resource->exported = false; |
637 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); | 637 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); |
638 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 638 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
639 m_mailboxes.append(it->mailbox); | 639 m_mailboxes.append(it->mailbox); |
640 } | 640 } |
641 } | 641 } |
642 | 642 |
643 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) | 643 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) |
644 { | 644 { |
645 ASSERT(CCProxy::isImplThread()); | 645 DCHECK(CCProxy::isImplThread()); |
646 ResourceMap::const_iterator it = m_resources.find(id); | 646 ResourceMap::const_iterator it = m_resources.find(id); |
647 CHECK(it != m_resources.end()); | 647 CHECK(it != m_resources.end()); |
648 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 648 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
649 const Resource* source = &it->value; | 649 const Resource* source = &it->value; |
650 #else | 650 #else |
651 const Resource* source = &it->second; | 651 const Resource* source = &it->second; |
652 #endif | 652 #endif |
653 ASSERT(!source->lockedForWrite); | 653 DCHECK(!source->lockedForWrite); |
654 ASSERT(!source->lockForReadCount); | 654 DCHECK(!source->lockForReadCount); |
655 ASSERT(!source->external); | 655 DCHECK(!source->external); |
656 if (source->exported) | 656 if (source->exported) |
657 return false; | 657 return false; |
658 resource->id = id; | 658 resource->id = id; |
659 resource->format = source->format; | 659 resource->format = source->format; |
660 resource->size = source->size; | 660 resource->size = source->size; |
661 if (!m_mailboxes.isEmpty()) | 661 if (!m_mailboxes.isEmpty()) |
662 resource->mailbox = m_mailboxes.takeFirst(); | 662 resource->mailbox = m_mailboxes.takeFirst(); |
663 else | 663 else |
664 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 664 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
665 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); | 665 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 if (ContainsKey(childPoolSet, it->second.pool)) | 699 if (ContainsKey(childPoolSet, it->second.pool)) |
700 #endif | 700 #endif |
701 ++maxMailboxCount; | 701 ++maxMailboxCount; |
702 } | 702 } |
703 } | 703 } |
704 while (m_mailboxes.size() > maxMailboxCount) | 704 while (m_mailboxes.size() > maxMailboxCount) |
705 m_mailboxes.removeFirst(); | 705 m_mailboxes.removeFirst(); |
706 } | 706 } |
707 | 707 |
708 } | 708 } |
OLD | NEW |