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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 FloatRect unionRect; | 89 FloatRect unionRect; |
90 for (const auto& tileStream : tiles) { | 90 for (const auto& tileStream : tiles) { |
91 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()); | 91 SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size()); |
92 SkiaImageDecoder factory; | 92 SkiaImageDecoder factory; |
93 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, &factory); | 93 sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, &factory); |
94 if (!picture) | 94 if (!picture) |
95 return nullptr; | 95 return nullptr; |
96 FloatRect cullRect(picture->cullRect()); | 96 FloatRect cullRect(picture->cullRect()); |
97 cullRect.moveBy(tileStream->layerOffset); | 97 cullRect.moveBy(tileStream->layerOffset); |
98 unionRect.unite(cullRect); | 98 unionRect.unite(cullRect); |
99 pictures.append(std::move(picture)); | 99 pictures.push_back(std::move(picture)); |
100 } | 100 } |
101 if (tiles.size() == 1) | 101 if (tiles.size() == 1) |
102 return adoptRef(new PictureSnapshot(std::move(pictures[0]))); | 102 return adoptRef(new PictureSnapshot(std::move(pictures[0]))); |
103 SkPictureRecorder recorder; | 103 SkPictureRecorder recorder; |
104 SkCanvas* canvas = | 104 SkCanvas* canvas = |
105 recorder.beginRecording(unionRect.width(), unionRect.height(), 0, 0); | 105 recorder.beginRecording(unionRect.width(), unionRect.height(), 0, 0); |
106 for (size_t i = 0; i < pictures.size(); ++i) { | 106 for (size_t i = 0; i < pictures.size(); ++i) { |
107 canvas->save(); | 107 canvas->save(); |
108 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), | 108 canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), |
109 tiles[i]->layerOffset.y() - unionRect.y()); | 109 tiles[i]->layerOffset.y() - unionRect.y()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 timings->reserveCapacity(minRepeatCount); | 171 timings->reserveCapacity(minRepeatCount); |
172 const SkIRect bounds = m_picture->cullRect().roundOut(); | 172 const SkIRect bounds = m_picture->cullRect().roundOut(); |
173 SkBitmap bitmap; | 173 SkBitmap bitmap; |
174 bitmap.allocPixels( | 174 bitmap.allocPixels( |
175 SkImageInfo::MakeN32Premul(bounds.width(), bounds.height())); | 175 SkImageInfo::MakeN32Premul(bounds.width(), bounds.height())); |
176 bitmap.eraseARGB(0, 0, 0, 0); | 176 bitmap.eraseARGB(0, 0, 0, 0); |
177 | 177 |
178 double now = WTF::monotonicallyIncreasingTime(); | 178 double now = WTF::monotonicallyIncreasingTime(); |
179 double stopTime = now + minDuration; | 179 double stopTime = now + minDuration; |
180 for (unsigned step = 0; step < minRepeatCount || now < stopTime; ++step) { | 180 for (unsigned step = 0; step < minRepeatCount || now < stopTime; ++step) { |
181 timings->append(Vector<double>()); | 181 timings->push_back(Vector<double>()); |
182 Vector<double>* currentTimings = &timings->back(); | 182 Vector<double>* currentTimings = &timings->back(); |
183 if (timings->size() > 1) | 183 if (timings->size() > 1) |
184 currentTimings->reserveCapacity(timings->begin()->size()); | 184 currentTimings->reserveCapacity(timings->begin()->size()); |
185 ProfilingCanvas canvas(bitmap); | 185 ProfilingCanvas canvas(bitmap); |
186 if (clipRect) { | 186 if (clipRect) { |
187 canvas.clipRect(SkRect::MakeXYWH(clipRect->x(), clipRect->y(), | 187 canvas.clipRect(SkRect::MakeXYWH(clipRect->x(), clipRect->y(), |
188 clipRect->width(), clipRect->height())); | 188 clipRect->width(), clipRect->height())); |
189 canvas.resetStepCount(); | 189 canvas.resetStepCount(); |
190 } | 190 } |
191 canvas.setTimings(currentTimings); | 191 canvas.setTimings(currentTimings); |
192 m_picture->playback(&canvas); | 192 m_picture->playback(&canvas); |
193 now = WTF::monotonicallyIncreasingTime(); | 193 now = WTF::monotonicallyIncreasingTime(); |
194 } | 194 } |
195 return timings; | 195 return timings; |
196 } | 196 } |
197 | 197 |
198 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const { | 198 std::unique_ptr<JSONArray> PictureSnapshot::snapshotCommandLog() const { |
199 const SkIRect bounds = m_picture->cullRect().roundOut(); | 199 const SkIRect bounds = m_picture->cullRect().roundOut(); |
200 LoggingCanvas canvas(bounds.width(), bounds.height()); | 200 LoggingCanvas canvas(bounds.width(), bounds.height()); |
201 m_picture->playback(&canvas); | 201 m_picture->playback(&canvas); |
202 return canvas.log(); | 202 return canvas.log(); |
203 } | 203 } |
204 | 204 |
205 } // namespace blink | 205 } // namespace blink |
OLD | NEW |