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

Side by Side Diff: content/common/gpu/media/gles2_external_texture_copier.cc

Issue 11973010: AndroidVDA by using Android's MediaCodec API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: using CopyTextureCHROMIUMResourceManager Created 7 years, 10 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
(Empty)
1 // Copyright (c) 2013 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 "content/common/gpu/media/gles2_external_texture_copier.h"
6
7 #include "base/logging.h"
8
9 namespace content {
10
11 static void CheckGlError(const char* op) {
12 #ifndef NDEBUG
13 for (GLint error = glGetError(); error; error = glGetError()) {
14 LOG(ERROR) << "after " << op <<" glError (0x" << std::hex << error << ")";
15 NOTREACHED();
16 }
17 #endif
18 }
19
20 Gles2ExternalTextureCopier::Gles2ExternalTextureCopier(
21 int32 width, int32 height)
22 : width_(width),
greggman 2013/02/20 19:13:58 style nit: 4 spaces in front of :
dwkang1 2013/02/25 23:48:00 Done.
23 height_(height) {
24 SaveState();
25 copier_.Initialize();
26 RestoreState();
27 }
28
29 Gles2ExternalTextureCopier::~Gles2ExternalTextureCopier() {
30 copier_.Destroy();
31 }
32
33 bool Gles2ExternalTextureCopier::Copy(
34 GLuint source_texture_id, GLuint destination_texture_id_) {
35 SaveState();
36 glViewport(0, 0, width_, height_);
37 copier_.DoCopyTexture(
38 GL_TEXTURE_2D, source_texture_id, destination_texture_id_, 0,
39 false, false, false, true);
40 RestoreState();
41 return true;
42 }
43
44 void Gles2ExternalTextureCopier::SaveState() {
45 // TODO(dwkang): Reportedly, glGetXXXs are extremely slow on some platforms.
46 // Check if we can skip some of below or find out a way to get
47 // the status from GLES2Decoder().
48 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_framebuffer_id_);
49 glGetIntegerv(GL_RENDERBUFFER_BINDING, &previous_renderbuffer_id_);
greggman 2013/02/20 19:13:58 render buffers are not used by copy
dwkang1 2013/02/25 23:48:00 Done.
50 glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous_texture_2d_id_);
greggman 2013/02/20 19:13:58 CopyTextureCHROMIUMResourceManager::DoCopyTexture
dwkang1 2013/02/25 23:48:00 Done.
51 glGetIntegerv(GL_CURRENT_PROGRAM, &previous_program_);
52 glGetIntegerv(GL_VIEWPORT, previous_viewport_);
53 glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vertex_array_buffer_binding_);
54 glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &index_array_buffer_binding_);
55
greggman 2013/02/20 19:13:58 You also need to query/restore GL_DEPTH_TEST, GL_S
dwkang1 2013/02/25 23:48:00 Done.
56 SaveStateForAttrib(
57 CopyTextureCHROMIUMResourceManager::kVertexPositionAttrib, 0);
58 SaveStateForAttrib(
59 CopyTextureCHROMIUMResourceManager::kVertexTextureAttrib, 1);
60 CheckGlError("SaveState");
greggman 2013/02/20 19:13:58 You also need to query and restore the Texture Par
dwkang1 2013/02/25 23:48:00 The doc says glTexParameter sets params for the ac
61 }
62
63 void Gles2ExternalTextureCopier::RestoreState() {
64 glBindFramebufferEXT(GL_FRAMEBUFFER, previous_framebuffer_id_);
65 glBindRenderbufferEXT(GL_RENDERBUFFER, previous_renderbuffer_id_);
66 glBindTexture(GL_TEXTURE_2D, previous_texture_2d_id_);
67 glUseProgram(previous_program_);
greggman 2013/02/20 19:13:58 Note: Querying and restoring bindings can never wo
dwkang1 2013/02/25 23:48:00 I added a TODO message for it.
68 glViewport(previous_viewport_[0], previous_viewport_[1],
69 previous_viewport_[2], previous_viewport_[3]);
70 glBindBuffer(GL_ARRAY_BUFFER, vertex_array_buffer_binding_);
71 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_);
72
73 RestoreStateForAttrib(
74 CopyTextureCHROMIUMResourceManager::kVertexPositionAttrib, 0);
75 RestoreStateForAttrib(
76 CopyTextureCHROMIUMResourceManager::kVertexTextureAttrib, 1);
77 CheckGlError("RestoreState");
78 }
79
80 void Gles2ExternalTextureCopier::SaveStateForAttrib(
81 GLuint attrib, int index) {
82 glGetVertexAttribiv(attrib, GL_VERTEX_ATTRIB_ARRAY_ENABLED,
83 &previous_vertex_attrib_[index].enabled);
84 glGetVertexAttribiv(attrib, GL_VERTEX_ATTRIB_ARRAY_SIZE,
85 &previous_vertex_attrib_[index].size);
86 glGetVertexAttribiv(attrib, GL_VERTEX_ATTRIB_ARRAY_TYPE,
87 &previous_vertex_attrib_[index].type);
88 glGetVertexAttribiv(attrib, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED,
89 &previous_vertex_attrib_[index].normalized);
90 glGetVertexAttribiv(attrib, GL_VERTEX_ATTRIB_ARRAY_STRIDE,
91 &previous_vertex_attrib_[index].stride);
92 glGetVertexAttribPointerv(attrib, GL_VERTEX_ATTRIB_ARRAY_POINTER,
93 &previous_vertex_attrib_[index].pointer);
94 }
95
96 void Gles2ExternalTextureCopier::RestoreStateForAttrib(
97 GLuint attrib, int index) {
98 glVertexAttribPointer(
99 attrib,
100 previous_vertex_attrib_[index].size,
101 previous_vertex_attrib_[index].type,
102 previous_vertex_attrib_[index].normalized,
103 previous_vertex_attrib_[index].stride,
104 previous_vertex_attrib_[index].pointer);
105
106 if (previous_vertex_attrib_[index].enabled)
107 glEnableVertexAttribArray(attrib);
108 else
109 glDisableVertexAttribArray(attrib);
110 }
111
112 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698