OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "remoting/client/display/gl_render_layer.h" | 5 #include "remoting/client/display/gl_render_layer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "remoting/client/display/gl_canvas.h" | 8 #include "remoting/client/display/gl_canvas.h" |
9 #include "remoting/client/display/gl_helpers.h" | 9 #include "remoting/client/display/gl_helpers.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 int stride) { | 32 int stride) { |
33 for (int i = 0; i < height; i++) { | 33 for (int i = 0; i < height; i++) { |
34 memcpy(dest, source, width * GlRenderLayer::kBytesPerPixel); | 34 memcpy(dest, source, width * GlRenderLayer::kBytesPerPixel); |
35 source += stride; | 35 source += stride; |
36 dest += GlRenderLayer::kBytesPerPixel * width; | 36 dest += GlRenderLayer::kBytesPerPixel * width; |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 GlRenderLayer::GlRenderLayer(int texture_id, GlCanvas* canvas) | 42 GlRenderLayer::GlRenderLayer(int texture_id, Canvas* canvas) |
43 : texture_id_(texture_id), canvas_(canvas) { | 43 : texture_id_(texture_id), canvas_(canvas) { |
44 texture_handle_ = CreateTexture(); | 44 texture_handle_ = CreateTexture(); |
45 buffer_handle_ = CreateBuffer(kVertices, sizeof(kVertices)); | 45 buffer_handle_ = CreateBuffer(kVertices, sizeof(kVertices)); |
46 } | 46 } |
47 | 47 |
48 GlRenderLayer::~GlRenderLayer() { | 48 GlRenderLayer::~GlRenderLayer() { |
49 DCHECK(thread_checker_.CalledOnValidThread()); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
50 glDeleteBuffers(1, &buffer_handle_); | 50 glDeleteBuffers(1, &buffer_handle_); |
51 glDeleteTextures(1, &texture_handle_); | 51 glDeleteTextures(1, &texture_handle_); |
52 } | 52 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 *should_reset_row_length = false; | 139 *should_reset_row_length = false; |
140 | 140 |
141 bool stride_multiple_of_bytes_per_pixel = stride % kBytesPerPixel == 0; | 141 bool stride_multiple_of_bytes_per_pixel = stride % kBytesPerPixel == 0; |
142 bool loosely_packed = !stride_multiple_of_bytes_per_pixel || | 142 bool loosely_packed = !stride_multiple_of_bytes_per_pixel || |
143 (stride > 0 && stride != kBytesPerPixel * width); | 143 (stride > 0 && stride != kBytesPerPixel * width); |
144 | 144 |
145 if (!loosely_packed) { | 145 if (!loosely_packed) { |
146 return data; | 146 return data; |
147 } | 147 } |
148 | 148 |
149 if (stride_multiple_of_bytes_per_pixel && canvas_->GetGlVersion() >= 3) { | 149 if (stride_multiple_of_bytes_per_pixel && canvas_->GetVersion() >= 3) { |
150 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / kBytesPerPixel); | 150 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / kBytesPerPixel); |
151 *should_reset_row_length = true; | 151 *should_reset_row_length = true; |
152 return data; | 152 return data; |
153 } | 153 } |
154 | 154 |
155 // Doesn't support GL_UNPACK_ROW_LENGTH or stride not multiple of | 155 // Doesn't support GL_UNPACK_ROW_LENGTH or stride not multiple of |
156 // kBytesPerPixel. Manually pack the data. | 156 // kBytesPerPixel. Manually pack the data. |
157 int required_size = width * height * kBytesPerPixel; | 157 int required_size = width * height * kBytesPerPixel; |
158 if (update_buffer_size_ < required_size) { | 158 if (update_buffer_size_ < required_size) { |
159 if (required_size < kDefaultUpdateBufferCapacity) { | 159 if (required_size < kDefaultUpdateBufferCapacity) { |
160 update_buffer_size_ = kDefaultUpdateBufferCapacity; | 160 update_buffer_size_ = kDefaultUpdateBufferCapacity; |
161 } else { | 161 } else { |
162 update_buffer_size_ = required_size; | 162 update_buffer_size_ = required_size; |
163 } | 163 } |
164 update_buffer_.reset(new uint8_t[update_buffer_size_]); | 164 update_buffer_.reset(new uint8_t[update_buffer_size_]); |
165 } | 165 } |
166 PackDirtyRegion(update_buffer_.get(), data, width, height, stride); | 166 PackDirtyRegion(update_buffer_.get(), data, width, height, stride); |
167 return update_buffer_.get(); | 167 return update_buffer_.get(); |
168 } | 168 } |
169 | 169 |
170 } // namespace remoting | 170 } // namespace remoting |
OLD | NEW |