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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Resource* resource = &it->second; | 143 Resource* resource = &it->second; |
144 return !!resource->lockForReadCount || resource->exported; | 144 return !!resource->lockForReadCount || resource->exported; |
145 } | 145 } |
146 | 146 |
147 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) | 147 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) |
148 { | 148 { |
149 switch (m_defaultResourceType) { | 149 switch (m_defaultResourceType) { |
150 case GLTexture: | 150 case GLTexture: |
151 return createGLTexture(pool, size, format, hint); | 151 return createGLTexture(pool, size, format, hint); |
152 case Bitmap: | 152 case Bitmap: |
153 ASSERT(format == GraphicsContext3D::RGBA); | 153 CC_DCHECK(format == GraphicsContext3D::RGBA); |
154 return createBitmap(pool, size); | 154 return createBitmap(pool, size); |
155 } | 155 } |
156 | 156 |
157 CRASH(); | 157 CRASH(); |
158 return 0; | 158 return 0; |
159 } | 159 } |
160 | 160 |
161 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con
st IntSize& size, GC3Denum format, TextureUsageHint hint) | 161 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con
st IntSize& size, GC3Denum format, TextureUsageHint hint) |
162 { | 162 { |
163 ASSERT(CCProxy::isImplThread()); | 163 CC_DCHECK(CCProxy::isImplThread()); |
164 unsigned textureId = 0; | 164 unsigned textureId = 0; |
165 WebGraphicsContext3D* context3d = m_context->context3D(); | 165 WebGraphicsContext3D* context3d = m_context->context3D(); |
166 ASSERT(context3d); | 166 CC_DCHECK(context3d); |
167 GLC(context3d, textureId = context3d->createTexture()); | 167 GLC(context3d, textureId = context3d->createTexture()); |
168 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); | 168 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); |
169 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); | 169 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_MAG_FILTER, GraphicsContext3D::LINEAR)); | 170 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_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); | 171 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_T, GraphicsContext3D::CLAMP_TO_EDGE)); | 172 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); |
173 | 173 |
174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); | 175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); |
176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
177 GC3Denum storageFormat = textureToStorageFormat(format); | 177 GC3Denum storageFormat = textureToStorageFormat(format); |
178 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); | 178 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); |
179 } else | 179 } else |
180 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); | 180 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); |
181 ResourceId id = m_nextId++; | 181 ResourceId id = m_nextId++; |
182 Resource resource(textureId, pool, size, format); | 182 Resource resource(textureId, pool, size, format); |
183 m_resources[id] = resource; | 183 m_resources[id] = resource; |
184 return id; | 184 return id; |
185 } | 185 } |
186 | 186 |
187 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) | 187 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) |
188 { | 188 { |
189 ASSERT(CCProxy::isImplThread()); | 189 CC_DCHECK(CCProxy::isImplThread()); |
190 | 190 |
191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
192 | 192 |
193 ResourceId id = m_nextId++; | 193 ResourceId id = m_nextId++; |
194 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); | 194 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); |
195 m_resources[id] = resource; | 195 m_resources[id] = resource; |
196 return id; | 196 return id; |
197 } | 197 } |
198 | 198 |
199 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) | 199 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) |
200 { | 200 { |
201 ASSERT(CCProxy::isImplThread()); | 201 CC_DCHECK(CCProxy::isImplThread()); |
202 ASSERT(m_context->context3D()); | 202 CC_DCHECK(m_context->context3D()); |
203 ResourceId id = m_nextId++; | 203 ResourceId id = m_nextId++; |
204 Resource resource(textureId, 0, IntSize(), 0); | 204 Resource resource(textureId, 0, IntSize(), 0); |
205 resource.external = true; | 205 resource.external = true; |
206 m_resources[id] = resource; | 206 m_resources[id] = resource; |
207 return id; | 207 return id; |
208 } | 208 } |
209 | 209 |
210 void CCResourceProvider::deleteResource(ResourceId id) | 210 void CCResourceProvider::deleteResource(ResourceId id) |
211 { | 211 { |
212 ASSERT(CCProxy::isImplThread()); | 212 CC_DCHECK(CCProxy::isImplThread()); |
213 ResourceMap::iterator it = m_resources.find(id); | 213 ResourceMap::iterator it = m_resources.find(id); |
214 CHECK(it != m_resources.end()); | 214 CHECK(it != m_resources.end()); |
215 Resource* resource = &it->second; | 215 Resource* resource = &it->second; |
216 ASSERT(!resource->lockedForWrite); | 216 CC_DCHECK(!resource->lockedForWrite); |
217 ASSERT(!resource->lockForReadCount); | 217 CC_DCHECK(!resource->lockForReadCount); |
218 ASSERT(!resource->markedForDeletion); | 218 CC_DCHECK(!resource->markedForDeletion); |
219 | 219 |
220 if (resource->exported) { | 220 if (resource->exported) { |
221 resource->markedForDeletion = true; | 221 resource->markedForDeletion = true; |
222 return; | 222 return; |
223 } else | 223 } else |
224 deleteResourceInternal(it); | 224 deleteResourceInternal(it); |
225 } | 225 } |
226 | 226 |
227 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 227 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
228 { | 228 { |
229 Resource* resource = &it->second; | 229 Resource* resource = &it->second; |
230 if (resource->glId && !resource->external) { | 230 if (resource->glId && !resource->external) { |
231 WebGraphicsContext3D* context3d = m_context->context3D(); | 231 WebGraphicsContext3D* context3d = m_context->context3D(); |
232 ASSERT(context3d); | 232 CC_DCHECK(context3d); |
233 GLC(context3d, context3d->deleteTexture(resource->glId)); | 233 GLC(context3d, context3d->deleteTexture(resource->glId)); |
234 } | 234 } |
235 if (resource->pixels) | 235 if (resource->pixels) |
236 delete resource->pixels; | 236 delete resource->pixels; |
237 | 237 |
238 m_resources.erase(it); | 238 m_resources.erase(it); |
239 } | 239 } |
240 | 240 |
241 void CCResourceProvider::deleteOwnedResources(int pool) | 241 void CCResourceProvider::deleteOwnedResources(int pool) |
242 { | 242 { |
243 ASSERT(CCProxy::isImplThread()); | 243 CC_DCHECK(CCProxy::isImplThread()); |
244 ResourceIdArray toDelete; | 244 ResourceIdArray toDelete; |
245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) | 246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) |
247 toDelete.append(it->first); | 247 toDelete.append(it->first); |
248 } | 248 } |
249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
250 deleteResource(*it); | 250 deleteResource(*it); |
251 } | 251 } |
252 | 252 |
253 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) | 253 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) |
254 { | 254 { |
255 ResourceMap::iterator it = m_resources.find(id); | 255 ResourceMap::iterator it = m_resources.find(id); |
256 CHECK(it != m_resources.end()); | 256 CHECK(it != m_resources.end()); |
257 Resource* resource = &it->second; | 257 Resource* resource = &it->second; |
258 return resource->type; | 258 return resource->type; |
259 } | 259 } |
260 | 260 |
261 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 261 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
262 { | 262 { |
263 ASSERT(CCProxy::isImplThread()); | 263 CC_DCHECK(CCProxy::isImplThread()); |
264 ResourceMap::iterator it = m_resources.find(id); | 264 ResourceMap::iterator it = m_resources.find(id); |
265 CHECK(it != m_resources.end()); | 265 CHECK(it != m_resources.end()); |
266 Resource* resource = &it->second; | 266 Resource* resource = &it->second; |
267 ASSERT(!resource->lockedForWrite); | 267 CC_DCHECK(!resource->lockedForWrite); |
268 ASSERT(!resource->lockForReadCount); | 268 CC_DCHECK(!resource->lockForReadCount); |
269 ASSERT(!resource->external); | 269 CC_DCHECK(!resource->external); |
270 ASSERT(!resource->exported); | 270 CC_DCHECK(!resource->exported); |
271 | 271 |
272 if (resource->glId) { | 272 if (resource->glId) { |
273 WebGraphicsContext3D* context3d = m_context->context3D(); | 273 WebGraphicsContext3D* context3d = m_context->context3D(); |
274 ASSERT(context3d); | 274 CC_DCHECK(context3d); |
275 ASSERT(m_texSubImage.get()); | 275 CC_DCHECK(m_texSubImage.get()); |
276 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); | 276 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); |
277 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, resource
->format, context3d); | 277 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, resource
->format, context3d); |
278 } | 278 } |
279 | 279 |
280 if (resource->pixels) { | 280 if (resource->pixels) { |
281 SkBitmap srcFull; | 281 SkBitmap srcFull; |
282 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); | 282 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); |
283 srcFull.setPixels(const_cast<uint8_t*>(image)); | 283 srcFull.setPixels(const_cast<uint8_t*>(image)); |
284 SkBitmap srcSubset; | 284 SkBitmap srcSubset; |
285 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); | 285 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); |
286 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 286 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
287 srcFull.extractSubset(&srcSubset, skSourceRect); | 287 srcFull.extractSubset(&srcSubset, skSourceRect); |
288 | 288 |
289 ScopedWriteLockSoftware lock(this, id); | 289 ScopedWriteLockSoftware lock(this, id); |
290 SkCanvas* dest = lock.skCanvas(); | 290 SkCanvas* dest = lock.skCanvas(); |
291 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); | 291 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 void CCResourceProvider::flush() | 295 void CCResourceProvider::flush() |
296 { | 296 { |
297 ASSERT(CCProxy::isImplThread()); | 297 CC_DCHECK(CCProxy::isImplThread()); |
298 WebGraphicsContext3D* context3d = m_context->context3D(); | 298 WebGraphicsContext3D* context3d = m_context->context3D(); |
299 if (context3d) | 299 if (context3d) |
300 context3d->flush(); | 300 context3d->flush(); |
301 } | 301 } |
302 | 302 |
303 bool CCResourceProvider::shallowFlushIfSupported() | 303 bool CCResourceProvider::shallowFlushIfSupported() |
304 { | 304 { |
305 ASSERT(CCProxy::isImplThread()); | 305 CC_DCHECK(CCProxy::isImplThread()); |
306 WebGraphicsContext3D* context3d = m_context->context3D(); | 306 WebGraphicsContext3D* context3d = m_context->context3D(); |
307 if (!context3d || !m_useShallowFlush) | 307 if (!context3d || !m_useShallowFlush) |
308 return false; | 308 return false; |
309 | 309 |
310 context3d->shallowFlushCHROMIUM(); | 310 context3d->shallowFlushCHROMIUM(); |
311 return true; | 311 return true; |
312 } | 312 } |
313 | 313 |
314 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) | 314 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) |
315 { | 315 { |
316 ASSERT(CCProxy::isImplThread()); | 316 CC_DCHECK(CCProxy::isImplThread()); |
317 ResourceMap::iterator it = m_resources.find(id); | 317 ResourceMap::iterator it = m_resources.find(id); |
318 CHECK(it != m_resources.end()); | 318 CHECK(it != m_resources.end()); |
319 | 319 |
320 Resource* resource = &it->second; | 320 Resource* resource = &it->second; |
321 ASSERT(!resource->lockedForWrite); | 321 CC_DCHECK(!resource->lockedForWrite); |
322 ASSERT(!resource->exported); | 322 CC_DCHECK(!resource->exported); |
323 resource->lockForReadCount++; | 323 resource->lockForReadCount++; |
324 return resource; | 324 return resource; |
325 } | 325 } |
326 | 326 |
327 void CCResourceProvider::unlockForRead(ResourceId id) | 327 void CCResourceProvider::unlockForRead(ResourceId id) |
328 { | 328 { |
329 ASSERT(CCProxy::isImplThread()); | 329 CC_DCHECK(CCProxy::isImplThread()); |
330 ResourceMap::iterator it = m_resources.find(id); | 330 ResourceMap::iterator it = m_resources.find(id); |
331 CHECK(it != m_resources.end()); | 331 CHECK(it != m_resources.end()); |
332 Resource* resource = &it->second; | 332 Resource* resource = &it->second; |
333 ASSERT(resource->lockForReadCount > 0); | 333 CC_DCHECK(resource->lockForReadCount > 0); |
334 ASSERT(!resource->exported); | 334 CC_DCHECK(!resource->exported); |
335 resource->lockForReadCount--; | 335 resource->lockForReadCount--; |
336 } | 336 } |
337 | 337 |
338 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) | 338 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) |
339 { | 339 { |
340 ASSERT(CCProxy::isImplThread()); | 340 CC_DCHECK(CCProxy::isImplThread()); |
341 ResourceMap::iterator it = m_resources.find(id); | 341 ResourceMap::iterator it = m_resources.find(id); |
342 CHECK(it != m_resources.end()); | 342 CHECK(it != m_resources.end()); |
343 Resource* resource = &it->second; | 343 Resource* resource = &it->second; |
344 ASSERT(!resource->lockedForWrite); | 344 CC_DCHECK(!resource->lockedForWrite); |
345 ASSERT(!resource->lockForReadCount); | 345 CC_DCHECK(!resource->lockForReadCount); |
346 ASSERT(!resource->exported); | 346 CC_DCHECK(!resource->exported); |
347 ASSERT(!resource->external); | 347 CC_DCHECK(!resource->external); |
348 resource->lockedForWrite = true; | 348 resource->lockedForWrite = true; |
349 return resource; | 349 return resource; |
350 } | 350 } |
351 | 351 |
352 void CCResourceProvider::unlockForWrite(ResourceId id) | 352 void CCResourceProvider::unlockForWrite(ResourceId id) |
353 { | 353 { |
354 ASSERT(CCProxy::isImplThread()); | 354 CC_DCHECK(CCProxy::isImplThread()); |
355 ResourceMap::iterator it = m_resources.find(id); | 355 ResourceMap::iterator it = m_resources.find(id); |
356 CHECK(it != m_resources.end()); | 356 CHECK(it != m_resources.end()); |
357 Resource* resource = &it->second; | 357 Resource* resource = &it->second; |
358 ASSERT(resource->lockedForWrite); | 358 CC_DCHECK(resource->lockedForWrite); |
359 ASSERT(!resource->exported); | 359 CC_DCHECK(!resource->exported); |
360 ASSERT(!resource->external); | 360 CC_DCHECK(!resource->external); |
361 resource->lockedForWrite = false; | 361 resource->lockedForWrite = false; |
362 } | 362 } |
363 | 363 |
364 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) | 364 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) |
365 : m_resourceProvider(resourceProvider) | 365 : m_resourceProvider(resourceProvider) |
366 , m_resourceId(resourceId) | 366 , m_resourceId(resourceId) |
367 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) | 367 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) |
368 { | 368 { |
369 ASSERT(m_textureId); | 369 CC_DCHECK(m_textureId); |
370 } | 370 } |
371 | 371 |
372 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() | 372 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() |
373 { | 373 { |
374 m_resourceProvider->unlockForRead(m_resourceId); | 374 m_resourceProvider->unlockForRead(m_resourceId); |
375 } | 375 } |
376 | 376 |
377 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res
ourceProvider, CCResourceProvider::ResourceId resourceId) | 377 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res
ourceProvider, CCResourceProvider::ResourceId resourceId) |
378 : m_resourceProvider(resourceProvider) | 378 : m_resourceProvider(resourceProvider) |
379 , m_resourceId(resourceId) | 379 , m_resourceId(resourceId) |
380 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) | 380 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) |
381 { | 381 { |
382 ASSERT(m_textureId); | 382 CC_DCHECK(m_textureId); |
383 } | 383 } |
384 | 384 |
385 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() | 385 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() |
386 { | 386 { |
387 m_resourceProvider->unlockForWrite(m_resourceId); | 387 m_resourceProvider->unlockForWrite(m_resourceId); |
388 } | 388 } |
389 | 389 |
390 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const
Resource* resource) | 390 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const
Resource* resource) |
391 { | 391 { |
392 ASSERT(resource->pixels); | 392 CC_DCHECK(resource->pixels); |
393 ASSERT(resource->format == GraphicsContext3D::RGBA); | 393 CC_DCHECK(resource->format == GraphicsContext3D::RGBA); |
394 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res
ource->size.height()); | 394 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res
ource->size.height()); |
395 skBitmap->setPixels(resource->pixels); | 395 skBitmap->setPixels(resource->pixels); |
396 } | 396 } |
397 | 397 |
398 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro
vider* resourceProvider, CCResourceProvider::ResourceId resourceId) | 398 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro
vider* resourceProvider, CCResourceProvider::ResourceId resourceId) |
399 : m_resourceProvider(resourceProvider) | 399 : m_resourceProvider(resourceProvider) |
400 , m_resourceId(resourceId) | 400 , m_resourceId(resourceId) |
401 { | 401 { |
402 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForRead(resourceId)); | 402 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForRead(resourceId)); |
403 } | 403 } |
(...skipping 23 matching lines...) Expand all Loading... |
427 , m_defaultResourceType(GLTexture) | 427 , m_defaultResourceType(GLTexture) |
428 , m_useTextureStorageExt(false) | 428 , m_useTextureStorageExt(false) |
429 , m_useTextureUsageHint(false) | 429 , m_useTextureUsageHint(false) |
430 , m_useShallowFlush(false) | 430 , m_useShallowFlush(false) |
431 , m_maxTextureSize(0) | 431 , m_maxTextureSize(0) |
432 { | 432 { |
433 } | 433 } |
434 | 434 |
435 bool CCResourceProvider::initialize() | 435 bool CCResourceProvider::initialize() |
436 { | 436 { |
437 ASSERT(CCProxy::isImplThread()); | 437 CC_DCHECK(CCProxy::isImplThread()); |
438 WebGraphicsContext3D* context3d = m_context->context3D(); | 438 WebGraphicsContext3D* context3d = m_context->context3D(); |
439 if (!context3d) { | 439 if (!context3d) { |
440 m_maxTextureSize = INT_MAX / 2; | 440 m_maxTextureSize = INT_MAX / 2; |
441 m_textureUploader = UnthrottledTextureUploader::create(); | 441 m_textureUploader = UnthrottledTextureUploader::create(); |
442 return true; | 442 return true; |
443 } | 443 } |
444 if (!context3d->makeContextCurrent()) | 444 if (!context3d->makeContextCurrent()) |
445 return false; | 445 return false; |
446 | 446 |
447 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); | 447 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); |
(...skipping 17 matching lines...) Expand all Loading... |
465 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); | 465 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); |
466 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 466 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
467 | 467 |
468 m_textureUploader = ThrottledTextureUploader::create(context3d); | 468 m_textureUploader = ThrottledTextureUploader::create(context3d); |
469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); | 469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 int CCResourceProvider::createChild(int pool) | 473 int CCResourceProvider::createChild(int pool) |
474 { | 474 { |
475 ASSERT(CCProxy::isImplThread()); | 475 CC_DCHECK(CCProxy::isImplThread()); |
476 Child childInfo; | 476 Child childInfo; |
477 childInfo.pool = pool; | 477 childInfo.pool = pool; |
478 int child = m_nextChild++; | 478 int child = m_nextChild++; |
479 m_children[child] = childInfo; | 479 m_children[child] = childInfo; |
480 return child; | 480 return child; |
481 } | 481 } |
482 | 482 |
483 void CCResourceProvider::destroyChild(int child) | 483 void CCResourceProvider::destroyChild(int child) |
484 { | 484 { |
485 ASSERT(CCProxy::isImplThread()); | 485 CC_DCHECK(CCProxy::isImplThread()); |
486 ChildMap::iterator it = m_children.find(child); | 486 ChildMap::iterator it = m_children.find(child); |
487 ASSERT(it != m_children.end()); | 487 CC_DCHECK(it != m_children.end()); |
488 deleteOwnedResources(it->second.pool); | 488 deleteOwnedResources(it->second.pool); |
489 m_children.erase(it); | 489 m_children.erase(it); |
490 trimMailboxDeque(); | 490 trimMailboxDeque(); |
491 } | 491 } |
492 | 492 |
493 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const | 493 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const |
494 { | 494 { |
495 ASSERT(CCProxy::isImplThread()); | 495 CC_DCHECK(CCProxy::isImplThread()); |
496 ChildMap::const_iterator it = m_children.find(child); | 496 ChildMap::const_iterator it = m_children.find(child); |
497 ASSERT(it != m_children.end()); | 497 CC_DCHECK(it != m_children.end()); |
498 return it->second.childToParentMap; | 498 return it->second.childToParentMap; |
499 } | 499 } |
500 | 500 |
501 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) | 501 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) |
502 { | 502 { |
503 ASSERT(CCProxy::isImplThread()); | 503 CC_DCHECK(CCProxy::isImplThread()); |
504 TransferableResourceList list; | 504 TransferableResourceList list; |
505 list.syncPoint = 0; | 505 list.syncPoint = 0; |
506 WebGraphicsContext3D* context3d = m_context->context3D(); | 506 WebGraphicsContext3D* context3d = m_context->context3D(); |
507 if (!context3d || !context3d->makeContextCurrent()) { | 507 if (!context3d || !context3d->makeContextCurrent()) { |
508 // FIXME: Implement this path for software compositing. | 508 // FIXME: Implement this path for software compositing. |
509 return list; | 509 return list; |
510 } | 510 } |
511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
512 TransferableResource resource; | 512 TransferableResource resource; |
513 if (transferResource(context3d, *it, &resource)) { | 513 if (transferResource(context3d, *it, &resource)) { |
514 m_resources.find(*it)->second.exported = true; | 514 m_resources.find(*it)->second.exported = true; |
515 list.resources.append(resource); | 515 list.resources.append(resource); |
516 } | 516 } |
517 } | 517 } |
518 if (list.resources.size()) | 518 if (list.resources.size()) |
519 list.syncPoint = context3d->insertSyncPoint(); | 519 list.syncPoint = context3d->insertSyncPoint(); |
520 return list; | 520 return list; |
521 } | 521 } |
522 | 522 |
523 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) | 523 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) |
524 { | 524 { |
525 ASSERT(CCProxy::isImplThread()); | 525 CC_DCHECK(CCProxy::isImplThread()); |
526 TransferableResourceList list; | 526 TransferableResourceList list; |
527 list.syncPoint = 0; | 527 list.syncPoint = 0; |
528 WebGraphicsContext3D* context3d = m_context->context3D(); | 528 WebGraphicsContext3D* context3d = m_context->context3D(); |
529 if (!context3d || !context3d->makeContextCurrent()) { | 529 if (!context3d || !context3d->makeContextCurrent()) { |
530 // FIXME: Implement this path for software compositing. | 530 // FIXME: Implement this path for software compositing. |
531 return list; | 531 return list; |
532 } | 532 } |
533 Child& childInfo = m_children.find(child)->second; | 533 Child& childInfo = m_children.find(child)->second; |
534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
535 TransferableResource resource; | 535 TransferableResource resource; |
536 if (!transferResource(context3d, *it, &resource)) | 536 if (!transferResource(context3d, *it, &resource)) |
537 ASSERT_NOT_REACHED(); | 537 NOTREACHED(); |
538 ASSERT(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 538 CC_DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChil
dMap.end()); |
539 resource.id = childInfo.parentToChildMap[*it]; | 539 resource.id = childInfo.parentToChildMap[*it]; |
540 childInfo.parentToChildMap.erase(*it); | 540 childInfo.parentToChildMap.erase(*it); |
541 childInfo.childToParentMap.erase(resource.id); | 541 childInfo.childToParentMap.erase(resource.id); |
542 list.resources.append(resource); | 542 list.resources.append(resource); |
543 deleteResource(*it); | 543 deleteResource(*it); |
544 } | 544 } |
545 if (list.resources.size()) | 545 if (list.resources.size()) |
546 list.syncPoint = context3d->insertSyncPoint(); | 546 list.syncPoint = context3d->insertSyncPoint(); |
547 return list; | 547 return list; |
548 } | 548 } |
549 | 549 |
550 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) | 550 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) |
551 { | 551 { |
552 ASSERT(CCProxy::isImplThread()); | 552 CC_DCHECK(CCProxy::isImplThread()); |
553 WebGraphicsContext3D* context3d = m_context->context3D(); | 553 WebGraphicsContext3D* context3d = m_context->context3D(); |
554 if (!context3d || !context3d->makeContextCurrent()) { | 554 if (!context3d || !context3d->makeContextCurrent()) { |
555 // FIXME: Implement this path for software compositing. | 555 // FIXME: Implement this path for software compositing. |
556 return; | 556 return; |
557 } | 557 } |
558 if (resources.syncPoint) { | 558 if (resources.syncPoint) { |
559 // NOTE: If the parent is a browser and the child a renderer, the parent | 559 // NOTE: If the parent is a browser and the child a renderer, the parent |
560 // is not supposed to have its context wait, because that could induce | 560 // is not supposed to have its context wait, because that could induce |
561 // deadlocks and/or security issues. The caller is responsible for | 561 // deadlocks and/or security issues. The caller is responsible for |
562 // waiting asynchronously, and resetting syncPoint before calling this. | 562 // waiting asynchronously, and resetting syncPoint before calling this. |
(...skipping 11 matching lines...) Expand all Loading... |
574 Resource resource(textureId, childInfo.pool, it->size, it->format); | 574 Resource resource(textureId, childInfo.pool, it->size, it->format); |
575 m_resources[id] = resource; | 575 m_resources[id] = resource; |
576 m_mailboxes.append(it->mailbox); | 576 m_mailboxes.append(it->mailbox); |
577 childInfo.parentToChildMap[id] = it->id; | 577 childInfo.parentToChildMap[id] = it->id; |
578 childInfo.childToParentMap[it->id] = id; | 578 childInfo.childToParentMap[it->id] = id; |
579 } | 579 } |
580 } | 580 } |
581 | 581 |
582 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) | 582 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) |
583 { | 583 { |
584 ASSERT(CCProxy::isImplThread()); | 584 CC_DCHECK(CCProxy::isImplThread()); |
585 WebGraphicsContext3D* context3d = m_context->context3D(); | 585 WebGraphicsContext3D* context3d = m_context->context3D(); |
586 if (!context3d || !context3d->makeContextCurrent()) { | 586 if (!context3d || !context3d->makeContextCurrent()) { |
587 // FIXME: Implement this path for software compositing. | 587 // FIXME: Implement this path for software compositing. |
588 return; | 588 return; |
589 } | 589 } |
590 if (resources.syncPoint) | 590 if (resources.syncPoint) |
591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
592 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 592 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { |
593 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 593 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
594 ASSERT(mapIterator != m_resources.end()); | 594 CC_DCHECK(mapIterator != m_resources.end()); |
595 Resource* resource = &mapIterator->second; | 595 Resource* resource = &mapIterator->second; |
596 ASSERT(resource->exported); | 596 CC_DCHECK(resource->exported); |
597 resource->exported = false; | 597 resource->exported = false; |
598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); | 598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); |
599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
600 m_mailboxes.append(it->mailbox); | 600 m_mailboxes.append(it->mailbox); |
601 if (resource->markedForDeletion) | 601 if (resource->markedForDeletion) |
602 deleteResourceInternal(mapIterator); | 602 deleteResourceInternal(mapIterator); |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) | 606 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) |
607 { | 607 { |
608 ASSERT(CCProxy::isImplThread()); | 608 CC_DCHECK(CCProxy::isImplThread()); |
609 ResourceMap::const_iterator it = m_resources.find(id); | 609 ResourceMap::const_iterator it = m_resources.find(id); |
610 CHECK(it != m_resources.end()); | 610 CHECK(it != m_resources.end()); |
611 const Resource* source = &it->second; | 611 const Resource* source = &it->second; |
612 ASSERT(!source->lockedForWrite); | 612 CC_DCHECK(!source->lockedForWrite); |
613 ASSERT(!source->lockForReadCount); | 613 CC_DCHECK(!source->lockForReadCount); |
614 ASSERT(!source->external); | 614 CC_DCHECK(!source->external); |
615 if (source->exported) | 615 if (source->exported) |
616 return false; | 616 return false; |
617 resource->id = id; | 617 resource->id = id; |
618 resource->format = source->format; | 618 resource->format = source->format; |
619 resource->size = source->size; | 619 resource->size = source->size; |
620 if (!m_mailboxes.isEmpty()) | 620 if (!m_mailboxes.isEmpty()) |
621 resource->mailbox = m_mailboxes.takeFirst(); | 621 resource->mailbox = m_mailboxes.takeFirst(); |
622 else | 622 else |
623 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 623 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
624 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); | 624 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); |
(...skipping 21 matching lines...) Expand all Loading... |
646 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 646 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
647 if (ContainsKey(childPoolSet, it->second.pool)) | 647 if (ContainsKey(childPoolSet, it->second.pool)) |
648 ++maxMailboxCount; | 648 ++maxMailboxCount; |
649 } | 649 } |
650 } | 650 } |
651 while (m_mailboxes.size() > maxMailboxCount) | 651 while (m_mailboxes.size() > maxMailboxCount) |
652 m_mailboxes.removeFirst(); | 652 m_mailboxes.removeFirst(); |
653 } | 653 } |
654 | 654 |
655 } | 655 } |
OLD | NEW |