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

Side by Side Diff: content/browser/media/capture/cursor_renderer.cc

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: win fix after rebase Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/browser/media/capture/cursor_renderer.h" 5 #include "content/browser/media/capture/cursor_renderer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 139 return;
140 140
141 DCHECK(target); 141 DCHECK(target);
142 142
143 gfx::Rect rect = gfx::IntersectRects( 143 gfx::Rect rect = gfx::IntersectRects(
144 gfx::Rect(scaled_cursor_bitmap_.width(), scaled_cursor_bitmap_.height()) + 144 gfx::Rect(scaled_cursor_bitmap_.width(), scaled_cursor_bitmap_.height()) +
145 gfx::Vector2d(cursor_position_in_frame_.x(), 145 gfx::Vector2d(cursor_position_in_frame_.x(),
146 cursor_position_in_frame_.y()), 146 cursor_position_in_frame_.y()),
147 target->visible_rect()); 147 target->visible_rect());
148 148
149 scaled_cursor_bitmap_.lockPixels();
150 for (int y = rect.y(); y < rect.bottom(); ++y) { 149 for (int y = rect.y(); y < rect.bottom(); ++y) {
151 int cursor_y = y - cursor_position_in_frame_.y(); 150 int cursor_y = y - cursor_position_in_frame_.y();
152 uint8_t* yplane = target->data(media::VideoFrame::kYPlane) + 151 uint8_t* yplane = target->data(media::VideoFrame::kYPlane) +
153 y * target->row_bytes(media::VideoFrame::kYPlane); 152 y * target->row_bytes(media::VideoFrame::kYPlane);
154 uint8_t* uplane = target->data(media::VideoFrame::kUPlane) + 153 uint8_t* uplane = target->data(media::VideoFrame::kUPlane) +
155 (y / 2) * target->row_bytes(media::VideoFrame::kUPlane); 154 (y / 2) * target->row_bytes(media::VideoFrame::kUPlane);
156 uint8_t* vplane = target->data(media::VideoFrame::kVPlane) + 155 uint8_t* vplane = target->data(media::VideoFrame::kVPlane) +
157 (y / 2) * target->row_bytes(media::VideoFrame::kVPlane); 156 (y / 2) * target->row_bytes(media::VideoFrame::kVPlane);
158 for (int x = rect.x(); x < rect.right(); ++x) { 157 for (int x = rect.x(); x < rect.right(); ++x) {
159 int cursor_x = x - cursor_position_in_frame_.x(); 158 int cursor_x = x - cursor_position_in_frame_.x();
(...skipping 10 matching lines...) Expand all
170 if ((x % 2 == 0) && (y % 2 == 0)) { 169 if ((x % 2 == 0) && (y % 2 == 0)) {
171 int color_u = clip_byte( 170 int color_u = clip_byte(
172 ((color_r * -38 + color_g * -74 + color_b * 112 + 128) >> 8) + 128); 171 ((color_r * -38 + color_g * -74 + color_b * 112 + 128) >> 8) + 128);
173 int color_v = clip_byte( 172 int color_v = clip_byte(
174 ((color_r * 112 + color_g * -94 + color_b * -18 + 128) >> 8) + 128); 173 ((color_r * 112 + color_g * -94 + color_b * -18 + 128) >> 8) + 128);
175 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); 174 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]);
176 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); 175 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]);
177 } 176 }
178 } 177 }
179 } 178 }
180 scaled_cursor_bitmap_.unlockPixels();
181 } 179 }
182 180
183 void CursorRenderer::OnMouseMoved(const gfx::Point& location, 181 void CursorRenderer::OnMouseMoved(const gfx::Point& location,
184 base::TimeTicks timestamp) { 182 base::TimeTicks timestamp) {
185 if (!cursor_displayed_) { 183 if (!cursor_displayed_) {
186 if (std::abs(location.x() - last_mouse_position_x_) > MIN_MOVEMENT_PIXELS || 184 if (std::abs(location.x() - last_mouse_position_x_) > MIN_MOVEMENT_PIXELS ||
187 std::abs(location.y() - last_mouse_position_y_) > MIN_MOVEMENT_PIXELS) 185 std::abs(location.y() - last_mouse_position_y_) > MIN_MOVEMENT_PIXELS)
188 cursor_displayed_ = true; 186 cursor_displayed_ = true;
189 } 187 }
190 188
191 if (cursor_displayed_) { 189 if (cursor_displayed_) {
192 last_mouse_movement_timestamp_ = timestamp; 190 last_mouse_movement_timestamp_ = timestamp;
193 last_mouse_position_x_ = location.x(); 191 last_mouse_position_x_ = location.x();
194 last_mouse_position_y_ = location.y(); 192 last_mouse_position_y_ = location.y();
195 } 193 }
196 } 194 }
197 195
198 void CursorRenderer::OnMouseClicked(const gfx::Point& location, 196 void CursorRenderer::OnMouseClicked(const gfx::Point& location,
199 base::TimeTicks timestamp) { 197 base::TimeTicks timestamp) {
200 cursor_displayed_ = true; 198 cursor_displayed_ = true;
201 last_mouse_movement_timestamp_ = timestamp; 199 last_mouse_movement_timestamp_ = timestamp;
202 last_mouse_position_x_ = location.x(); 200 last_mouse_position_x_ = location.x();
203 last_mouse_position_y_ = location.y(); 201 last_mouse_position_y_ = location.y();
204 } 202 }
205 203
206 } // namespace content 204 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698