summaryrefslogtreecommitdiffstats
path: root/media/video
diff options
context:
space:
mode:
authoralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-26 01:51:32 +0000
committeralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-26 01:51:32 +0000
commit3545639f849e3eb78ddce07bb1103c6bb17369cb (patch)
tree440610f68888df28b3878bb81c55036e649a1272 /media/video
parent014eb20106c8a775ebbd4c8bc258c1c42f59c928 (diff)
downloadchromium_src-3545639f849e3eb78ddce07bb1103c6bb17369cb.zip
chromium_src-3545639f849e3eb78ddce07bb1103c6bb17369cb.tar.gz
chromium_src-3545639f849e3eb78ddce07bb1103c6bb17369cb.tar.bz2
Do not use division in ScreenCapturerLinux::SlowBlit().
BUG=174381 Review URL: https://chromiumcodereview.appspot.com/12315088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/video')
-rw-r--r--media/video/capture/screen/linux/x_server_pixel_buffer.cc16
-rw-r--r--media/video/capture/screen/linux/x_server_pixel_buffer.h4
-rw-r--r--media/video/capture/screen/screen_capturer_linux.cc71
3 files changed, 51 insertions, 40 deletions
diff --git a/media/video/capture/screen/linux/x_server_pixel_buffer.cc b/media/video/capture/screen/linux/x_server_pixel_buffer.cc
index 99d454c..11d6220 100644
--- a/media/video/capture/screen/linux/x_server_pixel_buffer.cc
+++ b/media/video/capture/screen/linux/x_server_pixel_buffer.cc
@@ -256,20 +256,4 @@ int XServerPixelBuffer::GetGreenMask() const {
return x_image_->green_mask;
}
-int XServerPixelBuffer::GetRedShift() const {
- return ffs(x_image_->red_mask) - 1;
-}
-
-int XServerPixelBuffer::GetBlueShift() const {
- return ffs(x_image_->blue_mask) - 1;
-}
-
-int XServerPixelBuffer::GetGreenShift() const {
- return ffs(x_image_->green_mask) - 1;
-}
-
-bool XServerPixelBuffer::IsRgb() const {
- return GetRedShift() == 16 && GetGreenShift() == 8 && GetBlueShift() == 0;
-}
-
} // namespace media
diff --git a/media/video/capture/screen/linux/x_server_pixel_buffer.h b/media/video/capture/screen/linux/x_server_pixel_buffer.h
index e4d2f4b..a565a73 100644
--- a/media/video/capture/screen/linux/x_server_pixel_buffer.h
+++ b/media/video/capture/screen/linux/x_server_pixel_buffer.h
@@ -57,10 +57,6 @@ class XServerPixelBuffer {
int GetRedMask() const;
int GetBlueMask() const;
int GetGreenMask() const;
- int GetRedShift() const;
- int GetBlueShift() const;
- int GetGreenShift() const;
- bool IsRgb() const;
private:
void InitShm(int screen);
diff --git a/media/video/capture/screen/screen_capturer_linux.cc b/media/video/capture/screen/screen_capturer_linux.cc
index ed45d05..2f4559b 100644
--- a/media/video/capture/screen/screen_capturer_linux.cc
+++ b/media/video/capture/screen/screen_capturer_linux.cc
@@ -103,6 +103,11 @@ class ScreenCapturerLinux : public ScreenCapturer {
const SkIRect& rect,
ScreenCaptureData* capture_data);
+ // Returns the number of bits |mask| has to be shifted left so its last
+ // (most-significant) bit set becomes the most-significant bit of the word.
+ // When |mask| is 0 the function returns 31.
+ static uint32 GetRgbShift(uint32 mask);
+
Delegate* delegate_;
// X11 graphics context.
@@ -508,9 +513,11 @@ void ScreenCapturerLinux::CaptureRect(const SkIRect& rect,
ScreenCaptureData* capture_data) {
uint8* image = x_server_pixel_buffer_.CaptureRect(rect);
int depth = x_server_pixel_buffer_.GetDepth();
- int bpp = x_server_pixel_buffer_.GetBitsPerPixel();
- bool is_rgb = x_server_pixel_buffer_.IsRgb();
- if ((depth == 24 || depth == 32) && bpp == 32 && is_rgb) {
+ if ((depth == 24 || depth == 32) &&
+ x_server_pixel_buffer_.GetBitsPerPixel() == 32 &&
+ x_server_pixel_buffer_.GetRedMask() == 0xff0000 &&
+ x_server_pixel_buffer_.GetGreenMask() == 0xff00 &&
+ x_server_pixel_buffer_.GetBlueMask() == 0xff) {
DVLOG(3) << "Fast blitting";
FastBlit(image, rect, capture_data);
} else {
@@ -543,16 +550,13 @@ void ScreenCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect,
int dst_x = rect.fLeft, dst_y = rect.fTop;
int width = rect.width(), height = rect.height();
- unsigned int red_mask = x_server_pixel_buffer_.GetRedMask();
- unsigned int blue_mask = x_server_pixel_buffer_.GetBlueMask();
- unsigned int green_mask = x_server_pixel_buffer_.GetGreenMask();
- unsigned int red_shift = x_server_pixel_buffer_.GetRedShift();
- unsigned int blue_shift = x_server_pixel_buffer_.GetBlueShift();
- unsigned int green_shift = x_server_pixel_buffer_.GetGreenShift();
+ uint32 red_mask = x_server_pixel_buffer_.GetRedMask();
+ uint32 green_mask = x_server_pixel_buffer_.GetGreenMask();
+ uint32 blue_mask = x_server_pixel_buffer_.GetBlueMask();
- unsigned int max_red = red_mask >> red_shift;
- unsigned int max_blue = blue_mask >> blue_shift;
- unsigned int max_green = green_mask >> green_shift;
+ uint32 red_shift = GetRgbShift(red_mask);
+ uint32 green_shift = GetRgbShift(green_mask);
+ uint32 blue_shift = GetRgbShift(blue_mask);
unsigned int bits_per_pixel = x_server_pixel_buffer_.GetBitsPerPixel();
@@ -562,29 +566,56 @@ void ScreenCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect,
// TODO(hclam): Optimize, perhaps using MMX code or by converting to
// YUV directly
for (int y = 0; y < height; y++) {
- uint32_t* dst_pos_32 = reinterpret_cast<uint32_t*>(dst_pos);
- uint32_t* src_pos_32 = reinterpret_cast<uint32_t*>(src_pos);
- uint16_t* src_pos_16 = reinterpret_cast<uint16_t*>(src_pos);
+ uint32* dst_pos_32 = reinterpret_cast<uint32*>(dst_pos);
+ uint32* src_pos_32 = reinterpret_cast<uint32*>(src_pos);
+ uint16* src_pos_16 = reinterpret_cast<uint16*>(src_pos);
for (int x = 0; x < width; x++) {
// Dereference through an appropriately-aligned pointer.
- uint32_t pixel;
+ uint32 pixel;
if (bits_per_pixel == 32)
pixel = src_pos_32[x];
else if (bits_per_pixel == 16)
pixel = src_pos_16[x];
else
pixel = src_pos[x];
- uint32_t r = (((pixel & red_mask) >> red_shift) * 255) / max_red;
- uint32_t b = (((pixel & blue_mask) >> blue_shift) * 255) / max_blue;
- uint32_t g = (((pixel & green_mask) >> green_shift) * 255) / max_green;
+ uint32 r = (pixel & red_mask) << red_shift;
+ uint32 g = (pixel & green_mask) << green_shift;
+ uint32 b = (pixel & blue_mask) << blue_shift;
+
// Write as 32-bit RGB.
- dst_pos_32[x] = r << 16 | g << 8 | b;
+ dst_pos_32[x] = ((r >> 8) & 0xff0000) | ((g >> 16) & 0xff00) |
+ ((b >> 24) & 0xff);
}
dst_pos += capture_data->stride();
src_pos += src_stride;
}
}
+// static
+uint32 ScreenCapturerLinux::GetRgbShift(uint32 mask) {
+ int shift = 0;
+ if ((mask & 0xffff0000u) == 0) {
+ mask <<= 16;
+ shift += 16;
+ }
+ if ((mask & 0xff000000u) == 0) {
+ mask <<= 8;
+ shift += 8;
+ }
+ if ((mask & 0xf0000000u) == 0) {
+ mask <<= 4;
+ shift += 4;
+ }
+ if ((mask & 0xc0000000u) == 0) {
+ mask <<= 2;
+ shift += 2;
+ }
+ if ((mask & 0x80000000u) == 0)
+ shift += 1;
+
+ return shift;
+}
+
} // namespace
scoped_refptr<SharedBuffer> ScreenCapturer::Delegate::CreateSharedBuffer(