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