| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return DontCopyBackingStore; | 165 return DontCopyBackingStore; |
| 166 } | 166 } |
| 167 | 167 |
| 168 WebLayer* ImageBuffer::platformLayer() const | 168 WebLayer* ImageBuffer::platformLayer() const |
| 169 { | 169 { |
| 170 return m_surface->layer(); | 170 return m_surface->layer(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) | 173 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) |
| 174 { | 174 { |
| 175 if (!m_surface->isAccelerated() || !getBackingTexture() || !isSurfaceValid()
) | 175 if (!m_surface->isAccelerated() || !isSurfaceValid()) |
| 176 return false; | 176 return false; |
| 177 | 177 |
| 178 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) | 178 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) |
| 179 return false; | 179 return false; |
| 180 | 180 |
| 181 RefPtr<const SkImage> textureImage = m_surface->getBackingTextureImage(); |
| 182 if (!textureImage) |
| 183 return false; |
| 184 |
| 185 ASSERT(textureImage->isTextureBacked()); |
| 186 // Get the texture ID, flushing pending operations if needed. |
| 187 Platform3DObject textureId = textureImage->getTextureHandle(true); |
| 188 if (!textureId) |
| 189 return false; |
| 190 |
| 181 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 191 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); |
| 182 if (!provider) | 192 if (!provider) |
| 183 return false; | 193 return false; |
| 184 WebGraphicsContext3D* sharedContext = provider->context3d(); | 194 WebGraphicsContext3D* sharedContext = provider->context3d(); |
| 185 if (!sharedContext) | 195 if (!sharedContext) |
| 186 return false; | 196 return false; |
| 187 | 197 |
| 188 OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureM
ailbox); | 198 OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureM
ailbox); |
| 189 | 199 |
| 190 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 200 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
| 191 sharedContext->genMailboxCHROMIUM(mailbox->name); | 201 sharedContext->genMailboxCHROMIUM(mailbox->name); |
| 192 sharedContext->produceTextureDirectCHROMIUM(getBackingTexture(), GL_TEXTURE_
2D, mailbox->name); | 202 sharedContext->produceTextureDirectCHROMIUM(textureId, GL_TEXTURE_2D, mailbo
x->name); |
| 193 sharedContext->flush(); | 203 sharedContext->flush(); |
| 194 | 204 |
| 195 mailbox->syncPoint = sharedContext->insertSyncPoint(); | 205 mailbox->syncPoint = sharedContext->insertSyncPoint(); |
| 196 | 206 |
| 197 context->waitSyncPoint(mailbox->syncPoint); | 207 context->waitSyncPoint(mailbox->syncPoint); |
| 198 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, mailbox->name); | 208 Platform3DObject sourceTexture = context->createAndConsumeTextureCHROMIUM(GL
_TEXTURE_2D, mailbox->name); |
| 199 | 209 |
| 200 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. | 210 // The canvas is stored in a premultiplied format, so unpremultiply if neces
sary. |
| 201 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, !premultiplyA
lpha); | 211 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, !premultiplyA
lpha); |
| 202 | 212 |
| 203 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. | 213 // The canvas is stored in an inverted position, so the flip semantics are r
eversed. |
| 204 context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, !flipY); | 214 context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, !flipY); |
| 205 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, internal
Format, destType); | 215 context->copyTextureCHROMIUM(GL_TEXTURE_2D, sourceTexture, texture, internal
Format, destType); |
| 206 | 216 |
| 207 context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, false); | 217 context->pixelStorei(GC3D_UNPACK_FLIP_Y_CHROMIUM, false); |
| 208 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false); | 218 context->pixelStorei(GC3D_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM, false); |
| 209 | 219 |
| 210 context->deleteTexture(sourceTexture); | 220 context->deleteTexture(sourceTexture); |
| 211 | 221 |
| 212 context->flush(); | 222 context->flush(); |
| 213 sharedContext->waitSyncPoint(context->insertSyncPoint()); | 223 sharedContext->waitSyncPoint(context->insertSyncPoint()); |
| 214 | 224 |
| 215 // Undo grContext texture binding changes introduced in this function | 225 // Undo grContext texture binding changes introduced in this function |
| 216 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 226 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
| 217 | 227 |
| 218 return true; | 228 return true; |
| 219 } | 229 } |
| 220 | 230 |
| 221 Platform3DObject ImageBuffer::getBackingTexture() | |
| 222 { | |
| 223 return m_surface->getBackingTexture(); | |
| 224 } | |
| 225 | |
| 226 void ImageBuffer::didModifyBackingTexture() | |
| 227 { | |
| 228 m_surface->didModifyBackingTexture(); | |
| 229 } | |
| 230 | |
| 231 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) | 231 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) |
| 232 { | 232 { |
| 233 if (!drawingBuffer) | 233 if (!drawingBuffer) |
| 234 return false; | 234 return false; |
| 235 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 235 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); |
| 236 if (!provider) | 236 if (!provider) |
| 237 return false; | 237 return false; |
| 238 WebGraphicsContext3D* context3D = provider->context3d(); | 238 WebGraphicsContext3D* context3D = provider->context3d(); |
| 239 Platform3DObject tex = m_surface->getBackingTexture(); | 239 RefPtr<SkImage> textureImage = m_surface->getBackingTextureImage(); |
| 240 if (!context3D || !tex) | 240 if (!context3D || !textureImage) |
| 241 return false; |
| 242 ASSERT(textureImage->isTextureBacked()); |
| 243 // Get the texture ID, flushing pending operations if needed. |
| 244 Platform3DObject textureId = textureImage->getTextureHandle(true); |
| 245 if (!textureId) |
| 241 return false; | 246 return false; |
| 242 | 247 |
| 243 m_surface->invalidateCachedBitmap(); | 248 m_surface->invalidateCachedBitmap(); |
| 244 bool result = drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA, | 249 bool result = drawingBuffer->copyToPlatformTexture(context3D, textureId, GL_
RGBA, |
| 245 GL_UNSIGNED_BYTE, 0, true, false, sourceBuffer); | 250 GL_UNSIGNED_BYTE, 0, true, false, sourceBuffer); |
| 246 | 251 |
| 247 if (result) { | 252 if (result) { |
| 248 m_surface->didModifyBackingTexture(); | 253 m_surface->didModifyBackingTexture(); |
| 249 } | 254 } |
| 250 | 255 |
| 251 return result; | 256 return result; |
| 252 } | 257 } |
| 253 | 258 |
| 254 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) | 259 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 381 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 377 | 382 |
| 378 Vector<char> encodedImage; | 383 Vector<char> encodedImage; |
| 379 if (!encodeImage(*this, mimeType, quality, &encodedImage)) | 384 if (!encodeImage(*this, mimeType, quality, &encodedImage)) |
| 380 return "data:,"; | 385 return "data:,"; |
| 381 | 386 |
| 382 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); | 387 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); |
| 383 } | 388 } |
| 384 | 389 |
| 385 } // namespace blink | 390 } // namespace blink |
| OLD | NEW |