| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/paint/DrawingDisplayItem.h" | 5 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 6 | 6 |
| 7 #include "platform/graphics/GraphicsContext.h" | 7 #include "platform/graphics/GraphicsContext.h" |
| 8 #include "platform/graphics/paint/PaintCanvas.h" | 8 #include "platform/graphics/paint/PaintCanvas.h" |
| 9 #include "public/platform/WebDisplayItemList.h" | 9 #include "public/platform/WebDisplayItemList.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 if (m_record) | 25 if (m_record) |
| 26 list->appendDrawingItem(visualRect, m_record); | 26 list->appendDrawingItem(visualRect, m_record); |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool DrawingDisplayItem::drawsContent() const { | 29 bool DrawingDisplayItem::drawsContent() const { |
| 30 return m_record.get(); | 30 return m_record.get(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void DrawingDisplayItem::analyzeForGpuRasterization( | 33 void DrawingDisplayItem::analyzeForGpuRasterization( |
| 34 SkPictureGpuAnalyzer& analyzer) const { | 34 SkPictureGpuAnalyzer& analyzer) const { |
| 35 analyzer.analyzePicture(m_record.get()); | 35 // TODO(enne): Need an SkPictureGpuAnalyzer on PictureRecord. |
| 36 // This is a bit overkill to ToSkPicture a record just to get |
| 37 // numSlowPaths. |
| 38 if (!m_record) |
| 39 return; |
| 40 analyzer.analyzePicture(ToSkPicture(m_record.get())); |
| 36 } | 41 } |
| 37 | 42 |
| 38 #ifndef NDEBUG | 43 #ifndef NDEBUG |
| 39 void DrawingDisplayItem::dumpPropertiesAsDebugString( | 44 void DrawingDisplayItem::dumpPropertiesAsDebugString( |
| 40 StringBuilder& stringBuilder) const { | 45 StringBuilder& stringBuilder) const { |
| 41 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); | 46 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); |
| 42 if (m_record) { | 47 if (m_record) { |
| 43 stringBuilder.append( | 48 stringBuilder.append( |
| 44 String::format(", rect: [%f,%f %fx%f]", m_record->cullRect().x(), | 49 String::format(", rect: [%f,%f %fx%f]", m_record->cullRect().x(), |
| 45 m_record->cullRect().y(), m_record->cullRect().width(), | 50 m_record->cullRect().y(), m_record->cullRect().width(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 56 // TODO(enne): PaintRecord should have an operator== | 61 // TODO(enne): PaintRecord should have an operator== |
| 57 sk_sp<SkData> data1 = ToSkPicture(record1)->serialize(); | 62 sk_sp<SkData> data1 = ToSkPicture(record1)->serialize(); |
| 58 sk_sp<SkData> data2 = ToSkPicture(record2)->serialize(); | 63 sk_sp<SkData> data2 = ToSkPicture(record2)->serialize(); |
| 59 return data1->equals(data2.get()); | 64 return data1->equals(data2.get()); |
| 60 } | 65 } |
| 61 | 66 |
| 62 static SkBitmap recordToBitmap(const PaintRecord* record) { | 67 static SkBitmap recordToBitmap(const PaintRecord* record) { |
| 63 SkBitmap bitmap; | 68 SkBitmap bitmap; |
| 64 SkRect rect = record->cullRect(); | 69 SkRect rect = record->cullRect(); |
| 65 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); | 70 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); |
| 66 SkCanvas bitmapCanvas(bitmap); | 71 PaintCanvas canvas(bitmap); |
| 67 PaintCanvasPassThrough canvas(&bitmapCanvas); | |
| 68 canvas.clear(SK_ColorTRANSPARENT); | 72 canvas.clear(SK_ColorTRANSPARENT); |
| 69 canvas.translate(-rect.x(), -rect.y()); | 73 canvas.translate(-rect.x(), -rect.y()); |
| 70 canvas.drawPicture(ToSkPicture(record)); | 74 canvas.drawPicture(record); |
| 71 return bitmap; | 75 return bitmap; |
| 72 } | 76 } |
| 73 | 77 |
| 74 static bool bitmapsEqual(const PaintRecord* record1, | 78 static bool bitmapsEqual(const PaintRecord* record1, |
| 75 const PaintRecord* record2) { | 79 const PaintRecord* record2) { |
| 76 SkRect rect = record1->cullRect(); | 80 SkRect rect = record1->cullRect(); |
| 77 if (rect != record2->cullRect()) | 81 if (rect != record2->cullRect()) |
| 78 return false; | 82 return false; |
| 79 | 83 |
| 80 SkBitmap bitmap1 = recordToBitmap(record1); | 84 SkBitmap bitmap1 = recordToBitmap(record1); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 118 |
| 115 if (recordsEqual(record, otherRecord)) | 119 if (recordsEqual(record, otherRecord)) |
| 116 return true; | 120 return true; |
| 117 | 121 |
| 118 // Sometimes the client may produce different records for the same visual | 122 // Sometimes the client may produce different records for the same visual |
| 119 // result, which should be treated as equal. | 123 // result, which should be treated as equal. |
| 120 return bitmapsEqual(record, otherRecord); | 124 return bitmapsEqual(record, otherRecord); |
| 121 } | 125 } |
| 122 | 126 |
| 123 } // namespace blink | 127 } // namespace blink |
| OLD | NEW |