Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "third_party/skia/include/core/SkStream.h" | 46 #include "third_party/skia/include/core/SkStream.h" |
| 47 #include "wtf/CurrentTime.h" | 47 #include "wtf/CurrentTime.h" |
| 48 #include "wtf/HexNumber.h" | 48 #include "wtf/HexNumber.h" |
| 49 #include "wtf/PtrUtil.h" | 49 #include "wtf/PtrUtil.h" |
| 50 #include "wtf/text/Base64.h" | 50 #include "wtf/text/Base64.h" |
| 51 #include "wtf/text/TextEncoding.h" | 51 #include "wtf/text/TextEncoding.h" |
| 52 #include <memory> | 52 #include <memory> |
| 53 | 53 |
| 54 namespace blink { | 54 namespace blink { |
| 55 | 55 |
| 56 PictureSnapshot::PictureSnapshot(PassRefPtr<const SkPicture> picture) | 56 PictureSnapshot::PictureSnapshot(sk_sp<const SkPicture> picture) |
| 57 : m_picture(picture) | 57 : m_picture(picture) |
|
f(malita)
2016/09/01 03:55:38
std::move(picture)
Łukasz Anforowicz
2016/09/01 20:50:58
Done.
| |
| 58 { | 58 { |
| 59 } | 59 } |
| 60 | 60 |
| 61 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) | 61 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) |
| 62 { | 62 { |
| 63 // No need to copy the data; this decodes immediately. | 63 // No need to copy the data; this decodes immediately. |
| 64 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(SkData ::MakeWithoutCopy(data, length)); | 64 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(SkData ::MakeWithoutCopy(data, length)); |
| 65 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(segmentRea der.release(), true, | 65 std::unique_ptr<ImageDecoder> imageDecoder = ImageDecoder::create(segmentRea der.release(), true, |
| 66 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red); | 66 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgno red); |
| 67 if (!imageDecoder) | 67 if (!imageDecoder) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 84 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()) ; | 84 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()) ; |
| 85 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, decodeBitm ap); | 85 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, decodeBitm ap); |
| 86 if (!picture) | 86 if (!picture) |
| 87 return nullptr; | 87 return nullptr; |
| 88 FloatRect cullRect(picture->cullRect()); | 88 FloatRect cullRect(picture->cullRect()); |
| 89 cullRect.moveBy(tileStream->layerOffset); | 89 cullRect.moveBy(tileStream->layerOffset); |
| 90 unionRect.unite(cullRect); | 90 unionRect.unite(cullRect); |
| 91 pictures.append(std::move(picture)); | 91 pictures.append(std::move(picture)); |
| 92 } | 92 } |
| 93 if (tiles.size() == 1) | 93 if (tiles.size() == 1) |
| 94 return adoptRef(new PictureSnapshot(fromSkSp(std::move(pictures[0])))); | 94 return adoptRef(new PictureSnapshot(std::move(pictures[0]))); |
| 95 SkPictureRecorder recorder; | 95 SkPictureRecorder recorder; |
| 96 SkCanvas* canvas = recorder.beginRecording(unionRect.width(), unionRect.heig ht(), 0, 0); | 96 SkCanvas* canvas = recorder.beginRecording(unionRect.width(), unionRect.heig ht(), 0, 0); |
| 97 for (size_t i = 0; i < pictures.size(); ++i) { | 97 for (size_t i = 0; i < pictures.size(); ++i) { |
| 98 canvas->save(); | 98 canvas->save(); |
| 99 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), tiles[i]->l ayerOffset.y() - unionRect.y()); | 99 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), tiles[i]->l ayerOffset.y() - unionRect.y()); |
| 100 pictures[i]->playback(canvas, 0); | 100 pictures[i]->playback(canvas, 0); |
| 101 canvas->restore(); | 101 canvas->restore(); |
| 102 } | 102 } |
| 103 return adoptRef(new PictureSnapshot(fromSkSp(recorder.finishRecordingAsPictu re()))); | 103 return adoptRef(new PictureSnapshot(recorder.finishRecordingAsPicture())); |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool PictureSnapshot::isEmpty() const | 106 bool PictureSnapshot::isEmpty() const |
| 107 { | 107 { |
| 108 return m_picture->cullRect().isEmpty(); | 108 return m_picture->cullRect().isEmpty(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 std::unique_ptr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigne d toStep, double scale) const | 111 std::unique_ptr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigne d toStep, double scale) const |
| 112 { | 112 { |
| 113 const SkIRect bounds = m_picture->cullRect().roundOut(); | 113 const SkIRect bounds = m_picture->cullRect().roundOut(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 124 SkAutoCanvasRestore autoRestore(&canvas, false); | 124 SkAutoCanvasRestore autoRestore(&canvas, false); |
| 125 canvas.saveLayer(nullptr, nullptr); | 125 canvas.saveLayer(nullptr, nullptr); |
| 126 | 126 |
| 127 canvas.scale(scale, scale); | 127 canvas.scale(scale, scale); |
| 128 canvas.resetStepCount(); | 128 canvas.resetStepCount(); |
| 129 m_picture->playback(&canvas, &canvas); | 129 m_picture->playback(&canvas, &canvas); |
| 130 } | 130 } |
| 131 std::unique_ptr<Vector<char>> base64Data = wrapUnique(new Vector<char>()); | 131 std::unique_ptr<Vector<char>> base64Data = wrapUnique(new Vector<char>()); |
| 132 Vector<char> encodedImage; | 132 Vector<char> encodedImage; |
| 133 | 133 |
| 134 RefPtr<SkImage> image = fromSkSp(SkImage::MakeFromBitmap(bitmap)); | 134 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 135 if (!image) | 135 if (!image) |
| 136 return nullptr; | 136 return nullptr; |
| 137 | 137 |
| 138 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColo rType); | 138 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColo rType); |
| 139 ImageDataBuffer imageData(IntSize(image->width(), image->height()), | 139 ImageDataBuffer imageData(IntSize(image->width(), image->height()), |
| 140 static_cast<const unsigned char*>(pixelLocker.pixels())); | 140 static_cast<const unsigned char*>(pixelLocker.pixels())); |
| 141 if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned cha r>*>(&encodedImage))) | 141 if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned cha r>*>(&encodedImage))) |
| 142 return nullptr; | 142 return nullptr; |
| 143 | 143 |
| 144 base64Encode(encodedImage, *base64Data); | 144 base64Encode(encodedImage, *base64Data); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 175 | 175 |
| 176 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const | 176 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const |
| 177 { | 177 { |
| 178 const SkIRect bounds = m_picture->cullRect().roundOut(); | 178 const SkIRect bounds = m_picture->cullRect().roundOut(); |
| 179 LoggingCanvas canvas(bounds.width(), bounds.height()); | 179 LoggingCanvas canvas(bounds.width(), bounds.height()); |
| 180 m_picture->playback(&canvas); | 180 m_picture->playback(&canvas); |
| 181 return canvas.log(); | 181 return canvas.log(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace blink | 184 } // namespace blink |
| OLD | NEW |