| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); | 64 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); |
| 65 if (!frame) | 65 if (!frame) |
| 66 return true; | 66 return true; |
| 67 *result = frame->getSkBitmap(); | 67 *result = frame->getSkBitmap(); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur
eStream>>& tiles) | 71 PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictur
eStream>>& tiles) |
| 72 { | 72 { |
| 73 ASSERT(!tiles.isEmpty()); | 73 ASSERT(!tiles.isEmpty()); |
| 74 Vector<RefPtr<SkPicture>> pictures; | 74 Vector<sk_sp<SkPicture>> pictures; |
| 75 pictures.reserveCapacity(tiles.size()); | 75 pictures.reserveCapacity(tiles.size()); |
| 76 FloatRect unionRect; | 76 FloatRect unionRect; |
| 77 for (const auto& tileStream : tiles) { | 77 for (const auto& tileStream : tiles) { |
| 78 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size())
; | 78 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size())
; |
| 79 RefPtr<SkPicture> picture = adoptRef(SkPicture::CreateFromStream(&stream
, decodeBitmap)); | 79 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, decodeBitm
ap); |
| 80 if (!picture) | 80 if (!picture) |
| 81 return nullptr; | 81 return nullptr; |
| 82 FloatRect cullRect(picture->cullRect()); | 82 FloatRect cullRect(picture->cullRect()); |
| 83 cullRect.moveBy(tileStream->layerOffset); | 83 cullRect.moveBy(tileStream->layerOffset); |
| 84 unionRect.unite(cullRect); | 84 unionRect.unite(cullRect); |
| 85 pictures.append(picture); | 85 pictures.append(std::move(picture)); |
| 86 } | 86 } |
| 87 if (tiles.size() == 1) | 87 if (tiles.size() == 1) |
| 88 return adoptRef(new PictureSnapshot(pictures[0])); | 88 return adoptRef(new PictureSnapshot(fromSkSp(std::move(pictures[0])))); |
| 89 SkPictureRecorder recorder; | 89 SkPictureRecorder recorder; |
| 90 SkCanvas* canvas = recorder.beginRecording(unionRect.width(), unionRect.heig
ht(), 0, 0); | 90 SkCanvas* canvas = recorder.beginRecording(unionRect.width(), unionRect.heig
ht(), 0, 0); |
| 91 for (size_t i = 0; i < pictures.size(); ++i) { | 91 for (size_t i = 0; i < pictures.size(); ++i) { |
| 92 canvas->save(); | 92 canvas->save(); |
| 93 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), tiles[i]->l
ayerOffset.y() - unionRect.y()); | 93 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), tiles[i]->l
ayerOffset.y() - unionRect.y()); |
| 94 pictures[i]->playback(canvas, 0); | 94 pictures[i]->playback(canvas, 0); |
| 95 canvas->restore(); | 95 canvas->restore(); |
| 96 } | 96 } |
| 97 return adoptRef(new PictureSnapshot(adoptRef(recorder.endRecordingAsPicture(
)))); | 97 return adoptRef(new PictureSnapshot(fromSkSp(recorder.finishRecordingAsPictu
re()))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool PictureSnapshot::isEmpty() const | 100 bool PictureSnapshot::isEmpty() const |
| 101 { | 101 { |
| 102 return m_picture->cullRect().isEmpty(); | 102 return m_picture->cullRect().isEmpty(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 PassOwnPtr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigned toS
tep, double scale) const | 105 PassOwnPtr<Vector<char>> PictureSnapshot::replay(unsigned fromStep, unsigned toS
tep, double scale) const |
| 106 { | 106 { |
| 107 const SkIRect bounds = m_picture->cullRect().roundOut(); | 107 const SkIRect bounds = m_picture->cullRect().roundOut(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const | 170 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const |
| 171 { | 171 { |
| 172 const SkIRect bounds = m_picture->cullRect().roundOut(); | 172 const SkIRect bounds = m_picture->cullRect().roundOut(); |
| 173 LoggingCanvas canvas(bounds.width(), bounds.height()); | 173 LoggingCanvas canvas(bounds.width(), bounds.height()); |
| 174 m_picture->playback(&canvas); | 174 m_picture->playback(&canvas); |
| 175 return canvas.log(); | 175 return canvas.log(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace blink | 178 } // namespace blink |
| OLD | NEW |