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

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

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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
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 "skia/ext/cdl_canvas.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)
18 context.drawPicture(m_picture.get()); 19 context.drawPicture(m_picture.get());
19 } 20 }
20 21
21 void DrawingDisplayItem::appendToWebDisplayItemList( 22 void DrawingDisplayItem::appendToWebDisplayItemList(
22 const IntRect& visualRect, 23 const IntRect& visualRect,
23 WebDisplayItemList* list) const { 24 WebDisplayItemList* list) const {
24 if (m_picture) 25 if (m_picture)
25 list->appendDrawingItem(visualRect, m_picture); 26 list->appendDrawingItem(visualRect, m_picture);
26 } 27 }
27 28
28 bool DrawingDisplayItem::drawsContent() const { 29 bool DrawingDisplayItem::drawsContent() const {
29 return m_picture.get(); 30 return m_picture.get();
30 } 31 }
31 32
32 void DrawingDisplayItem::analyzeForGpuRasterization( 33 void DrawingDisplayItem::analyzeForGpuRasterization(
33 SkPictureGpuAnalyzer& analyzer) const { 34 SkPictureGpuAnalyzer& analyzer) const {
34 analyzer.analyzePicture(m_picture.get()); 35 // TODO(cdl): Need drawable analyzer.
36 // analyzer.analyzePicture(m_picture.get());
35 } 37 }
36 38
37 #ifndef NDEBUG 39 #ifndef NDEBUG
38 void DrawingDisplayItem::dumpPropertiesAsDebugString( 40 void DrawingDisplayItem::dumpPropertiesAsDebugString(
39 StringBuilder& stringBuilder) const { 41 StringBuilder& stringBuilder) const {
40 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); 42 DisplayItem::dumpPropertiesAsDebugString(stringBuilder);
41 if (m_picture) { 43 if (m_picture) {
42 stringBuilder.append( 44 stringBuilder.append(
43 String::format(", rect: [%f,%f %fx%f]", m_picture->cullRect().x(), 45 String::format(", rect: [%f,%f %fx%f]", m_picture->cullRect().x(),
44 m_picture->cullRect().y(), m_picture->cullRect().width(), 46 m_picture->cullRect().y(), m_picture->cullRect().width(),
45 m_picture->cullRect().height())); 47 m_picture->cullRect().height()));
46 } 48 }
47 } 49 }
48 #endif 50 #endif
49 51
50 static bool picturesEqual(const SkPicture* picture1, 52 static bool picturesEqual(const CdlPicture* picture1,
51 const SkPicture* picture2) { 53 const CdlPicture* picture2) {
52 if (picture1->approximateOpCount() != picture2->approximateOpCount()) 54 if (picture1->approximateOpCount() != picture2->approximateOpCount())
53 return false; 55 return false;
54 56
55 sk_sp<SkData> data1 = picture1->serialize(); 57 sk_sp<SkData> data1 = ToSkPicture(picture1)->serialize();
56 sk_sp<SkData> data2 = picture2->serialize(); 58 sk_sp<SkData> data2 = ToSkPicture(picture2)->serialize();
57 return data1->equals(data2.get()); 59 return data1->equals(data2.get());
58 } 60 }
59 61
60 static SkBitmap pictureToBitmap(const SkPicture* picture) { 62 static SkBitmap pictureToBitmap(const CdlPicture* picture) {
61 SkBitmap bitmap; 63 SkBitmap bitmap;
62 SkRect rect = picture->cullRect(); 64 SkRect rect = picture->cullRect();
63 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); 65 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height()));
64 SkCanvas canvas(bitmap); 66 SkCanvas sk_canvas(bitmap);
67 CdlPassThroughCanvas canvas(&sk_canvas);
65 canvas.clear(SK_ColorTRANSPARENT); 68 canvas.clear(SK_ColorTRANSPARENT);
66 canvas.translate(-rect.x(), -rect.y()); 69 canvas.translate(-rect.x(), -rect.y());
67 canvas.drawPicture(picture); 70 canvas.drawPicture(picture);
68 return bitmap; 71 return bitmap;
69 } 72 }
70 73
71 static bool bitmapsEqual(const SkPicture* picture1, const SkPicture* picture2) { 74 static bool bitmapsEqual(const CdlPicture* picture1,
75 const CdlPicture* picture2) {
72 SkRect rect = picture1->cullRect(); 76 SkRect rect = picture1->cullRect();
73 if (rect != picture2->cullRect()) 77 if (rect != picture2->cullRect())
74 return false; 78 return false;
75 79
76 SkBitmap bitmap1 = pictureToBitmap(picture1); 80 SkBitmap bitmap1 = pictureToBitmap(picture1);
77 SkBitmap bitmap2 = pictureToBitmap(picture2); 81 SkBitmap bitmap2 = pictureToBitmap(picture2);
78 bitmap1.lockPixels(); 82 bitmap1.lockPixels();
79 bitmap2.lockPixels(); 83 bitmap2.lockPixels();
80 int mismatchCount = 0; 84 int mismatchCount = 0;
81 const int maxMismatches = 10; 85 const int maxMismatches = 10;
(...skipping 10 matching lines...) Expand all
92 } 96 }
93 bitmap1.unlockPixels(); 97 bitmap1.unlockPixels();
94 bitmap2.unlockPixels(); 98 bitmap2.unlockPixels();
95 return !mismatchCount; 99 return !mismatchCount;
96 } 100 }
97 101
98 bool DrawingDisplayItem::equals(const DisplayItem& other) const { 102 bool DrawingDisplayItem::equals(const DisplayItem& other) const {
99 if (!DisplayItem::equals(other)) 103 if (!DisplayItem::equals(other))
100 return false; 104 return false;
101 105
102 const SkPicture* picture = this->picture(); 106 const CdlPicture* picture = this->picture();
103 const SkPicture* otherPicture = 107 const CdlPicture* otherPicture =
104 static_cast<const DrawingDisplayItem&>(other).picture(); 108 static_cast<const DrawingDisplayItem&>(other).picture();
105 109
106 if (!picture && !otherPicture) 110 if (!picture && !otherPicture)
107 return true; 111 return true;
108 if (!picture || !otherPicture) 112 if (!picture || !otherPicture)
109 return false; 113 return false;
110 114
111 if (picturesEqual(picture, otherPicture)) 115 if (picturesEqual(picture, otherPicture))
112 return true; 116 return true;
113 117
114 // Sometimes the client may produce different pictures for the same visual 118 // Sometimes the client may produce different pictures for the same visual
115 // result, which should be treated as equal. 119 // result, which should be treated as equal.
116 return bitmapsEqual(picture, otherPicture); 120 return bitmapsEqual(picture, otherPicture);
117 } 121 }
118 122
119 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698