Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(639)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/DrawingDisplayItem.cpp

Issue 2343993002: use SkData oriented picture serialize api (Closed)
Patch Set: doh -- use 0u for template bad guesses Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « skia/config/SkUserConfig.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "public/platform/WebDisplayItemList.h" 8 #include "public/platform/WebDisplayItemList.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkData.h" 11 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkPictureAnalyzer.h" 12 #include "third_party/skia/include/core/SkPictureAnalyzer.h"
13 #include "third_party/skia/include/core/SkStream.h"
14 13
15 namespace blink { 14 namespace blink {
16 15
17 void DrawingDisplayItem::replay(GraphicsContext& context) const 16 void DrawingDisplayItem::replay(GraphicsContext& context) const
18 { 17 {
19 if (m_picture) 18 if (m_picture)
20 context.drawPicture(m_picture.get()); 19 context.drawPicture(m_picture.get());
21 } 20 }
22 21
23 void DrawingDisplayItem::appendToWebDisplayItemList(const IntRect& visualRect, W ebDisplayItemList* list) const 22 void DrawingDisplayItem::appendToWebDisplayItemList(const IntRect& visualRect, W ebDisplayItemList* list) const
(...skipping 22 matching lines...) Expand all
46 m_picture->cullRect().width(), m_picture->cullRect().height())); 45 m_picture->cullRect().width(), m_picture->cullRect().height()));
47 } 46 }
48 } 47 }
49 #endif 48 #endif
50 49
51 static bool picturesEqual(const SkPicture* picture1, const SkPicture* picture2) 50 static bool picturesEqual(const SkPicture* picture1, const SkPicture* picture2)
52 { 51 {
53 if (picture1->approximateOpCount() != picture2->approximateOpCount()) 52 if (picture1->approximateOpCount() != picture2->approximateOpCount())
54 return false; 53 return false;
55 54
56 SkDynamicMemoryWStream picture1Serialized; 55 sk_sp<SkData> data1 = picture1->serialize();
57 picture1->serialize(&picture1Serialized); 56 sk_sp<SkData> data2 = picture2->serialize();
58 SkDynamicMemoryWStream picture2Serialized;
59 picture2->serialize(&picture2Serialized);
60 if (picture1Serialized.bytesWritten() != picture2Serialized.bytesWritten())
61 return false;
62
63 sk_sp<SkData> data1(picture1Serialized.copyToData());
64 sk_sp<SkData> data2(picture2Serialized.copyToData());
65 return data1->equals(data2.get()); 57 return data1->equals(data2.get());
66 } 58 }
67 59
68 static SkBitmap pictureToBitmap(const SkPicture* picture) 60 static SkBitmap pictureToBitmap(const SkPicture* picture)
69 { 61 {
70 SkBitmap bitmap; 62 SkBitmap bitmap;
71 SkRect rect = picture->cullRect(); 63 SkRect rect = picture->cullRect();
72 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); 64 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height()));
73 SkCanvas canvas(bitmap); 65 SkCanvas canvas(bitmap);
74 canvas.clear(SK_ColorTRANSPARENT); 66 canvas.clear(SK_ColorTRANSPARENT);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 111
120 if (picturesEqual(picture, otherPicture)) 112 if (picturesEqual(picture, otherPicture))
121 return true; 113 return true;
122 114
123 // Sometimes the client may produce different pictures for the same visual r esult 115 // Sometimes the client may produce different pictures for the same visual r esult
124 // which should be treated as equal. 116 // which should be treated as equal.
125 return bitmapsEqual(picture, otherPicture); 117 return bitmapsEqual(picture, otherPicture);
126 } 118 }
127 119
128 } // namespace blink 120 } // namespace blink
OLDNEW
« no previous file with comments | « skia/config/SkUserConfig.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698