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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // The canonical API involves SkSurface props, but since we're not | 135 // The canonical API involves SkSurface props, but since we're not |
136 // SkSurface-based at this point (see TODO above) we (ab)use saveLayer for | 136 // SkSurface-based at this point (see TODO above) we (ab)use saveLayer for |
137 // this purpose. | 137 // this purpose. |
138 SkAutoCanvasRestore autoRestore(&canvas, false); | 138 SkAutoCanvasRestore autoRestore(&canvas, false); |
139 canvas.saveLayer(nullptr, nullptr); | 139 canvas.saveLayer(nullptr, nullptr); |
140 | 140 |
141 canvas.scale(scale, scale); | 141 canvas.scale(scale, scale); |
142 canvas.resetStepCount(); | 142 canvas.resetStepCount(); |
143 m_picture->playback(&canvas, &canvas); | 143 m_picture->playback(&canvas, &canvas); |
144 } | 144 } |
145 std::unique_ptr<Vector<char>> base64Data = makeUnique<Vector<char>>(); | 145 std::unique_ptr<Vector<char>> base64Data = WTF::makeUnique<Vector<char>>(); |
146 Vector<char> encodedImage; | 146 Vector<char> encodedImage; |
147 | 147 |
148 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 148 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
149 if (!image) | 149 if (!image) |
150 return nullptr; | 150 return nullptr; |
151 | 151 |
152 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, | 152 ImagePixelLocker pixelLocker(image, kUnpremul_SkAlphaType, |
153 kRGBA_8888_SkColorType); | 153 kRGBA_8888_SkColorType); |
154 ImageDataBuffer imageData( | 154 ImageDataBuffer imageData( |
155 IntSize(image->width(), image->height()), | 155 IntSize(image->width(), image->height()), |
156 static_cast<const unsigned char*>(pixelLocker.pixels())); | 156 static_cast<const unsigned char*>(pixelLocker.pixels())); |
157 if (!PNGImageEncoder::encode( | 157 if (!PNGImageEncoder::encode( |
158 imageData, reinterpret_cast<Vector<unsigned char>*>(&encodedImage))) | 158 imageData, reinterpret_cast<Vector<unsigned char>*>(&encodedImage))) |
159 return nullptr; | 159 return nullptr; |
160 | 160 |
161 base64Encode(encodedImage, *base64Data); | 161 base64Encode(encodedImage, *base64Data); |
162 return base64Data; | 162 return base64Data; |
163 } | 163 } |
164 | 164 |
165 std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::profile( | 165 std::unique_ptr<PictureSnapshot::Timings> PictureSnapshot::profile( |
166 unsigned minRepeatCount, | 166 unsigned minRepeatCount, |
167 double minDuration, | 167 double minDuration, |
168 const FloatRect* clipRect) const { | 168 const FloatRect* clipRect) const { |
169 std::unique_ptr<PictureSnapshot::Timings> timings = | 169 std::unique_ptr<PictureSnapshot::Timings> timings = |
170 makeUnique<PictureSnapshot::Timings>(); | 170 WTF::makeUnique<PictureSnapshot::Timings>(); |
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) { |
(...skipping 15 matching lines...) Expand all Loading... |
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 |