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

Side by Side Diff: ui/gl/scoped_binders.cc

Issue 1419733005: gpu: Add YCbCr 420v extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on master. Add gl/gfx namespace qualifiers. Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gl/scoped_binders.h" 5 #include "ui/gl/scoped_binders.h"
6 #include "ui/gl/gl_bindings.h" 6 #include "ui/gl/gl_bindings.h"
7 #include "ui/gl/gl_context.h" 7 #include "ui/gl/gl_context.h"
8 #include "ui/gl/gl_state_restorer.h" 8 #include "ui/gl/gl_state_restorer.h"
9 9
10 namespace gfx { 10 namespace gfx {
(...skipping 29 matching lines...) Expand all
40 switch (target) { 40 switch (target) {
41 case GL_TEXTURE_2D: 41 case GL_TEXTURE_2D:
42 target_getter = GL_TEXTURE_BINDING_2D; 42 target_getter = GL_TEXTURE_BINDING_2D;
43 break; 43 break;
44 case GL_TEXTURE_CUBE_MAP: 44 case GL_TEXTURE_CUBE_MAP:
45 target_getter = GL_TEXTURE_BINDING_CUBE_MAP; 45 target_getter = GL_TEXTURE_BINDING_CUBE_MAP;
46 break; 46 break;
47 case GL_TEXTURE_EXTERNAL_OES: 47 case GL_TEXTURE_EXTERNAL_OES:
48 target_getter = GL_TEXTURE_BINDING_EXTERNAL_OES; 48 target_getter = GL_TEXTURE_BINDING_EXTERNAL_OES;
49 break; 49 break;
50 case GL_TEXTURE_RECTANGLE_ARB:
51 target_getter = GL_TEXTURE_BINDING_RECTANGLE_ARB;
52 break;
50 default: 53 default:
51 NOTIMPLEMENTED() << "Target not part of OpenGL ES 2.0 spec."; 54 NOTIMPLEMENTED() << " Target not supported.";
52 } 55 }
53 glGetIntegerv(target_getter, &old_id_); 56 glGetIntegerv(target_getter, &old_id_);
54 } 57 }
55 glBindTexture(target_, id); 58 glBindTexture(target_, id);
56 } 59 }
57 60
58 ScopedTextureBinder::~ScopedTextureBinder() { 61 ScopedTextureBinder::~ScopedTextureBinder() {
59 if (state_restorer_) { 62 if (state_restorer_) {
60 DCHECK(!!GLContext::GetCurrent()); 63 DCHECK(!!GLContext::GetCurrent());
61 DCHECK_EQ(state_restorer_, GLContext::GetCurrent()->GetGLStateRestorer()); 64 DCHECK_EQ(state_restorer_, GLContext::GetCurrent()->GetGLStateRestorer());
62 state_restorer_->RestoreActiveTextureUnitBinding(target_); 65 state_restorer_->RestoreActiveTextureUnitBinding(target_);
63 } else { 66 } else {
64 glBindTexture(target_, old_id_); 67 glBindTexture(target_, old_id_);
65 } 68 }
66 } 69 }
67 70
71 ScopedUseProgram::ScopedUseProgram(unsigned int program) : old_program_(-1) {
72 glGetIntegerv(GL_CURRENT_PROGRAM, &old_program_);
73 glUseProgram(program);
74 }
75
76 ScopedUseProgram::~ScopedUseProgram() {
77 glUseProgram(old_program_);
78 }
79
80 ScopedEnableVertexAttribArray::ScopedEnableVertexAttribArray(unsigned int index)
81 : enabled_(0), index_(index) {
reveman 2015/10/29 22:08:04 s/0/GL_FALSE/
Daniele Castagna 2015/10/30 23:51:57 Done.
82 glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled_);
83 glEnableVertexAttribArray(index);
84 }
85
86 ScopedEnableVertexAttribArray::~ScopedEnableVertexAttribArray() {
87 if (!enabled_) {
reveman 2015/10/29 22:08:04 if (enabled_ == GL_FALSE)
Daniele Castagna 2015/10/30 23:51:57 Done.
88 glDisableVertexAttribArray(index_);
89 }
90 }
91
92 ScopedBufferBinder::ScopedBufferBinder(unsigned int target, unsigned int id)
93 : target_(target), old_id_(-1) {
94 GLenum target_getter = 0;
95 switch (target) {
96 case GL_ARRAY_BUFFER:
97 target_getter = GL_ARRAY_BUFFER_BINDING;
98 break;
99 default:
100 NOTIMPLEMENTED() << " Target not supported.";
101 }
102 glGetIntegerv(target_getter, &old_id_);
103 glBindBuffer(target_, id);
104 }
105
106 ScopedBufferBinder::~ScopedBufferBinder() {
107 glBindBuffer(target_, old_id_);
108 }
109
68 } // namespace gfx 110 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698