| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (!image) | 134 if (!image) |
| 135 return nullptr; | 135 return nullptr; |
| 136 | 136 |
| 137 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColo
rType); | 137 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, kRGBA_8888_SkColo
rType); |
| 138 ImageDataBuffer imageData(IntSize(image->width(), image->height()), | 138 ImageDataBuffer imageData(IntSize(image->width(), image->height()), |
| 139 static_cast<const unsigned char*>(pixelLocker.pixels())); | 139 static_cast<const unsigned char*>(pixelLocker.pixels())); |
| 140 if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned cha
r>*>(&encodedImage))) | 140 if (!PNGImageEncoder::encode(imageData, reinterpret_cast<Vector<unsigned cha
r>*>(&encodedImage))) |
| 141 return nullptr; | 141 return nullptr; |
| 142 | 142 |
| 143 base64Encode(encodedImage, *base64Data); | 143 base64Encode(encodedImage, *base64Data); |
| 144 return base64Data.release(); | 144 return base64Data; |
| 145 } | 145 } |
| 146 | 146 |
| 147 PassOwnPtr<PictureSnapshot::Timings> PictureSnapshot::profile(unsigned minRepeat
Count, double minDuration, const FloatRect* clipRect) const | 147 PassOwnPtr<PictureSnapshot::Timings> PictureSnapshot::profile(unsigned minRepeat
Count, double minDuration, const FloatRect* clipRect) const |
| 148 { | 148 { |
| 149 OwnPtr<PictureSnapshot::Timings> timings = adoptPtr(new PictureSnapshot::Tim
ings()); | 149 OwnPtr<PictureSnapshot::Timings> timings = adoptPtr(new PictureSnapshot::Tim
ings()); |
| 150 timings->reserveCapacity(minRepeatCount); | 150 timings->reserveCapacity(minRepeatCount); |
| 151 const SkIRect bounds = m_picture->cullRect().roundOut(); | 151 const SkIRect bounds = m_picture->cullRect().roundOut(); |
| 152 SkBitmap bitmap; | 152 SkBitmap bitmap; |
| 153 bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height(
))); | 153 bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounds.width(), bounds.height(
))); |
| 154 bitmap.eraseARGB(0, 0, 0, 0); | 154 bitmap.eraseARGB(0, 0, 0, 0); |
| 155 | 155 |
| 156 double now = WTF::monotonicallyIncreasingTime(); | 156 double now = WTF::monotonicallyIncreasingTime(); |
| 157 double stopTime = now + minDuration; | 157 double stopTime = now + minDuration; |
| 158 for (unsigned step = 0; step < minRepeatCount || now < stopTime; ++step) { | 158 for (unsigned step = 0; step < minRepeatCount || now < stopTime; ++step) { |
| 159 timings->append(Vector<double>()); | 159 timings->append(Vector<double>()); |
| 160 Vector<double>* currentTimings = &timings->last(); | 160 Vector<double>* currentTimings = &timings->last(); |
| 161 if (timings->size() > 1) | 161 if (timings->size() > 1) |
| 162 currentTimings->reserveCapacity(timings->begin()->size()); | 162 currentTimings->reserveCapacity(timings->begin()->size()); |
| 163 ProfilingCanvas canvas(bitmap); | 163 ProfilingCanvas canvas(bitmap); |
| 164 if (clipRect) { | 164 if (clipRect) { |
| 165 canvas.clipRect(SkRect::MakeXYWH(clipRect->x(), clipRect->y(), clipR
ect->width(), clipRect->height())); | 165 canvas.clipRect(SkRect::MakeXYWH(clipRect->x(), clipRect->y(), clipR
ect->width(), clipRect->height())); |
| 166 canvas.resetStepCount(); | 166 canvas.resetStepCount(); |
| 167 } | 167 } |
| 168 canvas.setTimings(currentTimings); | 168 canvas.setTimings(currentTimings); |
| 169 m_picture->playback(&canvas); | 169 m_picture->playback(&canvas); |
| 170 now = WTF::monotonicallyIncreasingTime(); | 170 now = WTF::monotonicallyIncreasingTime(); |
| 171 } | 171 } |
| 172 return timings.release(); | 172 return timings; |
| 173 } | 173 } |
| 174 | 174 |
| 175 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const | 175 PassRefPtr<JSONArray> PictureSnapshot::snapshotCommandLog() const |
| 176 { | 176 { |
| 177 const SkIRect bounds = m_picture->cullRect().roundOut(); | 177 const SkIRect bounds = m_picture->cullRect().roundOut(); |
| 178 LoggingCanvas canvas(bounds.width(), bounds.height()); | 178 LoggingCanvas canvas(bounds.width(), bounds.height()); |
| 179 m_picture->playback(&canvas); | 179 m_picture->playback(&canvas); |
| 180 return canvas.log(); | 180 return canvas.log(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |