OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return false; | 221 return false; |
222 | 222 |
223 sk_sp<const SkImage> textureImage = m_surface->newImageSnapshot( | 223 sk_sp<const SkImage> textureImage = m_surface->newImageSnapshot( |
224 PreferAcceleration, SnapshotReasonCopyToWebGLTexture); | 224 PreferAcceleration, SnapshotReasonCopyToWebGLTexture); |
225 if (!textureImage) | 225 if (!textureImage) |
226 return false; | 226 return false; |
227 | 227 |
228 if (!m_surface->isAccelerated()) | 228 if (!m_surface->isAccelerated()) |
229 return false; | 229 return false; |
230 | 230 |
231 ASSERT( | 231 DCHECK(textureImage->isTextureBacked()); // The isAccelerated() check above |
232 textureImage | 232 // should guarantee this. |
233 ->isTextureBacked()); // isAccelerated() check above should guarantee
this | |
234 // Get the texture ID, flushing pending operations if needed. | 233 // Get the texture ID, flushing pending operations if needed. |
235 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo( | 234 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo( |
236 textureImage->getTextureHandle(true)); | 235 textureImage->getTextureHandle(true)); |
237 if (!textureInfo || !textureInfo->fID) | 236 if (!textureInfo || !textureInfo->fID) |
238 return false; | 237 return false; |
239 | 238 |
240 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique( | 239 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique( |
241 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 240 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
242 if (!provider) | 241 if (!provider) |
243 return false; | 242 return false; |
244 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); | 243 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); |
245 | 244 |
246 gpu::Mailbox mailbox; | 245 gpu::Mailbox mailbox; |
247 IntSize textureSize(textureImage->width(), textureImage->height()); | 246 IntSize textureSize(textureImage->width(), textureImage->height()); |
248 | 247 |
249 // Contexts may be in a different share group. We must transfer the texture th
rough a mailbox first | 248 // Contexts may be in a different share group. We must transfer the texture |
| 249 // through a mailbox first. |
250 sharedGL->GenMailboxCHROMIUM(mailbox.name); | 250 sharedGL->GenMailboxCHROMIUM(mailbox.name); |
251 sharedGL->ProduceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->fTarget, | 251 sharedGL->ProduceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->fTarget, |
252 mailbox.name); | 252 mailbox.name); |
253 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); | 253 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); |
254 sharedGL->Flush(); | 254 sharedGL->Flush(); |
255 | 255 |
256 gpu::SyncToken produceSyncToken; | 256 gpu::SyncToken produceSyncToken; |
257 sharedGL->GenSyncTokenCHROMIUM(sharedFenceSync, produceSyncToken.GetData()); | 257 sharedGL->GenSyncTokenCHROMIUM(sharedFenceSync, produceSyncToken.GetData()); |
258 gl->WaitSyncTokenCHROMIUM(produceSyncToken.GetConstData()); | 258 gl->WaitSyncTokenCHROMIUM(produceSyncToken.GetConstData()); |
259 | 259 |
260 GLuint sourceTexture = | 260 GLuint sourceTexture = |
261 gl->CreateAndConsumeTextureCHROMIUM(textureInfo->fTarget, mailbox.name); | 261 gl->CreateAndConsumeTextureCHROMIUM(textureInfo->fTarget, mailbox.name); |
262 | 262 |
263 // The canvas is stored in a premultiplied format, so unpremultiply if necessa
ry. | 263 // The canvas is stored in a premultiplied format, so unpremultiply if |
264 // The canvas is stored in an inverted position, so the flip semantics are rev
ersed. | 264 // necessary. The canvas is also stored in an inverted position, so the flip |
| 265 // semantics are reversed. |
265 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, | 266 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, |
266 flipY ? GL_FALSE : GL_TRUE, GL_FALSE, | 267 flipY ? GL_FALSE : GL_TRUE, GL_FALSE, |
267 premultiplyAlpha ? GL_FALSE : GL_TRUE); | 268 premultiplyAlpha ? GL_FALSE : GL_TRUE); |
268 | 269 |
269 gl->DeleteTextures(1, &sourceTexture); | 270 gl->DeleteTextures(1, &sourceTexture); |
270 | 271 |
271 const GLuint64 contextFenceSync = gl->InsertFenceSyncCHROMIUM(); | 272 const GLuint64 contextFenceSync = gl->InsertFenceSyncCHROMIUM(); |
272 | 273 |
273 gl->Flush(); | 274 gl->Flush(); |
274 | 275 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 516 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
516 | 517 |
517 Vector<unsigned char> result; | 518 Vector<unsigned char> result; |
518 if (!encodeImage(mimeType, quality, &result)) | 519 if (!encodeImage(mimeType, quality, &result)) |
519 return "data:,"; | 520 return "data:,"; |
520 | 521 |
521 return "data:" + mimeType + ";base64," + base64Encode(result); | 522 return "data:" + mimeType + ";base64," + base64Encode(result); |
522 } | 523 } |
523 | 524 |
524 } // namespace blink | 525 } // namespace blink |
OLD | NEW |