OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/cursors/webcursor.h" | 5 #include "content/common/cursors/webcursor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "third_party/WebKit/public/platform/WebImage.h" | 9 #include "third_party/WebKit/public/platform/WebImage.h" |
10 | 10 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 custom_scale_ = other.custom_scale_; | 224 custom_scale_ = other.custom_scale_; |
225 custom_data_ = other.custom_data_; | 225 custom_data_ = other.custom_data_; |
226 CopyPlatformData(other); | 226 CopyPlatformData(other); |
227 } | 227 } |
228 | 228 |
229 void WebCursor::SetCustomData(const SkBitmap& bitmap) { | 229 void WebCursor::SetCustomData(const SkBitmap& bitmap) { |
230 if (bitmap.empty()) | 230 if (bitmap.empty()) |
231 return; | 231 return; |
232 | 232 |
233 // Fill custom_data_ directly with the NativeImage pixels. | 233 // Fill custom_data_ directly with the NativeImage pixels. |
234 SkAutoLockPixels bitmap_lock(bitmap); | |
235 custom_data_.resize(bitmap.getSize()); | 234 custom_data_.resize(bitmap.getSize()); |
236 if (!custom_data_.empty()) | 235 if (!custom_data_.empty()) { |
237 memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize()); | 236 //This will divide color values by alpha (un-premultiply) if necessary |
| 237 SkImageInfo dstInfo = bitmap.info().makeAlphaType(kUnpremul_SkAlphaType); |
| 238 bitmap.readPixels(dstInfo, &custom_data_[0], dstInfo.minRowBytes(), 0, 0); |
| 239 } |
238 custom_size_.set_width(bitmap.width()); | 240 custom_size_.set_width(bitmap.width()); |
239 custom_size_.set_height(bitmap.height()); | 241 custom_size_.set_height(bitmap.height()); |
240 } | 242 } |
241 | 243 |
242 void WebCursor::ImageFromCustomData(SkBitmap* image) const { | 244 void WebCursor::ImageFromCustomData(SkBitmap* image) const { |
243 if (custom_data_.empty()) | 245 if (custom_data_.empty()) |
244 return; | 246 return; |
245 | 247 |
246 if (!image->tryAllocN32Pixels(custom_size_.width(), custom_size_.height())) | 248 SkImageInfo image_info = SkImageInfo::MakeN32(custom_size_.width(), |
| 249 custom_size_.height(), |
| 250 kUnpremul_SkAlphaType); |
| 251 if (!image->tryAllocPixels(image_info)) |
247 return; | 252 return; |
248 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); | 253 memcpy(image->getPixels(), &custom_data_[0], custom_data_.size()); |
249 } | 254 } |
250 | 255 |
251 void WebCursor::ClampHotspot() { | 256 void WebCursor::ClampHotspot() { |
252 if (!IsCustom()) | 257 if (!IsCustom()) |
253 return; | 258 return; |
254 | 259 |
255 // Clamp the hotspot to the custom image's dimensions. | 260 // Clamp the hotspot to the custom image's dimensions. |
256 hotspot_.set_x(std::max(0, | 261 hotspot_.set_x(std::max(0, |
257 std::min(custom_size_.width() - 1, hotspot_.x()))); | 262 std::min(custom_size_.width() - 1, hotspot_.x()))); |
258 hotspot_.set_y(std::max(0, | 263 hotspot_.set_y(std::max(0, |
259 std::min(custom_size_.height() - 1, hotspot_.y()))); | 264 std::min(custom_size_.height() - 1, hotspot_.y()))); |
260 } | 265 } |
261 | 266 |
262 } // namespace content | 267 } // namespace content |
OLD | NEW |