| 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 DCHECK_GT(global_accelerated_image_buffer_count_, 0u); | 518 DCHECK_GT(global_accelerated_image_buffer_count_, 0u); |
| 519 global_accelerated_image_buffer_count_--; | 519 global_accelerated_image_buffer_count_--; |
| 520 global_gpu_memory_usage_ -= gpu_memory_usage_; | 520 global_gpu_memory_usage_ -= gpu_memory_usage_; |
| 521 gpu_memory_usage_ = 0; | 521 gpu_memory_usage_ = 0; |
| 522 | 522 |
| 523 if (client_) | 523 if (client_) |
| 524 client_->DidDisableAcceleration(); | 524 client_->DidDisableAcceleration(); |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 | 527 |
| 528 namespace { | |
| 529 | |
| 530 class UnacceleratedSurfaceFactory | |
| 531 : public RecordingImageBufferFallbackSurfaceFactory { | |
| 532 public: | |
| 533 virtual std::unique_ptr<ImageBufferSurface> CreateSurface( | |
| 534 const IntSize& size, | |
| 535 OpacityMode opacity_mode, | |
| 536 const CanvasColorParams& color_params) { | |
| 537 return WTF::WrapUnique(new UnacceleratedImageBufferSurface( | |
| 538 size, opacity_mode, kInitializeImagePixels, color_params)); | |
| 539 } | |
| 540 | |
| 541 virtual ~UnacceleratedSurfaceFactory() {} | |
| 542 }; | |
| 543 | |
| 544 } // namespace | |
| 545 | |
| 546 void ImageBuffer::DisableAcceleration() { | 528 void ImageBuffer::DisableAcceleration() { |
| 547 if (!IsAccelerated()) | 529 if (!IsAccelerated()) |
| 548 return; | 530 return; |
| 549 | 531 |
| 550 // Create and configure a recording (unaccelerated) surface. | 532 // Create and configure a recording (unaccelerated) surface. |
| 551 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surface_factory = | |
| 552 WTF::MakeUnique<UnacceleratedSurfaceFactory>(); | |
| 553 std::unique_ptr<ImageBufferSurface> surface = | 533 std::unique_ptr<ImageBufferSurface> surface = |
| 554 WTF::WrapUnique(new RecordingImageBufferSurface( | 534 WTF::WrapUnique(new RecordingImageBufferSurface( |
| 555 surface_->size(), std::move(surface_factory), | 535 surface_->size(), surface_->GetOpacityMode(), |
| 556 surface_->GetOpacityMode(), surface_->color_params())); | 536 surface_->color_params())); |
| 557 SetSurface(std::move(surface)); | 537 SetSurface(std::move(surface)); |
| 558 } | 538 } |
| 559 | 539 |
| 560 void ImageBuffer::SetSurface(std::unique_ptr<ImageBufferSurface> surface) { | 540 void ImageBuffer::SetSurface(std::unique_ptr<ImageBufferSurface> surface) { |
| 561 sk_sp<SkImage> image = | 541 sk_sp<SkImage> image = |
| 562 surface_->NewImageSnapshot(kPreferNoAcceleration, kSnapshotReasonPaint); | 542 surface_->NewImageSnapshot(kPreferNoAcceleration, kSnapshotReasonPaint); |
| 563 | 543 |
| 564 // image can be null if alloaction failed in which case we should just | 544 // image can be null if alloaction failed in which case we should just |
| 565 // abort the surface switch to reatain the old surface which is still | 545 // abort the surface switch to reatain the old surface which is still |
| 566 // functional. | 546 // functional. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); | 597 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); |
| 618 | 598 |
| 619 Vector<unsigned char> result; | 599 Vector<unsigned char> result; |
| 620 if (!EncodeImage(mime_type, quality, &result)) | 600 if (!EncodeImage(mime_type, quality, &result)) |
| 621 return "data:,"; | 601 return "data:,"; |
| 622 | 602 |
| 623 return "data:" + mime_type + ";base64," + Base64Encode(result); | 603 return "data:" + mime_type + ";base64," + Base64Encode(result); |
| 624 } | 604 } |
| 625 | 605 |
| 626 } // namespace blink | 606 } // namespace blink |
| OLD | NEW |