| 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 431 } |
| 432 | 432 |
| 433 virtual ~UnacceleratedSurfaceFactory() { } | 433 virtual ~UnacceleratedSurfaceFactory() { } |
| 434 }; | 434 }; |
| 435 | 435 |
| 436 void ImageBuffer::disableAcceleration() | 436 void ImageBuffer::disableAcceleration() |
| 437 { | 437 { |
| 438 if (!isAccelerated()) | 438 if (!isAccelerated()) |
| 439 return; | 439 return; |
| 440 | 440 |
| 441 // Get current frame. | 441 sk_sp<SkImage> image = m_surface->newImageSnapshot(PreferNoAcceleration, Sna
pshotReasonPaint); |
| 442 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR
easonPaint).get(); | 442 // Using a GPU-backed image with RecordingImageBufferSurface |
| 443 // will fail at playback time. |
| 444 image = image->makeNonTextureImage(); |
| 443 | 445 |
| 444 // Create and configure a recording (unaccelerated) surface. | 446 // Create and configure a recording (unaccelerated) surface. |
| 445 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory =
wrapUnique(new UnacceleratedSurfaceFactory()); | 447 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory =
wrapUnique(new UnacceleratedSurfaceFactory()); |
| 446 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB
ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity
Mode(), m_surface->colorSpace())); | 448 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB
ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity
Mode(), m_surface->colorSpace())); |
| 447 surface->canvas()->drawImage(image, 0, 0); | 449 surface->canvas()->drawImage(image.get(), 0, 0); |
| 448 surface->setImageBuffer(this); | 450 surface->setImageBuffer(this); |
| 449 | 451 if (m_client) |
| 450 // Replace the current surface with the new surface. | 452 m_client->restoreCanvasMatrixClipStack(surface->canvas()); |
| 451 m_surface = std::move(surface); | 453 m_surface = std::move(surface); |
| 452 | 454 |
| 453 didDisableAcceleration(); | 455 didDisableAcceleration(); |
| 454 } | 456 } |
| 455 | 457 |
| 456 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality,
Vector<unsigned char>* encodedImage) const | 458 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality,
Vector<unsigned char>* encodedImage) const |
| 457 { | 459 { |
| 458 if (mimeType == "image/jpeg") { | 460 if (mimeType == "image/jpeg") { |
| 459 if (!JPEGImageEncoder::encode(*this, quality, encodedImage)) | 461 if (!JPEGImageEncoder::encode(*this, quality, encodedImage)) |
| 460 return false; | 462 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 478 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 480 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 479 | 481 |
| 480 Vector<unsigned char> result; | 482 Vector<unsigned char> result; |
| 481 if (!encodeImage(mimeType, quality, &result)) | 483 if (!encodeImage(mimeType, quality, &result)) |
| 482 return "data:,"; | 484 return "data:,"; |
| 483 | 485 |
| 484 return "data:" + mimeType + ";base64," + base64Encode(result); | 486 return "data:" + mimeType + ";base64," + base64Encode(result); |
| 485 } | 487 } |
| 486 | 488 |
| 487 } // namespace blink | 489 } // namespace blink |
| OLD | NEW |