| 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 "public/platform/WebDisplayItemList.h" |    9 #include "public/platform/WebDisplayItemList.h" | 
|    9 #include "third_party/skia/include/core/SkBitmap.h" |   10 #include "third_party/skia/include/core/SkBitmap.h" | 
|   10 #include "third_party/skia/include/core/SkCanvas.h" |   11 #include "third_party/skia/include/core/SkCanvas.h" | 
|   11 #include "third_party/skia/include/core/SkData.h" |   12 #include "third_party/skia/include/core/SkData.h" | 
|   12 #include "third_party/skia/include/core/SkPictureAnalyzer.h" |   13 #include "third_party/skia/include/core/SkPictureAnalyzer.h" | 
|   13  |   14  | 
|   14 namespace blink { |   15 namespace blink { | 
|   15  |   16  | 
|   16 void DrawingDisplayItem::replay(GraphicsContext& context) const { |   17 void DrawingDisplayItem::replay(GraphicsContext& context) const { | 
|   17   if (m_picture) |   18   if (m_picture) | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|   40   DisplayItem::dumpPropertiesAsDebugString(stringBuilder); |   41   DisplayItem::dumpPropertiesAsDebugString(stringBuilder); | 
|   41   if (m_picture) { |   42   if (m_picture) { | 
|   42     stringBuilder.append( |   43     stringBuilder.append( | 
|   43         String::format(", rect: [%f,%f %fx%f]", m_picture->cullRect().x(), |   44         String::format(", rect: [%f,%f %fx%f]", m_picture->cullRect().x(), | 
|   44                        m_picture->cullRect().y(), m_picture->cullRect().width(), |   45                        m_picture->cullRect().y(), m_picture->cullRect().width(), | 
|   45                        m_picture->cullRect().height())); |   46                        m_picture->cullRect().height())); | 
|   46   } |   47   } | 
|   47 } |   48 } | 
|   48 #endif |   49 #endif | 
|   49  |   50  | 
|   50 static bool picturesEqual(const SkPicture* picture1, |   51 static bool picturesEqual(const PaintRecord* picture1, | 
|   51                           const SkPicture* picture2) { |   52                           const PaintRecord* picture2) { | 
|   52   if (picture1->approximateOpCount() != picture2->approximateOpCount()) |   53   if (picture1->approximateOpCount() != picture2->approximateOpCount()) | 
|   53     return false; |   54     return false; | 
|   54  |   55  | 
|   55   sk_sp<SkData> data1 = picture1->serialize(); |   56   sk_sp<SkData> data1 = ToSkPicture(picture1)->serialize(); | 
|   56   sk_sp<SkData> data2 = picture2->serialize(); |   57   sk_sp<SkData> data2 = ToSkPicture(picture2)->serialize(); | 
|   57   return data1->equals(data2.get()); |   58   return data1->equals(data2.get()); | 
|   58 } |   59 } | 
|   59  |   60  | 
|   60 static SkBitmap pictureToBitmap(const SkPicture* picture) { |   61 static SkBitmap pictureToBitmap(const PaintRecord* picture) { | 
|   61   SkBitmap bitmap; |   62   SkBitmap bitmap; | 
|   62   SkRect rect = picture->cullRect(); |   63   SkRect rect = picture->cullRect(); | 
|   63   bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); |   64   bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); | 
|   64   SkCanvas canvas(bitmap); |   65   SkCanvas bitmapCanvas(bitmap); | 
 |   66   PaintCanvasPassThrough canvas(&bitmapCanvas); | 
|   65   canvas.clear(SK_ColorTRANSPARENT); |   67   canvas.clear(SK_ColorTRANSPARENT); | 
|   66   canvas.translate(-rect.x(), -rect.y()); |   68   canvas.translate(-rect.x(), -rect.y()); | 
|   67   canvas.drawPicture(picture); |   69   canvas.drawPicture(picture); | 
|   68   return bitmap; |   70   return bitmap; | 
|   69 } |   71 } | 
|   70  |   72  | 
|   71 static bool bitmapsEqual(const SkPicture* picture1, const SkPicture* picture2) { |   73 static bool bitmapsEqual(const PaintRecord* picture1, | 
 |   74                          const PaintRecord* picture2) { | 
|   72   SkRect rect = picture1->cullRect(); |   75   SkRect rect = picture1->cullRect(); | 
|   73   if (rect != picture2->cullRect()) |   76   if (rect != picture2->cullRect()) | 
|   74     return false; |   77     return false; | 
|   75  |   78  | 
|   76   SkBitmap bitmap1 = pictureToBitmap(picture1); |   79   SkBitmap bitmap1 = pictureToBitmap(picture1); | 
|   77   SkBitmap bitmap2 = pictureToBitmap(picture2); |   80   SkBitmap bitmap2 = pictureToBitmap(picture2); | 
|   78   bitmap1.lockPixels(); |   81   bitmap1.lockPixels(); | 
|   79   bitmap2.lockPixels(); |   82   bitmap2.lockPixels(); | 
|   80   int mismatchCount = 0; |   83   int mismatchCount = 0; | 
|   81   const int maxMismatches = 10; |   84   const int maxMismatches = 10; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   92   } |   95   } | 
|   93   bitmap1.unlockPixels(); |   96   bitmap1.unlockPixels(); | 
|   94   bitmap2.unlockPixels(); |   97   bitmap2.unlockPixels(); | 
|   95   return !mismatchCount; |   98   return !mismatchCount; | 
|   96 } |   99 } | 
|   97  |  100  | 
|   98 bool DrawingDisplayItem::equals(const DisplayItem& other) const { |  101 bool DrawingDisplayItem::equals(const DisplayItem& other) const { | 
|   99   if (!DisplayItem::equals(other)) |  102   if (!DisplayItem::equals(other)) | 
|  100     return false; |  103     return false; | 
|  101  |  104  | 
|  102   const SkPicture* picture = this->picture(); |  105   const PaintRecord* picture = this->picture(); | 
|  103   const SkPicture* otherPicture = |  106   const PaintRecord* otherPicture = | 
|  104       static_cast<const DrawingDisplayItem&>(other).picture(); |  107       static_cast<const DrawingDisplayItem&>(other).picture(); | 
|  105  |  108  | 
|  106   if (!picture && !otherPicture) |  109   if (!picture && !otherPicture) | 
|  107     return true; |  110     return true; | 
|  108   if (!picture || !otherPicture) |  111   if (!picture || !otherPicture) | 
|  109     return false; |  112     return false; | 
|  110  |  113  | 
|  111   if (picturesEqual(picture, otherPicture)) |  114   if (picturesEqual(picture, otherPicture)) | 
|  112     return true; |  115     return true; | 
|  113  |  116  | 
|  114   // Sometimes the client may produce different pictures for the same visual |  117   // Sometimes the client may produce different pictures for the same visual | 
|  115   // result, which should be treated as equal. |  118   // result, which should be treated as equal. | 
|  116   return bitmapsEqual(picture, otherPicture); |  119   return bitmapsEqual(picture, otherPicture); | 
|  117 } |  120 } | 
|  118  |  121  | 
|  119 }  // namespace blink |  122 }  // namespace blink | 
| OLD | NEW |