OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "chrome/browser/history/top_sites.h" | 7 #include "chrome/browser/history/top_sites.h" |
8 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 8 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // Process all pending tasks to avoid leaks. | 87 // Process all pending tasks to avoid leaks. |
88 message_loop_.RunAllPending(); | 88 message_loop_.RunAllPending(); |
89 } | 89 } |
90 | 90 |
91 protected: | 91 protected: |
92 // Indicates what bitmap should be sent with the paint message. _OTHER will | 92 // Indicates what bitmap should be sent with the paint message. _OTHER will |
93 // only be retrned by CheckFirstPixel if the pixel is none of the others. | 93 // only be retrned by CheckFirstPixel if the pixel is none of the others. |
94 enum TransportType { TRANSPORT_BLACK, TRANSPORT_WHITE, TRANSPORT_OTHER }; | 94 enum TransportType { TRANSPORT_BLACK, TRANSPORT_WHITE, TRANSPORT_OTHER }; |
95 | 95 |
96 void SendPaint(TransportType type) { | 96 void SendPaint(TransportType type) { |
97 ViewHostMsg_UpdateRect_Params params; | |
98 params.bitmap_rect = gfx::Rect(0, 0, kBitmapWidth, kBitmapHeight); | |
99 params.view_size = params.bitmap_rect.size(); | |
100 params.copy_rects.push_back(params.bitmap_rect); | |
101 params.flags = 0; | |
102 | |
103 scoped_ptr<skia::PlatformCanvas> canvas( | 97 scoped_ptr<skia::PlatformCanvas> canvas( |
104 transport_dib_->GetPlatformCanvas(kBitmapWidth, kBitmapHeight)); | 98 transport_dib_->GetPlatformCanvas(kBitmapWidth, kBitmapHeight)); |
105 switch (type) { | 99 switch (type) { |
106 case TRANSPORT_BLACK: | 100 case TRANSPORT_BLACK: |
107 skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB( | 101 skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB( |
108 0xFF, 0, 0, 0); | 102 0xFF, 0, 0, 0); |
109 break; | 103 break; |
110 case TRANSPORT_WHITE: | 104 case TRANSPORT_WHITE: |
111 skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB( | 105 skia::GetTopDevice(*canvas)->accessBitmap(true).eraseARGB( |
112 0xFF, 0xFF, 0xFF, 0xFF); | 106 0xFF, 0xFF, 0xFF, 0xFF); |
113 break; | 107 break; |
114 case TRANSPORT_OTHER: | 108 case TRANSPORT_OTHER: |
115 default: | 109 default: |
116 NOTREACHED(); | 110 NOTREACHED(); |
117 break; | 111 break; |
118 } | 112 } |
119 | 113 |
120 params.bitmap = transport_dib_->id(); | 114 gfx::Rect rect(0, 0, kBitmapWidth, kBitmapHeight); |
121 | 115 SimulateUpdateRect(widget_.get(), transport_dib_->id(), rect); |
122 ViewHostMsg_UpdateRect msg(1, params); | |
123 widget_->OnMessageReceived(msg); | |
124 } | 116 } |
125 | 117 |
126 TransportType ClassifyFirstPixel(const SkBitmap& bitmap) { | 118 TransportType ClassifyFirstPixel(const SkBitmap& bitmap) { |
127 // Returns the color of the first pixel of the bitmap. The bitmap must be | 119 // Returns the color of the first pixel of the bitmap. The bitmap must be |
128 // non-empty. | 120 // non-empty. |
129 SkAutoLockPixels lock(bitmap); | 121 SkAutoLockPixels lock(bitmap); |
130 uint32 pixel = *bitmap.getAddr32(0, 0); | 122 uint32 pixel = *bitmap.getAddr32(0, 0); |
131 | 123 |
132 if (SkGetPackedA32(pixel) != 0xFF) | 124 if (SkGetPackedA32(pixel) != 0xFF) |
133 return TRANSPORT_OTHER; // All values expect an opqaue alpha channel | 125 return TRANSPORT_OTHER; // All values expect an opqaue alpha channel |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 good_score.good_clipping = true; | 397 good_score.good_clipping = true; |
406 good_score.boring_score = 0.0; | 398 good_score.boring_score = 0.0; |
407 good_score.load_completed = true; | 399 good_score.load_completed = true; |
408 top_sites->AddKnownURL(kGoodURL, good_score); | 400 top_sites->AddKnownURL(kGoodURL, good_score); |
409 | 401 |
410 // Should be false, as the existing thumbnail is good enough (i.e. don't | 402 // Should be false, as the existing thumbnail is good enough (i.e. don't |
411 // need to replace the existing thumbnail which is new and good). | 403 // need to replace the existing thumbnail which is new and good). |
412 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( | 404 EXPECT_FALSE(ThumbnailGenerator::ShouldUpdateThumbnail( |
413 &profile, top_sites.get(), kGoodURL)); | 405 &profile, top_sites.get(), kGoodURL)); |
414 } | 406 } |
OLD | NEW |