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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "platform/graphics/GraphicsContext.h" | 42 #include "platform/graphics/GraphicsContext.h" |
43 #include "platform/graphics/ImageBufferClient.h" | 43 #include "platform/graphics/ImageBufferClient.h" |
44 #include "platform/graphics/RecordingImageBufferSurface.h" | 44 #include "platform/graphics/RecordingImageBufferSurface.h" |
45 #include "platform/graphics/StaticBitmapImage.h" | 45 #include "platform/graphics/StaticBitmapImage.h" |
46 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 46 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
47 #include "platform/graphics/gpu/DrawingBuffer.h" | 47 #include "platform/graphics/gpu/DrawingBuffer.h" |
48 #include "platform/graphics/gpu/Extensions3DUtil.h" | 48 #include "platform/graphics/gpu/Extensions3DUtil.h" |
49 #include "platform/graphics/paint/PaintImage.h" | 49 #include "platform/graphics/paint/PaintImage.h" |
50 #include "platform/graphics/paint/PaintRecord.h" | 50 #include "platform/graphics/paint/PaintRecord.h" |
51 #include "platform/graphics/skia/SkiaUtils.h" | 51 #include "platform/graphics/skia/SkiaUtils.h" |
52 #include "platform/image-encoders/JPEGImageEncoder.h" | |
53 #include "platform/image-encoders/PNGImageEncoder.h" | 52 #include "platform/image-encoders/PNGImageEncoder.h" |
54 #include "platform/image-encoders/WEBPImageEncoder.h" | 53 #include "platform/image-encoders/WEBPImageEncoder.h" |
55 #include "platform/network/mime/MIMETypeRegistry.h" | 54 #include "platform/network/mime/MIMETypeRegistry.h" |
56 #include "platform/wtf/CheckedNumeric.h" | 55 #include "platform/wtf/CheckedNumeric.h" |
57 #include "platform/wtf/MathExtras.h" | 56 #include "platform/wtf/MathExtras.h" |
58 #include "platform/wtf/PtrUtil.h" | 57 #include "platform/wtf/PtrUtil.h" |
59 #include "platform/wtf/Vector.h" | 58 #include "platform/wtf/Vector.h" |
60 #include "platform/wtf/text/Base64.h" | 59 #include "platform/wtf/text/Base64.h" |
61 #include "platform/wtf/text/WTFString.h" | 60 #include "platform/wtf/text/WTFString.h" |
62 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" | 61 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" |
63 #include "public/platform/Platform.h" | 62 #include "public/platform/Platform.h" |
64 #include "public/platform/WebGraphicsContext3DProvider.h" | 63 #include "public/platform/WebGraphicsContext3DProvider.h" |
65 #include "skia/ext/texture_handle.h" | 64 #include "skia/ext/texture_handle.h" |
66 #include "third_party/skia/include/core/SkSwizzle.h" | 65 #include "third_party/skia/include/core/SkSwizzle.h" |
| 66 #include "third_party/skia/include/encode/SkJpegEncoder.h" |
67 #include "third_party/skia/include/gpu/GrContext.h" | 67 #include "third_party/skia/include/gpu/GrContext.h" |
68 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 68 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
69 | 69 |
70 namespace blink { | 70 namespace blink { |
71 | 71 |
72 std::unique_ptr<ImageBuffer> ImageBuffer::Create( | 72 std::unique_ptr<ImageBuffer> ImageBuffer::Create( |
73 std::unique_ptr<ImageBufferSurface> surface) { | 73 std::unique_ptr<ImageBufferSurface> surface) { |
74 if (!surface->IsValid()) | 74 if (!surface->IsValid()) |
75 return nullptr; | 75 return nullptr; |
76 return WTF::WrapUnique(new ImageBuffer(std::move(surface))); | 76 return WTF::WrapUnique(new ImageBuffer(std::move(surface))); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 537 |
538 void ImageBuffer::SetNeedsCompositingUpdate() { | 538 void ImageBuffer::SetNeedsCompositingUpdate() { |
539 if (client_) | 539 if (client_) |
540 client_->SetNeedsCompositingUpdate(); | 540 client_->SetNeedsCompositingUpdate(); |
541 } | 541 } |
542 | 542 |
543 bool ImageDataBuffer::EncodeImage(const String& mime_type, | 543 bool ImageDataBuffer::EncodeImage(const String& mime_type, |
544 const double& quality, | 544 const double& quality, |
545 Vector<unsigned char>* encoded_image) const { | 545 Vector<unsigned char>* encoded_image) const { |
546 if (mime_type == "image/jpeg") { | 546 if (mime_type == "image/jpeg") { |
547 if (!JPEGImageEncoder::Encode(*this, quality, encoded_image)) | 547 VectorWStream dst(encoded_image); |
548 return false; | 548 |
549 } else if (mime_type == "image/webp") { | 549 SkImageInfo info = |
| 550 SkImageInfo::Make(Width(), Height(), kRGBA_8888_SkColorType, |
| 551 kUnpremul_SkAlphaType, nullptr); |
| 552 size_t rowBytes = |
| 553 Width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); |
| 554 SkPixmap src(info, Pixels(), rowBytes); |
| 555 |
| 556 SkJpegEncoder::Options options; |
| 557 options.fQuality = static_cast<int>(quality * 100 + 0.5); |
| 558 options.fAlphaOption = SkJpegEncoder::AlphaOption::kBlendOnBlack; |
| 559 options.fBlendBehavior = SkTransferFunctionBehavior::kIgnore; |
| 560 return SkJpegEncoder::Encode(&dst, src, options); |
| 561 } |
| 562 |
| 563 if (mime_type == "image/webp") { |
550 int compression_quality = WEBPImageEncoder::kDefaultCompressionQuality; | 564 int compression_quality = WEBPImageEncoder::kDefaultCompressionQuality; |
551 if (quality >= 0.0 && quality <= 1.0) | 565 if (quality >= 0.0 && quality <= 1.0) |
552 compression_quality = static_cast<int>(quality * 100 + 0.5); | 566 compression_quality = static_cast<int>(quality * 100 + 0.5); |
553 if (!WEBPImageEncoder::Encode(*this, compression_quality, encoded_image)) | 567 return WEBPImageEncoder::Encode(*this, compression_quality, encoded_image); |
554 return false; | |
555 } else { | |
556 if (!PNGImageEncoder::Encode(*this, encoded_image)) | |
557 return false; | |
558 DCHECK_EQ(mime_type, "image/png"); | |
559 } | 568 } |
560 | 569 |
561 return true; | 570 DCHECK_EQ(mime_type, "image/png"); |
| 571 return PNGImageEncoder::Encode(*this, encoded_image); |
562 } | 572 } |
563 | 573 |
564 String ImageDataBuffer::ToDataURL(const String& mime_type, | 574 String ImageDataBuffer::ToDataURL(const String& mime_type, |
565 const double& quality) const { | 575 const double& quality) const { |
566 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); | 576 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); |
567 | 577 |
568 Vector<unsigned char> result; | 578 Vector<unsigned char> result; |
569 if (!EncodeImage(mime_type, quality, &result)) | 579 if (!EncodeImage(mime_type, quality, &result)) |
570 return "data:,"; | 580 return "data:,"; |
571 | 581 |
572 return "data:" + mime_type + ";base64," + Base64Encode(result); | 582 return "data:" + mime_type + ";base64," + Base64Encode(result); |
573 } | 583 } |
574 | 584 |
575 } // namespace blink | 585 } // namespace blink |
OLD | NEW |