Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: remoting/client/gl_render_layer.cc

Issue 2148743005: [Remoting Android] Cursor & Cursor Feedback for OpenGL Renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop Skia dependencies Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gl_render_layer.h" 5 #include "remoting/client/gl_render_layer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "remoting/client/gl_canvas.h" 8 #include "remoting/client/gl_canvas.h"
9 #include "remoting/client/gl_helpers.h" 9 #include "remoting/client/gl_helpers.h"
10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
11 10
12 namespace { 11 namespace {
Sergey Ulanov 2016/07/21 19:28:48 nit: if you put this inside the remoting namespace
Yuwei 2016/07/21 19:53:04 Then they are out of the anonymous namespace? I'm
Sergey Ulanov 2016/07/21 20:14:15 namespace remoting { namespace { void foo() { /
Sergey Ulanov 2016/07/21 20:17:14 See https://google.github.io/styleguide/cppguide.h
Yuwei 2016/07/21 21:44:42 Done.
13 12
14 // Assign texture coordinates to buffers for use in shader program. 13 // Assign texture coordinates to buffers for use in shader program.
15 const float kVertices[] = { 14 const float kVertices[] = {
16 // Points order: upper-left, bottom-left, upper-right, bottom-right. 15 // Points order: upper-left, bottom-left, upper-right, bottom-right.
17 16
18 // Positions to draw the texture on the normalized canvas coordinate. 17 // Positions to draw the texture on the normalized canvas coordinate.
19 0, 0, 0, 1, 1, 0, 1, 1, 18 0, 0, 0, 1, 1, 0, 1, 1,
20 19
21 // Region of the texture to be used (normally the whole texture). 20 // Region of the texture to be used (normally the whole texture).
22 0, 0, 0, 1, 1, 0, 1, 1}; 21 0, 0, 0, 1, 1, 0, 1, 1};
23 22
24 const int kDefaultUpdateBufferCapacity = 23 const int kDefaultUpdateBufferCapacity =
25 2048 * 2048 * webrtc::DesktopFrame::kBytesPerPixel; 24 2048 * 2048 * remoting::GlRenderLayer::kBytesPerPixelRGB32;
26 25
27 } 26 }
28 27
29 namespace remoting { 28 namespace remoting {
30 29
31 GlRenderLayer::GlRenderLayer(int texture_id, GlCanvas* canvas) 30 GlRenderLayer::GlRenderLayer(int texture_id, GlCanvas* canvas)
32 : texture_id_(texture_id), canvas_(canvas) { 31 : texture_id_(texture_id), canvas_(canvas) {
33 texture_handle_ = CreateTexture(); 32 texture_handle_ = CreateTexture();
34 buffer_handle_ = CreateBuffer(kVertices, sizeof(kVertices)); 33 buffer_handle_ = CreateBuffer(kVertices, sizeof(kVertices));
35 } 34 }
36 35
37 GlRenderLayer::~GlRenderLayer() { 36 GlRenderLayer::~GlRenderLayer() {
38 DCHECK(thread_checker_.CalledOnValidThread()); 37 DCHECK(thread_checker_.CalledOnValidThread());
39 glDeleteBuffers(1, &buffer_handle_); 38 glDeleteBuffers(1, &buffer_handle_);
40 glDeleteTextures(1, &texture_handle_); 39 glDeleteTextures(1, &texture_handle_);
41 } 40 }
42 41
43 void GlRenderLayer::SetTexture(const uint8_t* texture, int width, int height) { 42 void GlRenderLayer::SetTexture(const uint8_t* texture, int width, int height) {
44 DCHECK(thread_checker_.CalledOnValidThread()); 43 DCHECK(thread_checker_.CalledOnValidThread());
45 CHECK(width > 0 && height > 0); 44 CHECK(width > 0 && height > 0);
46 texture_set_ = true; 45 texture_set_ = true;
47 glActiveTexture(GL_TEXTURE0 + texture_id_); 46 glActiveTexture(GL_TEXTURE0 + texture_id_);
48 glBindTexture(GL_TEXTURE_2D, texture_handle_); 47 glBindTexture(GL_TEXTURE_2D, texture_handle_);
49 48
50 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, 49 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
51 GL_UNSIGNED_BYTE, texture); 50 GL_UNSIGNED_BYTE, texture);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
54 55
55 glBindTexture(GL_TEXTURE_2D, 0); 56 glBindTexture(GL_TEXTURE_2D, 0);
56 } 57 }
57 58
58 void PackDirtyRegion(uint8_t* dest, 59 void PackDirtyRegion(uint8_t* dest,
Sergey Ulanov 2016/07/21 19:28:48 Move this to the anonymous namespace.
Yuwei 2016/07/21 21:44:42 Done.
59 const uint8_t* source, 60 const uint8_t* source,
60 int width, 61 int width,
61 int height, 62 int height,
62 int stride) { 63 int stride) {
63 for (int i = 0; i < height; i++) { 64 for (int i = 0; i < height; i++) {
64 memcpy(dest, source, width * webrtc::DesktopFrame::kBytesPerPixel); 65 memcpy(dest, source, width * GlRenderLayer::kBytesPerPixelRGB32);
65 source += stride; 66 source += stride;
66 dest += webrtc::DesktopFrame::kBytesPerPixel * width; 67 dest += GlRenderLayer::kBytesPerPixelRGB32 * width;
67 } 68 }
68 } 69 }
69 70
70 void GlRenderLayer::UpdateTexture(const uint8_t* subtexture, 71 void GlRenderLayer::UpdateTexture(const uint8_t* subtexture,
71 int offset_x, 72 int offset_x,
72 int offset_y, 73 int offset_y,
73 int width, 74 int width,
74 int height, 75 int height,
75 int stride) { 76 int stride) {
76 DCHECK(thread_checker_.CalledOnValidThread()); 77 DCHECK(thread_checker_.CalledOnValidThread());
77 DCHECK(texture_set_); 78 DCHECK(texture_set_);
78 DCHECK(width > 0 && height > 0); 79 DCHECK(width > 0 && height > 0);
79 glActiveTexture(GL_TEXTURE0 + texture_id_); 80 glActiveTexture(GL_TEXTURE0 + texture_id_);
80 glBindTexture(GL_TEXTURE_2D, texture_handle_); 81 glBindTexture(GL_TEXTURE_2D, texture_handle_);
81 82
82 bool stride_multiple_of_bytes_per_pixel = 83 bool stride_multiple_of_bytes_per_pixel = stride % kBytesPerPixelRGB32 == 0;
83 stride % webrtc::DesktopFrame::kBytesPerPixel == 0;
84 bool loosely_packed = 84 bool loosely_packed =
85 !stride_multiple_of_bytes_per_pixel || 85 !stride_multiple_of_bytes_per_pixel ||
86 (stride > 0 && stride != webrtc::DesktopFrame::kBytesPerPixel * width); 86 (stride > 0 && stride != kBytesPerPixelRGB32 * width);
87 87
88 const void* buffer_to_update = subtexture; 88 const void* buffer_to_update = subtexture;
89 89
90 if (loosely_packed) { 90 if (loosely_packed) {
91 if (stride_multiple_of_bytes_per_pixel && canvas_->GetGlVersion() >= 3) { 91 if (stride_multiple_of_bytes_per_pixel && canvas_->GetGlVersion() >= 3) {
92 glPixelStorei(GL_UNPACK_ROW_LENGTH, 92 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / kBytesPerPixelRGB32);
93 stride / webrtc::DesktopFrame::kBytesPerPixel);
94 } else { 93 } else {
95 // Doesn't support GL_UNPACK_ROW_LENGTH or stride not multiple of 94 // Doesn't support GL_UNPACK_ROW_LENGTH or stride not multiple of
96 // kBytesPerPixel. Manually pack the data. 95 // kBytesPerPixel. Manually pack the data.
97 int required_size = width * height * webrtc::DesktopFrame::kBytesPerPixel; 96 int required_size = width * height * kBytesPerPixelRGB32;
98 if (update_buffer_size_ < required_size) { 97 if (update_buffer_size_ < required_size) {
99 if (required_size < kDefaultUpdateBufferCapacity) { 98 if (required_size < kDefaultUpdateBufferCapacity) {
100 update_buffer_size_ = kDefaultUpdateBufferCapacity; 99 update_buffer_size_ = kDefaultUpdateBufferCapacity;
101 } else { 100 } else {
102 update_buffer_size_ = required_size; 101 update_buffer_size_ = required_size;
103 } 102 }
104 update_buffer_.reset(new uint8_t[update_buffer_size_]); 103 update_buffer_.reset(new uint8_t[update_buffer_size_]);
105 } 104 }
106 PackDirtyRegion(update_buffer_.get(), subtexture, width, height, stride); 105 PackDirtyRegion(update_buffer_.get(), subtexture, width, height, stride);
107 buffer_to_update = update_buffer_.get(); 106 buffer_to_update = update_buffer_.get();
(...skipping 19 matching lines...) Expand all
127 126
128 void GlRenderLayer::SetTextureVisibleArea( 127 void GlRenderLayer::SetTextureVisibleArea(
129 const std::array<float, 8>& positions) { 128 const std::array<float, 8>& positions) {
130 DCHECK(thread_checker_.CalledOnValidThread()); 129 DCHECK(thread_checker_.CalledOnValidThread());
131 glBindBuffer(GL_ARRAY_BUFFER, buffer_handle_); 130 glBindBuffer(GL_ARRAY_BUFFER, buffer_handle_);
132 glBufferSubData(GL_ARRAY_BUFFER, sizeof(kVertices) / 2, sizeof(kVertices) / 2, 131 glBufferSubData(GL_ARRAY_BUFFER, sizeof(kVertices) / 2, sizeof(kVertices) / 2,
133 positions.data()); 132 positions.data());
134 glBindBuffer(GL_ARRAY_BUFFER, 0); 133 glBindBuffer(GL_ARRAY_BUFFER, 0);
135 } 134 }
136 135
137 void GlRenderLayer::Draw() { 136 void GlRenderLayer::Draw(float alpha_multiplier) {
138 DCHECK(thread_checker_.CalledOnValidThread()); 137 DCHECK(thread_checker_.CalledOnValidThread());
139 DCHECK(texture_set_); 138 DCHECK(texture_set_);
140 canvas_->DrawTexture(texture_id_, texture_handle_, buffer_handle_); 139 canvas_->DrawTexture(texture_id_, texture_handle_, buffer_handle_,
140 alpha_multiplier);
141 } 141 }
142 142
143 } // namespace remoting 143 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698