| Index: remoting/client/opengl/gl_render_layer.cc
|
| diff --git a/remoting/client/opengl/gl_render_layer.cc b/remoting/client/opengl/gl_render_layer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8673b021f05f92701736a6cda750097e82c8b23e
|
| --- /dev/null
|
| +++ b/remoting/client/opengl/gl_render_layer.cc
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "remoting/client/opengl/gl_render_layer.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "remoting/client/opengl/gl_canvas.h"
|
| +#include "remoting/client/opengl/gl_helpers.h"
|
| +
|
| +namespace {
|
| +
|
| +// Assign texture coordinates to buffers for use in shader program.
|
| +const float kVertices[] = {
|
| + // Points order: upper-left, bottom-left, upper-right, bottom-right.
|
| +
|
| + // Positions to draw the texture on the normalized canvas coordinate.
|
| + 0, 0, 0, 1, 1, 0, 1, 1,
|
| +
|
| + // Region of the texture to be used (normally the whole texture).
|
| + 0, 0, 0, 1, 1, 0, 1, 1};
|
| +}
|
| +
|
| +namespace remoting {
|
| +
|
| +GlRenderLayer::GlRenderLayer(int texture_id, GlCanvas* canvas)
|
| + : texture_id_(texture_id), canvas_(canvas) {
|
| + texture_handle_ = CreateTexture();
|
| + buffer_handle_ = CreateBuffer(kVertices, sizeof(kVertices));
|
| +}
|
| +
|
| +GlRenderLayer::~GlRenderLayer() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + glDeleteBuffers(1, &buffer_handle_);
|
| + glDeleteTextures(1, &texture_handle_);
|
| +}
|
| +
|
| +void GlRenderLayer::SetTexture(const void* texture, int width, int height) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + CHECK(width > 0 && height > 0);
|
| + glActiveTexture(GL_TEXTURE0 + texture_id_);
|
| + glBindTexture(GL_TEXTURE_2D, texture_handle_);
|
| +
|
| + if (width != texture_width_ || height != texture_height_) {
|
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
|
| + GL_UNSIGNED_BYTE, texture);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
| + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
| + texture_width_ = width;
|
| + texture_height_ = height;
|
| + } else {
|
| + // Size not changed. Just update the texture.
|
| + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA,
|
| + GL_UNSIGNED_BYTE, texture);
|
| + }
|
| + glBindTexture(GL_TEXTURE_2D, 0);
|
| +}
|
| +
|
| +void GlRenderLayer::SetVertexPositions(const float positions[8]) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + glBindBuffer(GL_ARRAY_BUFFER, buffer_handle_);
|
| + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(kVertices) / 2, positions);
|
| + glBindBuffer(GL_ARRAY_BUFFER, 0);
|
| +}
|
| +
|
| +void GlRenderLayer::SetTextureVisibleArea(const float positions[8]) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + glBindBuffer(GL_ARRAY_BUFFER, buffer_handle_);
|
| + glBufferSubData(GL_ARRAY_BUFFER, sizeof(kVertices) / 2, sizeof(kVertices) / 2,
|
| + positions);
|
| + glBindBuffer(GL_ARRAY_BUFFER, 0);
|
| +}
|
| +
|
| +void GlRenderLayer::Draw() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + if (texture_width_ == 0 || texture_height_ == 0) {
|
| + return;
|
| + }
|
| + canvas_->DrawTexture(texture_id_, texture_handle_, buffer_handle_);
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|