| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 const GraphicsContextSnapshot::Timings& timingsVector() const { return *m_ti
mingsVector; } | 160 const GraphicsContextSnapshot::Timings& timingsVector() const { return *m_ti
mingsVector; } |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 GraphicsContextSnapshot::Timings* m_timingsVector; | 163 GraphicsContextSnapshot::Timings* m_timingsVector; |
| 164 Vector<double>* m_currentTimings; | 164 Vector<double>* m_currentTimings; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 class LoggingSnapshotPlayer : public SnapshotPlayer { | |
| 168 public: | |
| 169 LoggingSnapshotPlayer(PassRefPtr<SkPicture> picture, SkCanvas* canvas) | |
| 170 : SnapshotPlayer(picture, canvas) | |
| 171 { | |
| 172 } | |
| 173 | |
| 174 virtual bool abortDrawing() OVERRIDE | |
| 175 { | |
| 176 return false; | |
| 177 } | |
| 178 }; | |
| 179 | |
| 180 class LoggingCanvas : public SkCanvas { | 167 class LoggingCanvas : public SkCanvas { |
| 181 public: | 168 public: |
| 182 LoggingCanvas() | 169 LoggingCanvas(int width, int height) : SkCanvas(width, height) |
| 170 { |
| 171 initLog(); |
| 172 } |
| 173 |
| 174 void initLog() |
| 183 { | 175 { |
| 184 m_log = JSONArray::create(); | 176 m_log = JSONArray::create(); |
| 185 } | 177 } |
| 186 | 178 |
| 187 void clear(SkColor color) OVERRIDE | 179 void clear(SkColor color) OVERRIDE |
| 188 { | 180 { |
| 189 addItemWithParams("clear")->setString("color", stringForSkColor(color)); | 181 addItemWithParams("clear")->setString("color", stringForSkColor(color)); |
| 190 } | 182 } |
| 191 | 183 |
| 192 void drawPaint(const SkPaint& paint) OVERRIDE | 184 void drawPaint(const SkPaint& paint) OVERRIDE |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 413 |
| 422 void willRestore() OVERRIDE | 414 void willRestore() OVERRIDE |
| 423 { | 415 { |
| 424 addItem("restore"); | 416 addItem("restore"); |
| 425 this->SkCanvas::willRestore(); | 417 this->SkCanvas::willRestore(); |
| 426 } | 418 } |
| 427 | 419 |
| 428 SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) OVERRIDE | 420 SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
SaveFlags flags) OVERRIDE |
| 429 { | 421 { |
| 430 RefPtr<JSONObject> params = addItemWithParams("saveLayer"); | 422 RefPtr<JSONObject> params = addItemWithParams("saveLayer"); |
| 431 params->setObject("bounds", objectForSkRect(*bounds)); | 423 if (bounds) |
| 424 params->setObject("bounds", objectForSkRect(*bounds)); |
| 432 params->setObject("paint", objectForSkPaint(*paint)); | 425 params->setObject("paint", objectForSkPaint(*paint)); |
| 433 params->setString("saveFlags", saveFlagsToString(flags)); | 426 params->setString("saveFlags", saveFlagsToString(flags)); |
| 434 this->SkCanvas::willSaveLayer(bounds, paint, flags); | 427 this->SkCanvas::willSaveLayer(bounds, paint, flags); |
| 435 return kNoLayer_SaveLayerStrategy; | 428 return kNoLayer_SaveLayerStrategy; |
| 436 } | 429 } |
| 437 | 430 |
| 438 void willSave(SaveFlags flags) OVERRIDE | 431 void willSave(SaveFlags flags) OVERRIDE |
| 439 { | 432 { |
| 440 RefPtr<JSONObject> params = addItemWithParams("save"); | 433 RefPtr<JSONObject> params = addItemWithParams("save"); |
| 441 params->setString("saveFlags", saveFlagsToString(flags)); | 434 params->setString("saveFlags", saveFlagsToString(flags)); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 paint.glyphsToUnichars(static_cast<const uint16_t*>(text), byteLengt
h / 2, textData); | 974 paint.glyphsToUnichars(static_cast<const uint16_t*>(text), byteLengt
h / 2, textData); |
| 982 return WTF::UTF32LittleEndianEncoding().decode(reinterpret_cast<cons
t char*>(textData), byteLength * 2); | 975 return WTF::UTF32LittleEndianEncoding().decode(reinterpret_cast<cons
t char*>(textData), byteLength * 2); |
| 983 } | 976 } |
| 984 default: | 977 default: |
| 985 ASSERT_NOT_REACHED(); | 978 ASSERT_NOT_REACHED(); |
| 986 return "?"; | 979 return "?"; |
| 987 } | 980 } |
| 988 } | 981 } |
| 989 }; | 982 }; |
| 990 | 983 |
| 984 class LoggingSnapshotPlayer : public SnapshotPlayer { |
| 985 public: |
| 986 LoggingSnapshotPlayer(PassRefPtr<SkPicture> picture, LoggingCanvas* canvas) |
| 987 : SnapshotPlayer(picture, canvas) |
| 988 { |
| 989 } |
| 990 |
| 991 void play(unsigned fromStep, unsigned toStep) |
| 992 { |
| 993 m_fromStep = fromStep; |
| 994 m_toStep = toStep; |
| 995 m_stepCount = 0; |
| 996 SnapshotPlayer::play(); |
| 997 } |
| 998 |
| 999 virtual bool abortDrawing() OVERRIDE |
| 1000 { |
| 1001 ++m_stepCount; |
| 1002 if (m_stepCount == m_fromStep) { |
| 1003 static_cast<LoggingCanvas*>(canvas())->initLog(); |
| 1004 } |
| 1005 return m_toStep && m_stepCount > m_toStep; |
| 1006 } |
| 1007 |
| 1008 private: |
| 1009 unsigned m_fromStep; |
| 1010 unsigned m_toStep; |
| 1011 unsigned m_stepCount; |
| 1012 }; |
| 1013 |
| 991 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) | 1014 static bool decodeBitmap(const void* data, size_t length, SkBitmap* result) |
| 992 { | 1015 { |
| 993 RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<const char*>(
data), length); | 1016 RefPtr<SharedBuffer> buffer = SharedBuffer::create(static_cast<const char*>(
data), length); |
| 994 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(*buffer, ImageSourc
e::AlphaPremultiplied, ImageSource::GammaAndColorProfileIgnored); | 1017 OwnPtr<ImageDecoder> imageDecoder = ImageDecoder::create(*buffer, ImageSourc
e::AlphaPremultiplied, ImageSource::GammaAndColorProfileIgnored); |
| 995 if (!imageDecoder) | 1018 if (!imageDecoder) |
| 996 return false; | 1019 return false; |
| 997 imageDecoder->setData(buffer.get(), true); | 1020 imageDecoder->setData(buffer.get(), true); |
| 998 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); | 1021 ImageFrame* frame = imageDecoder->frameBufferAtIndex(0); |
| 999 if (!frame) | 1022 if (!frame) |
| 1000 return true; | 1023 return true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1026 ProfilingSnapshotPlayer player(m_picture, imageBuffer->context()->canvas()); | 1049 ProfilingSnapshotPlayer player(m_picture, imageBuffer->context()->canvas()); |
| 1027 player.play(timings.get(), minRepeatCount, minDuration); | 1050 player.play(timings.get(), minRepeatCount, minDuration); |
| 1028 return timings.release(); | 1051 return timings.release(); |
| 1029 } | 1052 } |
| 1030 | 1053 |
| 1031 PassOwnPtr<ImageBuffer> GraphicsContextSnapshot::createImageBuffer() const | 1054 PassOwnPtr<ImageBuffer> GraphicsContextSnapshot::createImageBuffer() const |
| 1032 { | 1055 { |
| 1033 return ImageBuffer::create(IntSize(m_picture->width(), m_picture->height()),
m_isCertainlyOpaque ? Opaque : NonOpaque); | 1056 return ImageBuffer::create(IntSize(m_picture->width(), m_picture->height()),
m_isCertainlyOpaque ? Opaque : NonOpaque); |
| 1034 } | 1057 } |
| 1035 | 1058 |
| 1036 PassRefPtr<JSONArray> GraphicsContextSnapshot::snapshotCommandLog() const | 1059 PassRefPtr<JSONArray> GraphicsContextSnapshot::snapshotCommandLog(unsigned fromS
tep, unsigned toStep) const |
| 1037 { | 1060 { |
| 1038 LoggingCanvas canvas; | 1061 LoggingCanvas canvas(m_picture->width(), m_picture->height()); |
| 1039 FragmentSnapshotPlayer player(m_picture, &canvas); | 1062 LoggingSnapshotPlayer player(m_picture, &canvas); |
| 1040 player.play(0, 0); | 1063 player.play(fromStep, toStep); |
| 1041 return canvas.log(); | 1064 return canvas.log(); |
| 1042 } | 1065 } |
| 1043 | 1066 |
| 1044 } | 1067 } |
| OLD | NEW |