| 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 18 matching lines...) Expand all Loading... |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #include "platform/graphics/ImageBuffer.h" | 33 #include "platform/graphics/ImageBuffer.h" |
| 34 | 34 |
| 35 #include "gpu/command_buffer/client/gles2_interface.h" | 35 #include "gpu/command_buffer/client/gles2_interface.h" |
| 36 #include "platform/MIMETypeRegistry.h" | 36 #include "platform/MIMETypeRegistry.h" |
| 37 #include "platform/geometry/IntRect.h" | 37 #include "platform/geometry/IntRect.h" |
| 38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
| 39 #include "platform/graphics/GraphicsTypes3D.h" | |
| 40 #include "platform/graphics/ImageBufferClient.h" | 39 #include "platform/graphics/ImageBufferClient.h" |
| 41 #include "platform/graphics/StaticBitmapImage.h" | 40 #include "platform/graphics/StaticBitmapImage.h" |
| 42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 41 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 43 #include "platform/graphics/gpu/DrawingBuffer.h" | 42 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 44 #include "platform/graphics/gpu/Extensions3DUtil.h" | 43 #include "platform/graphics/gpu/Extensions3DUtil.h" |
| 45 #include "platform/graphics/skia/SkiaUtils.h" | 44 #include "platform/graphics/skia/SkiaUtils.h" |
| 46 #include "platform/image-encoders/skia/JPEGImageEncoder.h" | 45 #include "platform/image-encoders/skia/JPEGImageEncoder.h" |
| 47 #include "platform/image-encoders/skia/PNGImageEncoder.h" | 46 #include "platform/image-encoders/skia/PNGImageEncoder.h" |
| 48 #include "platform/image-encoders/skia/WEBPImageEncoder.h" | 47 #include "platform/image-encoders/skia/WEBPImageEncoder.h" |
| 49 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (m_snapshotState == DidAcquireSnapshot) | 170 if (m_snapshotState == DidAcquireSnapshot) |
| 172 m_snapshotState = DrawnToAfterSnapshot; | 171 m_snapshotState = DrawnToAfterSnapshot; |
| 173 m_surface->didDraw(rect); | 172 m_surface->didDraw(rect); |
| 174 } | 173 } |
| 175 | 174 |
| 176 WebLayer* ImageBuffer::platformLayer() const | 175 WebLayer* ImageBuffer::platformLayer() const |
| 177 { | 176 { |
| 178 return m_surface->layer(); | 177 return m_surface->layer(); |
| 179 } | 178 } |
| 180 | 179 |
| 181 bool ImageBuffer::copyToPlatformTexture(gpu::gles2::GLES2Interface* gl, Platform
3DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool prem
ultiplyAlpha, bool flipY) | 180 bool ImageBuffer::copyToPlatformTexture(gpu::gles2::GLES2Interface* gl, GLuint t
exture, GLenum internalFormat, GLenum destType, GLint level, bool premultiplyAlp
ha, bool flipY) |
| 182 { | 181 { |
| 183 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) | 182 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) |
| 184 return false; | 183 return false; |
| 185 | 184 |
| 186 if (!isSurfaceValid()) | 185 if (!isSurfaceValid()) |
| 187 return false; | 186 return false; |
| 188 | 187 |
| 189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration, SnapshotReasonCopyToWebGLTexture); | 188 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration, SnapshotReasonCopyToWebGLTexture); |
| 190 if (!textureImage) | 189 if (!textureImage) |
| 191 return false; | 190 return false; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 211 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 210 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
| 212 sharedGL->GenMailboxCHROMIUM(mailbox->name); | 211 sharedGL->GenMailboxCHROMIUM(mailbox->name); |
| 213 sharedGL->ProduceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->fTarge
t, mailbox->name); | 212 sharedGL->ProduceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->fTarge
t, mailbox->name); |
| 214 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); | 213 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); |
| 215 sharedGL->Flush(); | 214 sharedGL->Flush(); |
| 216 | 215 |
| 217 sharedGL->GenSyncTokenCHROMIUM(sharedFenceSync, mailbox->syncToken); | 216 sharedGL->GenSyncTokenCHROMIUM(sharedFenceSync, mailbox->syncToken); |
| 218 mailbox->validSyncToken = true; | 217 mailbox->validSyncToken = true; |
| 219 gl->WaitSyncTokenCHROMIUM(mailbox->syncToken); | 218 gl->WaitSyncTokenCHROMIUM(mailbox->syncToken); |
| 220 | 219 |
| 221 Platform3DObject sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(texture
Info->fTarget, mailbox->name); | 220 GLuint sourceTexture = gl->CreateAndConsumeTextureCHROMIUM(textureInfo->fTar
get, mailbox->name); |
| 222 | 221 |
| 223 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. | 222 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. |
| 224 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. | 223 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. |
| 225 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl
ipY ? GL_FALSE : GL_TRUE, GL_FALSE, premultiplyAlpha ? GL_FALSE : GL_TRUE); | 224 gl->CopyTextureCHROMIUM(sourceTexture, texture, internalFormat, destType, fl
ipY ? GL_FALSE : GL_TRUE, GL_FALSE, premultiplyAlpha ? GL_FALSE : GL_TRUE); |
| 226 | 225 |
| 227 gl->DeleteTextures(1, &sourceTexture); | 226 gl->DeleteTextures(1, &sourceTexture); |
| 228 | 227 |
| 229 const GLuint64 contextFenceSync = gl->InsertFenceSyncCHROMIUM(); | 228 const GLuint64 contextFenceSync = gl->InsertFenceSyncCHROMIUM(); |
| 230 | 229 |
| 231 gl->Flush(); | 230 gl->Flush(); |
| 232 | 231 |
| 233 GLbyte syncToken[24]; | 232 GLbyte syncToken[24]; |
| 234 gl->GenSyncTokenCHROMIUM(contextFenceSync, syncToken); | 233 gl->GenSyncTokenCHROMIUM(contextFenceSync, syncToken); |
| 235 sharedGL->WaitSyncTokenCHROMIUM(syncToken); | 234 sharedGL->WaitSyncTokenCHROMIUM(syncToken); |
| 236 | 235 |
| 237 // Undo grContext texture binding changes introduced in this function | 236 // Undo grContext texture binding changes introduced in this function |
| 238 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 237 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
| 239 | 238 |
| 240 return true; | 239 return true; |
| 241 } | 240 } |
| 242 | 241 |
| 243 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) | 242 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) |
| 244 { | 243 { |
| 245 if (!drawingBuffer || !m_surface->isAccelerated()) | 244 if (!drawingBuffer || !m_surface->isAccelerated()) |
| 246 return false; | 245 return false; |
| 247 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 246 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); |
| 248 if (!provider) | 247 if (!provider) |
| 249 return false; | 248 return false; |
| 250 gpu::gles2::GLES2Interface* gl = provider->contextGL(); | 249 gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
| 251 Platform3DObject textureId = m_surface->getBackingTextureHandleForOverwrite(
); | 250 GLuint textureId = m_surface->getBackingTextureHandleForOverwrite(); |
| 252 if (!textureId) | 251 if (!textureId) |
| 253 return false; | 252 return false; |
| 254 | 253 |
| 255 gl->Flush(); | 254 gl->Flush(); |
| 256 | 255 |
| 257 return drawingBuffer->copyToPlatformTexture(gl, textureId, GL_RGBA, | 256 return drawingBuffer->copyToPlatformTexture(gl, textureId, GL_RGBA, |
| 258 GL_UNSIGNED_BYTE, 0, true, false, sourceBuffer); | 257 GL_UNSIGNED_BYTE, 0, true, false, sourceBuffer); |
| 259 } | 258 } |
| 260 | 259 |
| 261 void ImageBuffer::draw(GraphicsContext& context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) | 260 void ImageBuffer::draw(GraphicsContext& context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 400 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 402 | 401 |
| 403 Vector<unsigned char> result; | 402 Vector<unsigned char> result; |
| 404 if (!encodeImage(mimeType, quality, &result)) | 403 if (!encodeImage(mimeType, quality, &result)) |
| 405 return "data:,"; | 404 return "data:,"; |
| 406 | 405 |
| 407 return "data:" + mimeType + ";base64," + base64Encode(result); | 406 return "data:" + mimeType + ";base64," + base64Encode(result); |
| 408 } | 407 } |
| 409 | 408 |
| 410 } // namespace blink | 409 } // namespace blink |
| OLD | NEW |