OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/ios/display/gl_demo_screen.h" | |
6 | |
7 #import <Foundation/Foundation.h> | |
Yuwei
2017/01/26 20:18:25
Is core foundation used in this file?
nicholss
2017/01/26 23:46:44
Done.
| |
8 | |
9 #include "base/logging.h" | |
10 #include "remoting/client/display/canvas.h" | |
11 #include "remoting/client/display/gl_math.h" | |
12 | |
13 namespace remoting { | |
14 | |
15 namespace { | |
16 | |
17 const GLfloat square[] = {-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0}; | |
18 | |
19 const GLchar* fragmentShaderSource = | |
20 "precision mediump float;" | |
21 "void main() {" | |
22 " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);" | |
23 "} "; | |
24 | |
25 const GLchar* vertexShaderSource = | |
26 "precision mediump float;" | |
27 "attribute vec4 a_position;" | |
28 "void main() {" | |
29 " gl_Position = a_position;" | |
30 "}"; | |
31 | |
32 const GLchar* a_position = "a_position"; | |
33 | |
34 } // namespace | |
35 | |
36 // This is a demo screen that can be added to the renderer to test the drawable | |
37 // integration. This will draw an expanding checkerboard pattern to the screen. | |
38 GlDemoScreen::GlDemoScreen() : weak_factory_(this) {} | |
39 | |
40 GlDemoScreen::~GlDemoScreen() {} | |
41 | |
42 void GlDemoScreen::SetCanvas(base::WeakPtr<Canvas> canvas) { | |
43 canvas_ = canvas; | |
Yuwei
2017/01/26 20:18:25
On Android, SetCanvas(null) will be called once th
nicholss
2017/01/26 23:46:44
WeakPtr deals with this case.
Yuwei
2017/01/26 23:55:18
When will the shaders and program below get destro
nicholss
2017/01/27 00:51:05
Not bothering with cleanup on a demo.
Yuwei
2017/01/27 01:11:48
I agree that a demo may not need to cleanup, but I
| |
44 | |
45 // Create and compile vertex shader. | |
46 GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); | |
47 glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); | |
48 glCompileShader(vertexShader); | |
49 | |
50 // Create and compile fragment shader. | |
51 GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); | |
52 glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); | |
53 glCompileShader(fragmentShader); | |
54 | |
55 // Create and link program. | |
56 program_ = glCreateProgram(); | |
57 glAttachShader(program_, vertexShader); | |
58 glAttachShader(program_, fragmentShader); | |
59 glLinkProgram(program_); | |
60 } | |
61 | |
62 int GlDemoScreen::GetZIndex() { | |
63 return Drawable::DESKTOP + 1; | |
joedow
2017/01/26 21:30:23
nit: This would be better cleaner if it were a con
| |
64 } | |
65 | |
66 bool GlDemoScreen::Draw() { | |
67 if (!canvas_) { | |
68 return false; | |
69 } | |
70 | |
71 // TODO(nicholss): width and height should be dynamic based on the canvas. | |
72 int width = 640; | |
73 int height = 1024; | |
74 square_size_++; | |
75 if (square_size_ > 300) { | |
76 square_size_ = 1; | |
77 } | |
78 | |
79 // Set the viewport. | |
80 glViewport(0, 0, width, height); | |
81 | |
82 // Clear. | |
83 glClearColor(0, 1, 0, 1); | |
84 glClear(GL_COLOR_BUFFER_BIT); | |
85 | |
86 // Use program. | |
87 glUseProgram(program_); | |
88 | |
89 int skip = 0; | |
90 for (int i = 0; i < width; i += square_size_) { | |
91 if (skip == square_size_) { | |
92 skip = 0; | |
93 } else { | |
94 skip = square_size_; | |
95 } | |
96 for (int j = skip; j < height; j += square_size_ * 2) { | |
97 glViewport(i, j, square_size_, square_size_); | |
98 | |
99 // Send geometry to vertex shader. | |
100 GLuint aPosition = glGetAttribLocation(program_, a_position); | |
Yuwei
2017/01/26 20:18:25
|a_position| just stores the name of the variable
nicholss
2017/01/26 23:46:44
this is just a demo.
| |
101 | |
102 glVertexAttribPointer(aPosition, 2, GL_FLOAT, GL_FALSE, 0, square); | |
103 glEnableVertexAttribArray(aPosition); | |
104 | |
105 // Draw. | |
106 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | |
107 } | |
108 } | |
109 return true; | |
110 } | |
111 | |
112 base::WeakPtr<Drawable> GlDemoScreen::GetWeakPtr() { | |
113 DCHECK(thread_checker_.CalledOnValidThread()); | |
Yuwei
2017/01/26 20:18:25
Maybe rename thread_checker_ to get_weak_ptr_threa
joedow
2017/01/26 21:30:23
thread_checker_ is pretty standard in our codebase
Yuwei
2017/01/26 21:33:53
It implies the thread being checked is the thread
joedow
2017/01/26 21:40:51
ThreadChecker binds to the thread it is created on
| |
114 return weak_factory_.GetWeakPtr(); | |
115 } | |
116 | |
117 } // namespace remoting | |
OLD | NEW |