| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/client/plugin/empty_cursor_filter.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "remoting/proto/control.pb.h" | |
| 10 | |
| 11 namespace remoting { | |
| 12 | |
| 13 protocol::CursorShapeInfo EmptyCursorShape() { | |
| 14 protocol::CursorShapeInfo empty_shape; | |
| 15 empty_shape.set_data(std::string()); | |
| 16 empty_shape.set_width(0); | |
| 17 empty_shape.set_height(0); | |
| 18 empty_shape.set_hotspot_x(0); | |
| 19 empty_shape.set_hotspot_y(0); | |
| 20 return empty_shape; | |
| 21 } | |
| 22 | |
| 23 bool IsCursorShapeEmpty(const protocol::CursorShapeInfo& cursor_shape) { | |
| 24 return cursor_shape.width() <= 0 || cursor_shape.height() <= 0; | |
| 25 } | |
| 26 | |
| 27 EmptyCursorFilter::EmptyCursorFilter(protocol::CursorShapeStub* cursor_stub) | |
| 28 : cursor_stub_(cursor_stub) { | |
| 29 } | |
| 30 | |
| 31 EmptyCursorFilter::~EmptyCursorFilter() {} | |
| 32 | |
| 33 namespace { | |
| 34 | |
| 35 #if defined(ARCH_CPU_LITTLE_ENDIAN) | |
| 36 const uint32_t kPixelAlphaMask = 0xff000000; | |
| 37 #else // !defined(ARCH_CPU_LITTLE_ENDIAN) | |
| 38 const uint32_t kPixelAlphaMask = 0x000000ff; | |
| 39 #endif // !defined(ARCH_CPU_LITTLE_ENDIAN) | |
| 40 | |
| 41 // Returns true if |pixel| is not completely transparent. | |
| 42 bool IsVisiblePixel(uint32_t pixel) { | |
| 43 return (pixel & kPixelAlphaMask) != 0; | |
| 44 } | |
| 45 | |
| 46 // Returns true if there is at least one visible pixel in the given range. | |
| 47 bool IsVisibleRow(const uint32_t* begin, const uint32_t* end) { | |
| 48 return std::find_if(begin, end, &IsVisiblePixel) != end; | |
| 49 } | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 53 void EmptyCursorFilter::SetCursorShape( | |
| 54 const protocol::CursorShapeInfo& cursor_shape) { | |
| 55 const uint32_t* src_row_data = reinterpret_cast<const uint32_t*>( | |
| 56 cursor_shape.data().data()); | |
| 57 const uint32_t* src_row_data_end = | |
| 58 src_row_data + cursor_shape.width() * cursor_shape.height(); | |
| 59 if (IsVisibleRow(src_row_data, src_row_data_end)) { | |
| 60 cursor_stub_->SetCursorShape(cursor_shape); | |
| 61 return; | |
| 62 } | |
| 63 cursor_stub_->SetCursorShape(EmptyCursorShape()); | |
| 64 } | |
| 65 | |
| 66 } // namespace remoting | |
| OLD | NEW |