| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 ImageBuffer::~ImageBuffer() | 89 ImageBuffer::~ImageBuffer() |
| 90 { | 90 { |
| 91 ImageBuffer::s_globalGPUMemoryUsage -= m_gpuMemoryUsage; | 91 ImageBuffer::s_globalGPUMemoryUsage -= m_gpuMemoryUsage; |
| 92 } | 92 } |
| 93 | 93 |
| 94 SkCanvas* ImageBuffer::canvas() const | 94 SkCanvas* ImageBuffer::canvas() const |
| 95 { | 95 { |
| 96 return m_surface->canvas(); | 96 return m_surface->canvas(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ImageBuffer::disableDeferral() const | 99 void ImageBuffer::disableDeferral(DisableDeferralReason reason) const |
| 100 { | 100 { |
| 101 return m_surface->disableDeferral(); | 101 return m_surface->disableDeferral(reason); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool ImageBuffer::writePixels(const SkImageInfo& info, const void* pixels, size_
t rowBytes, int x, int y) | 104 bool ImageBuffer::writePixels(const SkImageInfo& info, const void* pixels, size_
t rowBytes, int x, int y) |
| 105 { | 105 { |
| 106 return m_surface->writePixels(info, pixels, rowBytes, x, y); | 106 return m_surface->writePixels(info, pixels, rowBytes, x, y); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool ImageBuffer::isSurfaceValid() const | 109 bool ImageBuffer::isSurfaceValid() const |
| 110 { | 110 { |
| 111 return m_surface->isValid(); | 111 return m_surface->isValid(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 138 if (m_client) | 138 if (m_client) |
| 139 m_client->notifySurfaceInvalid(); | 139 m_client->notifySurfaceInvalid(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ImageBuffer::resetCanvas(SkCanvas* canvas) const | 142 void ImageBuffer::resetCanvas(SkCanvas* canvas) const |
| 143 { | 143 { |
| 144 if (m_client) | 144 if (m_client) |
| 145 m_client->restoreCanvasMatrixClipStack(canvas); | 145 m_client->restoreCanvasMatrixClipStack(canvas); |
| 146 } | 146 } |
| 147 | 147 |
| 148 PassRefPtr<SkImage> ImageBuffer::newSkImageSnapshot(AccelerationHint hint) const | 148 PassRefPtr<SkImage> ImageBuffer::newSkImageSnapshot(AccelerationHint hint, Snaps
hotReason reason) const |
| 149 { | 149 { |
| 150 if (m_snapshotState == InitialSnapshotState) | 150 if (m_snapshotState == InitialSnapshotState) |
| 151 m_snapshotState = DidAcquireSnapshot; | 151 m_snapshotState = DidAcquireSnapshot; |
| 152 | 152 |
| 153 if (!isSurfaceValid()) | 153 if (!isSurfaceValid()) |
| 154 return nullptr; | 154 return nullptr; |
| 155 return m_surface->newImageSnapshot(hint); | 155 return m_surface->newImageSnapshot(hint, reason); |
| 156 } | 156 } |
| 157 | 157 |
| 158 PassRefPtr<Image> ImageBuffer::newImageSnapshot(AccelerationHint hint) const | 158 PassRefPtr<Image> ImageBuffer::newImageSnapshot(AccelerationHint hint, SnapshotR
eason reason) const |
| 159 { | 159 { |
| 160 RefPtr<SkImage> snapshot = newSkImageSnapshot(hint); | 160 RefPtr<SkImage> snapshot = newSkImageSnapshot(hint, reason); |
| 161 if (!snapshot) | 161 if (!snapshot) |
| 162 return nullptr; | 162 return nullptr; |
| 163 return StaticBitmapImage::create(snapshot); | 163 return StaticBitmapImage::create(snapshot); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void ImageBuffer::didDraw(const FloatRect& rect) const | 166 void ImageBuffer::didDraw(const FloatRect& rect) const |
| 167 { | 167 { |
| 168 if (m_snapshotState == DidAcquireSnapshot) | 168 if (m_snapshotState == DidAcquireSnapshot) |
| 169 m_snapshotState = DrawnToAfterSnapshot; | 169 m_snapshotState = DrawnToAfterSnapshot; |
| 170 m_surface->didDraw(rect); | 170 m_surface->didDraw(rect); |
| 171 } | 171 } |
| 172 | 172 |
| 173 WebLayer* ImageBuffer::platformLayer() const | 173 WebLayer* ImageBuffer::platformLayer() const |
| 174 { | 174 { |
| 175 return m_surface->layer(); | 175 return m_surface->layer(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) | 178 bool ImageBuffer::copyToPlatformTexture(WebGraphicsContext3D* context, Platform3
DObject texture, GLenum internalFormat, GLenum destType, GLint level, bool premu
ltiplyAlpha, bool flipY) |
| 179 { | 179 { |
| 180 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) | 180 if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(GL_TEXTURE_2D, internalForm
at, destType, level)) |
| 181 return false; | 181 return false; |
| 182 | 182 |
| 183 if (!isSurfaceValid()) | 183 if (!isSurfaceValid()) |
| 184 return false; | 184 return false; |
| 185 | 185 |
| 186 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration); | 186 RefPtr<const SkImage> textureImage = m_surface->newImageSnapshot(PreferAccel
eration, SnapshotReasonCopyToWebGLTexture); |
| 187 if (!textureImage) | 187 if (!textureImage) |
| 188 return false; | 188 return false; |
| 189 | 189 |
| 190 if (!m_surface->isAccelerated()) | 190 if (!m_surface->isAccelerated()) |
| 191 return false; | 191 return false; |
| 192 | 192 |
| 193 | 193 |
| 194 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this | 194 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this |
| 195 // Get the texture ID, flushing pending operations if needed. | 195 // Get the texture ID, flushing pending operations if needed. |
| 196 Platform3DObject textureId = textureImage->getTextureHandle(true); | 196 Platform3DObject textureId = textureImage->getTextureHandle(true); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 260 |
| 261 void ImageBuffer::draw(GraphicsContext& context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) | 261 void ImageBuffer::draw(GraphicsContext& context, const FloatRect& destRect, cons
t FloatRect* srcPtr, SkXfermode::Mode op) |
| 262 { | 262 { |
| 263 if (!isSurfaceValid()) | 263 if (!isSurfaceValid()) |
| 264 return; | 264 return; |
| 265 | 265 |
| 266 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), FloatSize(siz
e())); | 266 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), FloatSize(siz
e())); |
| 267 m_surface->draw(context, destRect, srcRect, op); | 267 m_surface->draw(context, destRect, srcRect, op); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void ImageBuffer::flush() | 270 void ImageBuffer::flush(FlushReason reason) |
| 271 { | 271 { |
| 272 if (m_surface->canvas()) { | 272 if (m_surface->canvas()) { |
| 273 m_surface->flush(); | 273 m_surface->flush(reason); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 void ImageBuffer::flushGpu() | 277 void ImageBuffer::flushGpu(FlushReason reason) |
| 278 { | 278 { |
| 279 if (m_surface->canvas()) { | 279 if (m_surface->canvas()) { |
| 280 m_surface->flushGpu(); | 280 m_surface->flushGpu(reason); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const | 284 bool ImageBuffer::getImageData(Multiply multiplied, const IntRect& rect, WTF::Ar
rayBufferContents& contents) const |
| 285 { | 285 { |
| 286 Checked<int, RecordOverflow> dataSize = 4; | 286 Checked<int, RecordOverflow> dataSize = 4; |
| 287 dataSize *= rect.width(); | 287 dataSize *= rect.width(); |
| 288 dataSize *= rect.height(); | 288 dataSize *= rect.height(); |
| 289 if (dataSize.hasOverflowed()) | 289 if (dataSize.hasOverflowed()) |
| 290 return false; | 290 return false; |
| 291 | 291 |
| 292 if (!isSurfaceValid()) { | 292 if (!isSurfaceValid()) { |
| 293 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); | 293 WTF::ArrayBufferContents result(rect.width() * rect.height(), 4, WTF::Ar
rayBufferContents::NotShared, WTF::ArrayBufferContents::ZeroInitialize); |
| 294 result.transfer(contents); | 294 result.transfer(contents); |
| 295 return true; | 295 return true; |
| 296 } | 296 } |
| 297 | 297 |
| 298 ASSERT(canvas()); | 298 ASSERT(canvas()); |
| 299 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration)
; | 299 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration,
SnapshotReasonGetImageData); |
| 300 if (!snapshot) | 300 if (!snapshot) |
| 301 return false; | 301 return false; |
| 302 | 302 |
| 303 const bool mayHaveStrayArea = | 303 const bool mayHaveStrayArea = |
| 304 m_surface->isAccelerated() // GPU readback may fail silently | 304 m_surface->isAccelerated() // GPU readback may fail silently |
| 305 || rect.x() < 0 | 305 || rect.x() < 0 |
| 306 || rect.y() < 0 | 306 || rect.y() < 0 |
| 307 || rect.maxX() > m_surface->size().width() | 307 || rect.maxX() > m_surface->size().width() |
| 308 || rect.maxY() > m_surface->size().height(); | 308 || rect.maxY() > m_surface->size().height(); |
| 309 WTF::ArrayBufferContents result( | 309 WTF::ArrayBufferContents result( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 400 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 401 | 401 |
| 402 Vector<unsigned char> result; | 402 Vector<unsigned char> result; |
| 403 if (!encodeImage(mimeType, quality, &result)) | 403 if (!encodeImage(mimeType, quality, &result)) |
| 404 return "data:,"; | 404 return "data:,"; |
| 405 | 405 |
| 406 return "data:" + mimeType + ";base64," + base64Encode(result); | 406 return "data:" + mimeType + ";base64," + base64Encode(result); |
| 407 } | 407 } |
| 408 | 408 |
| 409 } // namespace blink | 409 } // namespace blink |
| OLD | NEW |