| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (m_client) | 141 if (m_client) |
| 142 m_client->notifySurfaceInvalid(); | 142 m_client->notifySurfaceInvalid(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void ImageBuffer::resetCanvas(SkCanvas* canvas) const | 145 void ImageBuffer::resetCanvas(SkCanvas* canvas) const |
| 146 { | 146 { |
| 147 if (m_client) | 147 if (m_client) |
| 148 m_client->restoreCanvasMatrixClipStack(canvas); | 148 m_client->restoreCanvasMatrixClipStack(canvas); |
| 149 } | 149 } |
| 150 | 150 |
| 151 PassRefPtr<SkImage> ImageBuffer::newSkImageSnapshot(AccelerationHint hint) const | 151 PassRefPtr<SkImage> ImageBuffer::newSkImageSnapshot() const |
| 152 { | 152 { |
| 153 if (m_snapshotState == InitialSnapshotState) | 153 if (m_snapshotState == InitialSnapshotState) |
| 154 m_snapshotState = DidAcquireSnapshot; | 154 m_snapshotState = DidAcquireSnapshot; |
| 155 | 155 |
| 156 if (!isSurfaceValid()) | 156 if (!isSurfaceValid()) |
| 157 return nullptr; | 157 return nullptr; |
| 158 return m_surface->newImageSnapshot(hint); | 158 return m_surface->newImageSnapshot(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 PassRefPtr<Image> ImageBuffer::newImageSnapshot(AccelerationHint hint) const | 161 PassRefPtr<Image> ImageBuffer::newImageSnapshot() const |
| 162 { | 162 { |
| 163 RefPtr<SkImage> snapshot = newSkImageSnapshot(hint); | 163 RefPtr<SkImage> snapshot = newSkImageSnapshot(); |
| 164 if (!snapshot) | 164 if (!snapshot) |
| 165 return nullptr; | 165 return nullptr; |
| 166 return StaticBitmapImage::create(snapshot); | 166 return StaticBitmapImage::create(snapshot); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void ImageBuffer::didDraw(const FloatRect& rect) const | 169 void ImageBuffer::didDraw(const FloatRect& rect) const |
| 170 { | 170 { |
| 171 if (m_snapshotState == DidAcquireSnapshot) | 171 if (m_snapshotState == DidAcquireSnapshot) |
| 172 m_snapshotState = DrawnToAfterSnapshot; | 172 m_snapshotState = DrawnToAfterSnapshot; |
| 173 m_surface->didDraw(rect); | 173 m_surface->didDraw(rect); |
| 174 } | 174 } |
| 175 | 175 |
| 176 WebLayer* ImageBuffer::platformLayer() const | 176 WebLayer* ImageBuffer::platformLayer() const |
| 177 { | 177 { |
| 178 return m_surface->layer(); | 178 return m_surface->layer(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) | 181 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) |
| 182 { | 182 { |
| 183 if (!m_surface->isAccelerated() || !isSurfaceValid()) |
| 184 return false; |
| 185 |
| 183 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) | 186 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) |
| 184 return false; | 187 return false; |
| 185 | 188 |
| 186 if (!isSurfaceValid()) | 189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(); |
| 187 return false; | |
| 188 | |
| 189 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration); | |
| 190 if (!textureImage) | 190 if (!textureImage) |
| 191 return false; | 191 return false; |
| 192 | 192 |
| 193 if (!m_surface->isAccelerated()) | |
| 194 return false; | |
| 195 | |
| 196 | |
| 197 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this | 193 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this |
| 198 // Get the texture ID, flushing pending operations if needed. | 194 // Get the texture ID, flushing pending operations if needed. |
| 199 Platform3DObject textureId = textureImage->getTextureHandle(true); | 195 Platform3DObject textureId = textureImage->getTextureHandle(true); |
| 200 if (!textureId) | 196 if (!textureId) |
| 201 return false; | 197 return false; |
| 202 | 198 |
| 203 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 199 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); |
| 204 if (!provider) | 200 if (!provider) |
| 205 return false; | 201 return false; |
| 206 WebGraphicsContext3D* sharedContext = provider->context3d(); | 202 WebGraphicsContext3D* sharedContext = provider->context3d(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 dataSize *= rect.height(); | 280 dataSize *= rect.height(); |
| 285 if (dataSize.hasOverflowed()) | 281 if (dataSize.hasOverflowed()) |
| 286 return false; | 282 return false; |
| 287 | 283 |
| 288 if (!isSurfaceValid()) { | 284 if (!isSurfaceValid()) { |
| 289 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); | 285 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); |
| 290 result.transfer(contents); | 286 result.transfer(contents); |
| 291 return true; | 287 return true; |
| 292 } | 288 } |
| 293 | 289 |
| 294 ASSERT(canvas()); | |
| 295 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration)
; | |
| 296 if (!snapshot) | |
| 297 return false; | |
| 298 | |
| 299 const bool mayHaveStrayArea = | 290 const bool mayHaveStrayArea = |
| 300 m_surface->isAccelerated() // GPU readback may fail silently | 291 m_surface->isAccelerated() // GPU readback may fail silently |
| 301 || rect.x() < 0 | 292 || rect.x() < 0 |
| 302 || rect.y() < 0 | 293 || rect.y() < 0 |
| 303 || rect.maxX() > m_surface->size().width() | 294 || rect.maxX() > m_surface->size().width() |
| 304 || rect.maxY() > m_surface->size().height(); | 295 || rect.maxY() > m_surface->size().height(); |
| 305 WTF::ArrayBufferContents result( | 296 WTF::ArrayBufferContents result( |
| 306 rect.width() * rect.height(), 4, | 297 rect.width() * rect.height(), 4, |
| 307 WTF::ArrayBufferContents::NotShared, | 298 WTF::ArrayBufferContents::NotShared, |
| 308 mayHaveStrayArea | 299 mayHaveStrayArea |
| 309 ? WTF::ArrayBufferContents::ZeroInitialize | 300 ? WTF::ArrayBufferContents::ZeroInitialize |
| 310 : WTF::ArrayBufferContents::DontInitialize); | 301 : WTF::ArrayBufferContents::DontInitialize); |
| 311 | 302 |
| 312 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; | 303 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType
: kUnpremul_SkAlphaType; |
| 313 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); | 304 SkImageInfo info = SkImageInfo::Make(rect.width(), rect.height(), kRGBA_8888
_SkColorType, alphaType); |
| 314 | 305 |
| 306 ASSERT(canvas()); |
| 307 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(); |
| 308 if (!snapshot) |
| 309 return false; |
| 315 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y
()); | 310 snapshot->readPixels(info, result.data(), 4 * rect.width(), rect.x(), rect.y
()); |
| 316 result.transfer(contents); | 311 result.transfer(contents); |
| 317 return true; | 312 return true; |
| 318 } | 313 } |
| 319 | 314 |
| 320 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint
) | 315 void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint
) |
| 321 { | 316 { |
| 322 if (!isSurfaceValid()) | 317 if (!isSurfaceValid()) |
| 323 return; | 318 return; |
| 324 | 319 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 377 | 372 |
| 378 Vector<char> encodedImage; | 373 Vector<char> encodedImage; |
| 379 if (!encodeImage(mimeType, quality, &encodedImage)) | 374 if (!encodeImage(mimeType, quality, &encodedImage)) |
| 380 return "data:,"; | 375 return "data:,"; |
| 381 | 376 |
| 382 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); | 377 return "data:" + mimeType + ";base64," + base64Encode(encodedImage); |
| 383 } | 378 } |
| 384 | 379 |
| 385 } // namespace blink | 380 } // namespace blink |
| OLD | NEW |