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..d50ed4bc64a0e977dbf5475810b4dd6ad6422554 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,38 @@ 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<std::vector<char>>& |
|
dmazzoni
2016/10/11 17:15:39
I'd probably indent it like this:
void BrailleCon
ultimatedbz
2016/10/16 01:12:38
Cool! didn't know about git cl format!
ultimatedbz
2016/10/16 01:12:38
Done.
|
| + cells) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| if (connection_ && connection_->Connected()) { |
| - size_t size; |
| - if (!connection_->GetDisplaySize(&size)) { |
| + unsigned int rows, columns; |
| + if (!connection_->GetDisplaySize(&rows, &columns)) { |
| 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<std::vector<unsigned char>> sizedCells(rows, |
|
dmazzoni
2016/10/11 17:15:39
sizedCells -> sized_cells
ultimatedbz
2016/10/16 01:12:38
Done.
|
| + std::vector<unsigned char>(columns)); |
| + for (unsigned int i = 0; i < rows; i++) { |
|
dmazzoni
2016/10/11 17:15:39
I think you need to handle the case where cells.si
ultimatedbz
2016/10/16 01:12:38
Done.
|
| + std::memcpy(&sizedCells[i][0], cells[i].data(), std::min(cells[i].size(), |
| + (unsigned long)columns)); |
|
dmazzoni
2016/10/11 17:15:39
Use a C++-style cast, and I think size_t is the co
ultimatedbz
2016/10/16 01:12:38
Done.
|
| + if (columns > cells[i].size()) |
|
dmazzoni
2016/10/11 17:15:39
For readability, you need braces {} if there's mor
ultimatedbz
2016/10/16 01:12:38
Done.
|
| + std::fill(sizedCells[i].begin() + cells[i].size(), sizedCells[i].end(), |
| + 0); |
| + } |
| + // For now we are sending the whole 2D vector over. |
| + if (!connection_->WriteDots(sizedCells)) |
| Disconnect(); |
| } |
| } |