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

Side by Side Diff: cc/output/program_binding.cc

Issue 2628713002: The great shader refactor: Use ProgramKey to initialize shaders (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « cc/output/program_binding.h ('k') | cc/output/shader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/output/program_binding.h" 5 #include "cc/output/program_binding.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "cc/output/geometry_binding.h" 8 #include "cc/output/geometry_binding.h"
9 #include "gpu/GLES2/gl2extchromium.h" 9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface.h" 10 #include "gpu/command_buffer/client/gles2_interface.h"
11 11
12 using gpu::gles2::GLES2Interface; 12 using gpu::gles2::GLES2Interface;
13 13
14 namespace cc { 14 namespace cc {
15 15
16 ProgramKey::ProgramKey() = default;
17 ProgramKey::ProgramKey(const ProgramKey& other) = default;
18 ProgramKey::~ProgramKey() = default;
19
20 bool ProgramKey::operator==(const ProgramKey& other) const {
21 return type_ == other.type_ && precision_ == other.precision_ &&
22 sampler_ == other.sampler_ && blend_mode_ == other.blend_mode_ &&
23 aa_mode_ == other.aa_mode_ && swizzle_mode_ == other.swizzle_mode_ &&
24 is_opaque_ == other.is_opaque_ &&
25 premultiplied_alpha_ == other.premultiplied_alpha_ &&
26 has_background_color_ == other.has_background_color_ &&
27 mask_mode_ == other.mask_mode_ &&
28 mask_for_background_ == other.mask_for_background_ &&
29 has_color_matrix_ == other.has_color_matrix_;
30 }
31
32 // static
33 ProgramKey ProgramKey::DebugBorder() {
34 ProgramKey result;
35 result.type_ = PROGRAM_TYPE_DEBUG_BORDER;
36 return result;
37 }
38
39 // static
40 ProgramKey ProgramKey::SolidColor(AAMode aa_mode) {
41 ProgramKey result;
42 result.type_ = PROGRAM_TYPE_SOLID_COLOR;
43 result.aa_mode_ = aa_mode;
44 return result;
45 }
46
47 // static
48 ProgramKey ProgramKey::Tile(TexCoordPrecision precision,
49 SamplerType sampler,
50 AAMode aa_mode,
51 SwizzleMode swizzle_mode,
52 bool is_opaque) {
53 ProgramKey result;
54 result.type_ = PROGRAM_TYPE_TILE;
55 result.precision_ = precision;
56 result.sampler_ = sampler;
57 result.aa_mode_ = aa_mode;
58 result.swizzle_mode_ = swizzle_mode;
59 result.is_opaque_ = is_opaque;
60 return result;
61 }
62
63 // static
64 ProgramKey ProgramKey::Texture(TexCoordPrecision precision,
65 SamplerType sampler,
66 PremultipliedAlphaMode premultiplied_alpha,
67 bool has_background_color) {
68 ProgramKey result;
69 result.type_ = PROGRAM_TYPE_TEXTURE;
70 result.precision_ = precision;
71 result.sampler_ = sampler;
72 result.premultiplied_alpha_ = premultiplied_alpha;
73 result.has_background_color_ = has_background_color;
74 return result;
75 }
76
77 // static
78 ProgramKey ProgramKey::RenderPass(TexCoordPrecision precision,
79 SamplerType sampler,
80 BlendMode blend_mode,
81 AAMode aa_mode,
82 MaskMode mask_mode,
83 bool mask_for_background,
84 bool has_color_matrix) {
85 ProgramKey result;
86 result.type_ = PROGRAM_TYPE_RENDER_PASS;
87 result.precision_ = precision;
88 result.sampler_ = sampler;
89 result.blend_mode_ = blend_mode;
90 result.aa_mode_ = aa_mode;
91 result.mask_mode_ = mask_mode;
92 result.mask_for_background_ = mask_for_background;
93 result.has_color_matrix_ = has_color_matrix;
94 return result;
95 }
96
97 // static
98 ProgramKey ProgramKey::VideoStream(TexCoordPrecision precision) {
99 ProgramKey result;
100 result.type_ = PROGRAM_TYPE_VIDEO_STREAM;
101 result.precision_ = precision;
102 result.sampler_ = SAMPLER_TYPE_EXTERNAL_OES;
103 return result;
104 }
105
16 ProgramBindingBase::ProgramBindingBase() 106 ProgramBindingBase::ProgramBindingBase()
17 : program_(0), 107 : program_(0),
18 vertex_shader_id_(0), 108 vertex_shader_id_(0),
19 fragment_shader_id_(0), 109 fragment_shader_id_(0),
20 initialized_(false) {} 110 initialized_(false) {}
21 111
22 ProgramBindingBase::~ProgramBindingBase() { 112 ProgramBindingBase::~ProgramBindingBase() {
23 // If you hit these asserts, you initialized but forgot to call Cleanup(). 113 // If you hit these asserts, you initialized but forgot to call Cleanup().
24 DCHECK(!program_); 114 DCHECK(!program_);
25 DCHECK(!vertex_shader_id_); 115 DCHECK(!vertex_shader_id_);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 context->DeleteShader(fragment_shader_id_); 227 context->DeleteShader(fragment_shader_id_);
138 fragment_shader_id_ = 0; 228 fragment_shader_id_ = 0;
139 } 229 }
140 } 230 }
141 231
142 bool ProgramBindingBase::IsContextLost(GLES2Interface* context) { 232 bool ProgramBindingBase::IsContextLost(GLES2Interface* context) {
143 return context->GetGraphicsResetStatusKHR() != GL_NO_ERROR; 233 return context->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
144 } 234 }
145 235
146 } // namespace cc 236 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/program_binding.h ('k') | cc/output/shader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698