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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } else if (m_gpuMemoryUsage) { | 488 } else if (m_gpuMemoryUsage) { |
489 // In case of switching from accelerated to non-accelerated mode, | 489 // In case of switching from accelerated to non-accelerated mode, |
490 // the GPU memory usage needs to be updated too. | 490 // the GPU memory usage needs to be updated too. |
491 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u); | 491 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u); |
492 s_globalAcceleratedImageBufferCount--; | 492 s_globalAcceleratedImageBufferCount--; |
493 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; | 493 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; |
494 m_gpuMemoryUsage = 0; | 494 m_gpuMemoryUsage = 0; |
495 } | 495 } |
496 } | 496 } |
497 | 497 |
| 498 namespace { |
| 499 |
498 class UnacceleratedSurfaceFactory | 500 class UnacceleratedSurfaceFactory |
499 : public RecordingImageBufferFallbackSurfaceFactory { | 501 : public RecordingImageBufferFallbackSurfaceFactory { |
500 public: | 502 public: |
501 virtual std::unique_ptr<ImageBufferSurface> createSurface( | 503 virtual std::unique_ptr<ImageBufferSurface> createSurface( |
502 const IntSize& size, | 504 const IntSize& size, |
503 OpacityMode opacityMode, | 505 OpacityMode opacityMode, |
504 sk_sp<SkColorSpace> colorSpace, | 506 sk_sp<SkColorSpace> colorSpace, |
505 SkColorType colorType) { | 507 SkColorType colorType) { |
506 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( | 508 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( |
507 size, opacityMode, InitializeImagePixels, std::move(colorSpace), | 509 size, opacityMode, InitializeImagePixels, std::move(colorSpace), |
508 colorType)); | 510 colorType)); |
509 } | 511 } |
510 | 512 |
511 virtual ~UnacceleratedSurfaceFactory() {} | 513 virtual ~UnacceleratedSurfaceFactory() {} |
512 }; | 514 }; |
513 | 515 |
| 516 } // namespace |
| 517 |
514 void ImageBuffer::disableAcceleration() { | 518 void ImageBuffer::disableAcceleration() { |
515 if (!isAccelerated()) | 519 if (!isAccelerated()) |
516 return; | 520 return; |
517 | 521 |
518 sk_sp<SkImage> image = | 522 sk_sp<SkImage> image = |
519 m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonPaint); | 523 m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonPaint); |
520 // Using a GPU-backed image with RecordingImageBufferSurface | 524 // Using a GPU-backed image with RecordingImageBufferSurface |
521 // will fail at playback time. | 525 // will fail at playback time. |
522 image = image->makeNonTextureImage(); | 526 image = image->makeNonTextureImage(); |
523 | 527 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 567 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
564 | 568 |
565 Vector<unsigned char> result; | 569 Vector<unsigned char> result; |
566 if (!encodeImage(mimeType, quality, &result)) | 570 if (!encodeImage(mimeType, quality, &result)) |
567 return "data:,"; | 571 return "data:,"; |
568 | 572 |
569 return "data:" + mimeType + ";base64," + base64Encode(result); | 573 return "data:" + mimeType + ";base64," + base64Encode(result); |
570 } | 574 } |
571 | 575 |
572 } // namespace blink | 576 } // namespace blink |
OLD | NEW |