Chromium Code Reviews| Index: chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc |
| diff --git a/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc b/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc |
| index 78e84507d677a81fe3bf0b41b9dcd1ae20590738..e8ecff048e50284ecdf33896c6a2dd30f43393b1 100644 |
| --- a/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc |
| +++ b/chrome/browser/extensions/api/braille_display_private/braille_controller_brlapi.cc |
| @@ -87,29 +87,39 @@ std::unique_ptr<DisplayState> BrailleControllerImpl::GetDisplayState() { |
| StartConnecting(); |
| std::unique_ptr<DisplayState> display_state(new DisplayState); |
| if (connection_.get() && connection_->Connected()) { |
| - size_t size; |
| - if (!connection_->GetDisplaySize(&size)) { |
| + unsigned int columns, rows; |
| + if (!connection_->GetDisplaySize(&columns, &rows)) { |
| Disconnect(); |
| - } else if (size > 0) { // size == 0 means no display present. |
| + } else if (rows * columns > 0) { |
| + // rows * columns == 0 means no display present. |
| display_state->available = true; |
| - display_state->text_cell_count.reset(new int(size)); |
| + display_state->text_column_count.reset(new int(columns)); |
| + display_state->text_row_count.reset(new int(rows)); |
| } |
| } |
| return display_state; |
| } |
| -void BrailleControllerImpl::WriteDots(const std::vector<char>& cells) { |
| +void BrailleControllerImpl::WriteDots(const std::vector<char>& cells, |
| + unsigned int oldCols, |
|
dmazzoni
2016/10/17 05:13:05
"old" is a little confusing to me, I know what you
ultimatedbz
2016/10/17 21:49:46
Done.
|
| + unsigned int oldRows) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| if (connection_ && connection_->Connected()) { |
| - size_t size; |
| - if (!connection_->GetDisplaySize(&size)) { |
| + // Row count and column count of current display. |
| + unsigned int rows, columns; |
| + if (!connection_->GetDisplaySize(&columns, &rows)) { |
| Disconnect(); |
| } |
| - std::vector<unsigned char> sizedCells(size); |
| - std::memcpy(&sizedCells[0], cells.data(), std::min(cells.size(), size)); |
| - if (size > cells.size()) |
| - std::fill(sizedCells.begin() + cells.size(), sizedCells.end(), 0); |
| - if (!connection_->WriteDots(&sizedCells[0])) |
| + std::vector<unsigned char> sized_cells(rows * columns); |
| + for (unsigned int i = 0; i < rows; i++) { |
| + for (unsigned int j = 0; j < columns; j++) { |
| + // If we go out of the bounds of the old display size, pad with 0. |
| + sized_cells[i * columns + j] = |
| + (i >= oldRows || j >= oldCols) ? 0 : cells[i * oldCols + j]; |
| + } |
| + } |
| + |
| + if (!connection_->WriteDots(sized_cells)) |
| Disconnect(); |
| } |
| } |