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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.cc

Issue 2170293002: Use GLVersionInfo instead of gl::GetGLImplementation() to decide GL paths (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 (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 "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 5 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "gpu/command_buffer/service/gl_utils.h" 11 #include "gpu/command_buffer/service/gl_utils.h"
12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
13 #include "ui/gl/gl_implementation.h" 13 #include "ui/gl/gl_version_info.h"
14 14
15 namespace { 15 namespace {
16 16
17 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 17 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
18 0.0f, 1.0f, 0.0f, 0.0f, 18 0.0f, 1.0f, 0.0f, 0.0f,
19 0.0f, 0.0f, 1.0f, 0.0f, 19 0.0f, 0.0f, 1.0f, 0.0f,
20 0.0f, 0.0f, 0.0f, 1.0f}; 20 0.0f, 0.0f, 0.0f, 1.0f};
21 21
22 enum FragmentShaderId { 22 enum FragmentShaderId {
23 FRAGMENT_SHADER_COPY_TEXTURE_2D, 23 FRAGMENT_SHADER_COPY_TEXTURE_2D,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 88
89 const char* kShaderPrecisionPreamble = "\ 89 const char* kShaderPrecisionPreamble = "\
90 #ifdef GL_ES\n\ 90 #ifdef GL_ES\n\
91 precision mediump float;\n\ 91 precision mediump float;\n\
92 #define TexCoordPrecision mediump\n\ 92 #define TexCoordPrecision mediump\n\
93 #else\n\ 93 #else\n\
94 #define TexCoordPrecision\n\ 94 #define TexCoordPrecision\n\
95 #endif\n"; 95 #endif\n";
96 96
97 std::string GetVertexShaderSource() { 97 std::string GetVertexShaderSource(const gl::GLVersionInfo& gl_version_info) {
98 std::string source; 98 std::string source;
99 99
100 // Preamble for core and compatibility mode. 100 // Preamble for core and compatibility mode.
101 if (gl::GetGLImplementation() == gl::kGLImplementationDesktopGLCoreProfile) { 101 if (gl_version_info.is_desktop_core_profile) {
102 source += std::string("\ 102 source += std::string("\
103 #version 150\n\ 103 #version 150\n\
104 #define ATTRIBUTE in\n\ 104 #define ATTRIBUTE in\n\
105 #define VARYING out\n"); 105 #define VARYING out\n");
106 } else { 106 } else {
107 source += std::string("\ 107 source += std::string("\
108 #define ATTRIBUTE attribute\n\ 108 #define ATTRIBUTE attribute\n\
109 #define VARYING varying\n"); 109 #define VARYING varying\n");
110 } 110 }
111 111
(...skipping 11 matching lines...) Expand all
123 void main(void) {\n\ 123 void main(void) {\n\
124 gl_Position = vec4(0, 0, 0, 1);\n\ 124 gl_Position = vec4(0, 0, 0, 1);\n\
125 gl_Position.xy = a_position.xy * u_vertex_dest_mult + \ 125 gl_Position.xy = a_position.xy * u_vertex_dest_mult + \
126 u_vertex_dest_add;\n\ 126 u_vertex_dest_add;\n\
127 v_uv = a_position.xy * u_vertex_source_mult + u_vertex_source_add;\n\ 127 v_uv = a_position.xy * u_vertex_source_mult + u_vertex_source_add;\n\
128 }\n"); 128 }\n");
129 129
130 return source; 130 return source;
131 } 131 }
132 132
133 std::string GetFragmentShaderSource(bool premultiply_alpha, 133 std::string GetFragmentShaderSource(const gl::GLVersionInfo& gl_version_info,
134 bool premultiply_alpha,
134 bool unpremultiply_alpha, 135 bool unpremultiply_alpha,
135 GLenum target) { 136 GLenum target) {
136 std::string source; 137 std::string source;
137 138
138 // Preamble for core and compatibility mode. 139 // Preamble for core and compatibility mode.
139 if (gl::GetGLImplementation() == gl::kGLImplementationDesktopGLCoreProfile) { 140 if (gl_version_info.is_desktop_core_profile) {
140 source += std::string("\ 141 source += std::string("\
141 #version 150\n\ 142 #version 150\n\
142 out vec4 frag_color;\n\ 143 out vec4 frag_color;\n\
143 #define VARYING in\n\ 144 #define VARYING in\n\
144 #define FRAGCOLOR frag_color\n\ 145 #define FRAGCOLOR frag_color\n\
145 #define TextureLookup texture\n"); 146 #define TextureLookup texture\n");
146 } else { 147 } else {
147 switch (target) { 148 switch (target) {
148 case GL_TEXTURE_2D: 149 case GL_TEXTURE_2D:
149 source += std::string("#define TextureLookup texture2D\n"); 150 source += std::string("#define TextureLookup texture2D\n");
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 DCHECK_LE(yoffset + height, dest_height); 568 DCHECK_LE(yoffset + height, dest_height);
568 if (dest_width == 0 || dest_height == 0 || source_width == 0 || 569 if (dest_width == 0 || dest_height == 0 || source_width == 0 ||
569 source_height == 0) { 570 source_height == 0) {
570 return; 571 return;
571 } 572 }
572 573
573 if (!initialized_) { 574 if (!initialized_) {
574 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; 575 DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager.";
575 return; 576 return;
576 } 577 }
578 const gl::GLVersionInfo& gl_version_info =
579 decoder->GetFeatureInfo()->gl_version_info();
577 580
578 if (vertex_array_object_id_) { 581 if (vertex_array_object_id_) {
579 glBindVertexArrayOES(vertex_array_object_id_); 582 glBindVertexArrayOES(vertex_array_object_id_);
580 } else { 583 } else {
581 if (gl::GetGLImplementation() != 584 if (!gl_version_info.is_desktop_core_profile) {
582 gl::kGLImplementationDesktopGLCoreProfile) {
583 decoder->ClearAllAttributes(); 585 decoder->ClearAllAttributes();
584 } 586 }
585 glEnableVertexAttribArray(kVertexPositionAttrib); 587 glEnableVertexAttribArray(kVertexPositionAttrib);
586 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); 588 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_);
587 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); 589 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
588 } 590 }
589 591
590 FragmentShaderId fragment_shader_id = GetFragmentShaderId( 592 FragmentShaderId fragment_shader_id = GetFragmentShaderId(
591 premultiply_alpha, unpremultiply_alpha, source_target); 593 premultiply_alpha, unpremultiply_alpha, source_target);
592 DCHECK_LT(static_cast<size_t>(fragment_shader_id), fragment_shaders_.size()); 594 DCHECK_LT(static_cast<size_t>(fragment_shader_id), fragment_shaders_.size());
593 595
594 ProgramMapKey key(fragment_shader_id); 596 ProgramMapKey key(fragment_shader_id);
595 ProgramInfo* info = &programs_[key]; 597 ProgramInfo* info = &programs_[key];
596 // Create program if necessary. 598 // Create program if necessary.
597 if (!info->program) { 599 if (!info->program) {
598 info->program = glCreateProgram(); 600 info->program = glCreateProgram();
599 if (!vertex_shader_) { 601 if (!vertex_shader_) {
600 vertex_shader_ = glCreateShader(GL_VERTEX_SHADER); 602 vertex_shader_ = glCreateShader(GL_VERTEX_SHADER);
601 std::string source = GetVertexShaderSource(); 603 std::string source = GetVertexShaderSource(gl_version_info);
602 CompileShader(vertex_shader_, source.c_str()); 604 CompileShader(vertex_shader_, source.c_str());
603 } 605 }
604 glAttachShader(info->program, vertex_shader_); 606 glAttachShader(info->program, vertex_shader_);
605 GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id]; 607 GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id];
606 if (!*fragment_shader) { 608 if (!*fragment_shader) {
607 *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 609 *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
608 std::string source = GetFragmentShaderSource( 610 std::string source =
609 premultiply_alpha, unpremultiply_alpha, source_target); 611 GetFragmentShaderSource(gl_version_info, premultiply_alpha,
612 unpremultiply_alpha, source_target);
610 CompileShader(*fragment_shader, source.c_str()); 613 CompileShader(*fragment_shader, source.c_str());
611 } 614 }
612 glAttachShader(info->program, *fragment_shader); 615 glAttachShader(info->program, *fragment_shader);
613 glBindAttribLocation(info->program, kVertexPositionAttrib, "a_position"); 616 glBindAttribLocation(info->program, kVertexPositionAttrib, "a_position");
614 glLinkProgram(info->program); 617 glLinkProgram(info->program);
615 #ifndef NDEBUG 618 #ifndef NDEBUG
616 GLint linked; 619 GLint linked;
617 glGetProgramiv(info->program, GL_LINK_STATUS, &linked); 620 glGetProgramiv(info->program, GL_LINK_STATUS, &linked);
618 if (!linked) 621 if (!linked)
619 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure."; 622 DLOG(ERROR) << "CopyTextureCHROMIUM: program link failure.";
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 decoder->RestoreTextureState(dest_id); 752 decoder->RestoreTextureState(dest_id);
750 decoder->RestoreTextureUnitBindings(0); 753 decoder->RestoreTextureUnitBindings(0);
751 decoder->RestoreActiveTexture(); 754 decoder->RestoreActiveTexture();
752 decoder->RestoreProgramBindings(); 755 decoder->RestoreProgramBindings();
753 decoder->RestoreBufferBindings(); 756 decoder->RestoreBufferBindings();
754 decoder->RestoreFramebufferBindings(); 757 decoder->RestoreFramebufferBindings();
755 decoder->RestoreGlobalState(); 758 decoder->RestoreGlobalState();
756 } 759 }
757 760
758 } // namespace gpu 761 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698