OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 } // namespace | 110 } // namespace |
111 | 111 |
112 MouseCursor* CreateMouseCursorFromHCursor(HDC dc, HCURSOR cursor) { | 112 MouseCursor* CreateMouseCursorFromHCursor(HDC dc, HCURSOR cursor) { |
113 ICONINFO iinfo; | 113 ICONINFO iinfo; |
114 if (!GetIconInfo(cursor, &iinfo)) { | 114 if (!GetIconInfo(cursor, &iinfo)) { |
115 LOG_F(LS_ERROR) << "Unable to get cursor icon info. Error = " | 115 LOG_F(LS_ERROR) << "Unable to get cursor icon info. Error = " |
116 << GetLastError(); | 116 << GetLastError(); |
117 return NULL; | 117 return nullptr; |
118 } | 118 } |
119 | 119 |
120 int hotspot_x = iinfo.xHotspot; | 120 int hotspot_x = iinfo.xHotspot; |
121 int hotspot_y = iinfo.yHotspot; | 121 int hotspot_y = iinfo.yHotspot; |
122 | 122 |
123 // Make sure the bitmaps will be freed. | 123 // Make sure the bitmaps will be freed. |
124 win::ScopedBitmap scoped_mask(iinfo.hbmMask); | 124 win::ScopedBitmap scoped_mask(iinfo.hbmMask); |
125 win::ScopedBitmap scoped_color(iinfo.hbmColor); | 125 win::ScopedBitmap scoped_color(iinfo.hbmColor); |
126 bool is_color = iinfo.hbmColor != NULL; | 126 bool is_color = iinfo.hbmColor != nullptr; |
127 | 127 |
128 // Get |scoped_mask| dimensions. | 128 // Get |scoped_mask| dimensions. |
129 BITMAP bitmap_info; | 129 BITMAP bitmap_info; |
130 if (!GetObject(scoped_mask, sizeof(bitmap_info), &bitmap_info)) { | 130 if (!GetObject(scoped_mask, sizeof(bitmap_info), &bitmap_info)) { |
131 LOG_F(LS_ERROR) << "Unable to get bitmap info. Error = " | 131 LOG_F(LS_ERROR) << "Unable to get bitmap info. Error = " |
132 << GetLastError(); | 132 << GetLastError(); |
133 return NULL; | 133 return nullptr; |
134 } | 134 } |
135 | 135 |
136 int width = bitmap_info.bmWidth; | 136 int width = bitmap_info.bmWidth; |
137 int height = bitmap_info.bmHeight; | 137 int height = bitmap_info.bmHeight; |
138 std::unique_ptr<uint32_t[]> mask_data(new uint32_t[width * height]); | 138 std::unique_ptr<uint32_t[]> mask_data(new uint32_t[width * height]); |
139 | 139 |
140 // Get pixel data from |scoped_mask| converting it to 32bpp along the way. | 140 // Get pixel data from |scoped_mask| converting it to 32bpp along the way. |
141 // GetDIBits() sets the alpha component of every pixel to 0. | 141 // GetDIBits() sets the alpha component of every pixel to 0. |
142 BITMAPV5HEADER bmi = {0}; | 142 BITMAPV5HEADER bmi = {0}; |
143 bmi.bV5Size = sizeof(bmi); | 143 bmi.bV5Size = sizeof(bmi); |
144 bmi.bV5Width = width; | 144 bmi.bV5Width = width; |
145 bmi.bV5Height = -height; // request a top-down bitmap. | 145 bmi.bV5Height = -height; // request a top-down bitmap. |
146 bmi.bV5Planes = 1; | 146 bmi.bV5Planes = 1; |
147 bmi.bV5BitCount = kBytesPerPixel * 8; | 147 bmi.bV5BitCount = kBytesPerPixel * 8; |
148 bmi.bV5Compression = BI_RGB; | 148 bmi.bV5Compression = BI_RGB; |
149 bmi.bV5AlphaMask = 0xff000000; | 149 bmi.bV5AlphaMask = 0xff000000; |
150 bmi.bV5CSType = LCS_WINDOWS_COLOR_SPACE; | 150 bmi.bV5CSType = LCS_WINDOWS_COLOR_SPACE; |
151 bmi.bV5Intent = LCS_GM_BUSINESS; | 151 bmi.bV5Intent = LCS_GM_BUSINESS; |
152 if (!GetDIBits(dc, | 152 if (!GetDIBits(dc, |
153 scoped_mask, | 153 scoped_mask, |
154 0, | 154 0, |
155 height, | 155 height, |
156 mask_data.get(), | 156 mask_data.get(), |
157 reinterpret_cast<BITMAPINFO*>(&bmi), | 157 reinterpret_cast<BITMAPINFO*>(&bmi), |
158 DIB_RGB_COLORS)) { | 158 DIB_RGB_COLORS)) { |
159 LOG_F(LS_ERROR) << "Unable to get bitmap bits. Error = " | 159 LOG_F(LS_ERROR) << "Unable to get bitmap bits. Error = " |
160 << GetLastError(); | 160 << GetLastError(); |
161 return NULL; | 161 return nullptr; |
162 } | 162 } |
163 | 163 |
164 uint32_t* mask_plane = mask_data.get(); | 164 uint32_t* mask_plane = mask_data.get(); |
165 std::unique_ptr<DesktopFrame> image( | 165 std::unique_ptr<DesktopFrame> image( |
166 new BasicDesktopFrame(DesktopSize(width, height))); | 166 new BasicDesktopFrame(DesktopSize(width, height))); |
167 bool has_alpha = false; | 167 bool has_alpha = false; |
168 | 168 |
169 if (is_color) { | 169 if (is_color) { |
170 image.reset(new BasicDesktopFrame(DesktopSize(width, height))); | 170 image.reset(new BasicDesktopFrame(DesktopSize(width, height))); |
171 // Get the pixels from the color bitmap. | 171 // Get the pixels from the color bitmap. |
172 if (!GetDIBits(dc, | 172 if (!GetDIBits(dc, |
173 scoped_color, | 173 scoped_color, |
174 0, | 174 0, |
175 height, | 175 height, |
176 image->data(), | 176 image->data(), |
177 reinterpret_cast<BITMAPINFO*>(&bmi), | 177 reinterpret_cast<BITMAPINFO*>(&bmi), |
178 DIB_RGB_COLORS)) { | 178 DIB_RGB_COLORS)) { |
179 LOG_F(LS_ERROR) << "Unable to get bitmap bits. Error = " | 179 LOG_F(LS_ERROR) << "Unable to get bitmap bits. Error = " |
180 << GetLastError(); | 180 << GetLastError(); |
181 return NULL; | 181 return nullptr; |
182 } | 182 } |
183 | 183 |
184 // GetDIBits() does not provide any indication whether the bitmap has alpha | 184 // GetDIBits() does not provide any indication whether the bitmap has alpha |
185 // channel, so we use HasAlphaChannel() below to find it out. | 185 // channel, so we use HasAlphaChannel() below to find it out. |
186 has_alpha = HasAlphaChannel(reinterpret_cast<uint32_t*>(image->data()), | 186 has_alpha = HasAlphaChannel(reinterpret_cast<uint32_t*>(image->data()), |
187 width, width, height); | 187 width, width, height); |
188 } else { | 188 } else { |
189 // For non-color cursors, the mask contains both an AND and an XOR mask and | 189 // For non-color cursors, the mask contains both an AND and an XOR mask and |
190 // the height includes both. Thus, the width is correct, but we need to | 190 // the height includes both. Thus, the width is correct, but we need to |
191 // divide by 2 to get the correct mask height. | 191 // divide by 2 to get the correct mask height. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 // Pre-multiply the resulting pixels since MouseCursor uses premultiplied | 240 // Pre-multiply the resulting pixels since MouseCursor uses premultiplied |
241 // images. | 241 // images. |
242 AlphaMul(reinterpret_cast<uint32_t*>(image->data()), width, height); | 242 AlphaMul(reinterpret_cast<uint32_t*>(image->data()), width, height); |
243 | 243 |
244 return new MouseCursor( | 244 return new MouseCursor( |
245 image.release(), DesktopVector(hotspot_x, hotspot_y)); | 245 image.release(), DesktopVector(hotspot_x, hotspot_y)); |
246 } | 246 } |
247 | 247 |
248 } // namespace webrtc | 248 } // namespace webrtc |
OLD | NEW |