OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 | 2153 |
2154 // Bind the correct texture sampler location. | 2154 // Bind the correct texture sampler location. |
2155 gl_->Uniform1i(draw_cache_.sampler_location, 0); | 2155 gl_->Uniform1i(draw_cache_.sampler_location, 0); |
2156 | 2156 |
2157 // Assume the current active textures is 0. | 2157 // Assume the current active textures is 0. |
2158 ResourceProvider::ScopedSamplerGL locked_quad( | 2158 ResourceProvider::ScopedSamplerGL locked_quad( |
2159 resource_provider_, | 2159 resource_provider_, |
2160 draw_cache_.resource_id, | 2160 draw_cache_.resource_id, |
2161 draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR); | 2161 draw_cache_.nearest_neighbor ? GL_NEAREST : GL_LINEAR); |
2162 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 2162 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
2163 gl_->BindTexture(GL_TEXTURE_2D, locked_quad.texture_id()); | 2163 gl_->BindTexture(locked_quad.target(), locked_quad.texture_id()); |
2164 | 2164 |
2165 static_assert(sizeof(Float4) == 4 * sizeof(float), | 2165 static_assert(sizeof(Float4) == 4 * sizeof(float), |
2166 "Float4 struct should be densely packed"); | 2166 "Float4 struct should be densely packed"); |
2167 static_assert(sizeof(Float16) == 16 * sizeof(float), | 2167 static_assert(sizeof(Float16) == 16 * sizeof(float), |
2168 "Float16 struct should be densely packed"); | 2168 "Float16 struct should be densely packed"); |
2169 | 2169 |
2170 // Upload the tranforms for both points and uvs. | 2170 // Upload the tranforms for both points and uvs. |
2171 gl_->UniformMatrix4fv( | 2171 gl_->UniformMatrix4fv( |
2172 static_cast<int>(draw_cache_.matrix_location), | 2172 static_cast<int>(draw_cache_.matrix_location), |
2173 static_cast<int>(draw_cache_.matrix_data.size()), false, | 2173 static_cast<int>(draw_cache_.matrix_data.size()), false, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 // queue using the shared_geometry and not clipped_geometry | 2215 // queue using the shared_geometry and not clipped_geometry |
2216 FlushTextureQuadCache(SHARED_BINDING); | 2216 FlushTextureQuadCache(SHARED_BINDING); |
2217 } | 2217 } |
2218 | 2218 |
2219 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2219 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
2220 gl_, | 2220 gl_, |
2221 &highp_threshold_cache_, | 2221 &highp_threshold_cache_, |
2222 highp_threshold_min_, | 2222 highp_threshold_min_, |
2223 quad->shared_quad_state->visible_content_rect.bottom_right()); | 2223 quad->shared_quad_state->visible_content_rect.bottom_right()); |
2224 | 2224 |
| 2225 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2226 quad->resource_id); |
| 2227 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); |
2225 // Choose the correct texture program binding | 2228 // Choose the correct texture program binding |
2226 TexTransformTextureProgramBinding binding; | 2229 TexTransformTextureProgramBinding binding; |
2227 if (quad->premultiplied_alpha) { | 2230 if (quad->premultiplied_alpha) { |
2228 if (quad->background_color == SK_ColorTRANSPARENT) { | 2231 if (quad->background_color == SK_ColorTRANSPARENT) { |
2229 binding.Set(GetTextureProgram(tex_coord_precision)); | 2232 binding.Set(GetTextureProgram(tex_coord_precision, sampler)); |
2230 } else { | 2233 } else { |
2231 binding.Set(GetTextureBackgroundProgram(tex_coord_precision)); | 2234 binding.Set(GetTextureBackgroundProgram(tex_coord_precision, sampler)); |
2232 } | 2235 } |
2233 } else { | 2236 } else { |
2234 if (quad->background_color == SK_ColorTRANSPARENT) { | 2237 if (quad->background_color == SK_ColorTRANSPARENT) { |
2235 binding.Set(GetNonPremultipliedTextureProgram(tex_coord_precision)); | 2238 binding.Set( |
| 2239 GetNonPremultipliedTextureProgram(tex_coord_precision, sampler)); |
2236 } else { | 2240 } else { |
2237 binding.Set( | 2241 binding.Set(GetNonPremultipliedTextureBackgroundProgram( |
2238 GetNonPremultipliedTextureBackgroundProgram(tex_coord_precision)); | 2242 tex_coord_precision, sampler)); |
2239 } | 2243 } |
2240 } | 2244 } |
2241 | 2245 |
2242 int resource_id = quad->resource_id; | 2246 int resource_id = quad->resource_id; |
2243 | 2247 |
2244 if (draw_cache_.program_id != binding.program_id || | 2248 if (draw_cache_.program_id != binding.program_id || |
2245 draw_cache_.resource_id != resource_id || | 2249 draw_cache_.resource_id != resource_id || |
2246 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || | 2250 draw_cache_.needs_blending != quad->ShouldDrawWithBlending() || |
2247 draw_cache_.nearest_neighbor != quad->nearest_neighbor || | 2251 draw_cache_.nearest_neighbor != quad->nearest_neighbor || |
2248 draw_cache_.background_color != quad->background_color || | 2252 draw_cache_.background_color != quad->background_color || |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3190 TileProgramSwizzleAA* program = &tile_program_swizzle_aa_[precision][sampler]; | 3194 TileProgramSwizzleAA* program = &tile_program_swizzle_aa_[precision][sampler]; |
3191 if (!program->initialized()) { | 3195 if (!program->initialized()) { |
3192 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); | 3196 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); |
3193 program->Initialize( | 3197 program->Initialize( |
3194 output_surface_->context_provider(), precision, sampler); | 3198 output_surface_->context_provider(), precision, sampler); |
3195 } | 3199 } |
3196 return program; | 3200 return program; |
3197 } | 3201 } |
3198 | 3202 |
3199 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( | 3203 const GLRenderer::TextureProgram* GLRenderer::GetTextureProgram( |
3200 TexCoordPrecision precision) { | 3204 TexCoordPrecision precision, |
| 3205 SamplerType sampler) { |
3201 DCHECK_GE(precision, 0); | 3206 DCHECK_GE(precision, 0); |
3202 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3207 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3203 TextureProgram* program = &texture_program_[precision]; | 3208 DCHECK_GE(sampler, 0); |
| 3209 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3210 TextureProgram* program = &texture_program_[precision][sampler]; |
3204 if (!program->initialized()) { | 3211 if (!program->initialized()) { |
3205 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); | 3212 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
3206 program->Initialize(output_surface_->context_provider(), precision, | 3213 program->Initialize(output_surface_->context_provider(), precision, |
3207 SAMPLER_TYPE_2D); | 3214 sampler); |
3208 } | 3215 } |
3209 return program; | 3216 return program; |
3210 } | 3217 } |
3211 | 3218 |
3212 const GLRenderer::NonPremultipliedTextureProgram* | 3219 const GLRenderer::NonPremultipliedTextureProgram* |
3213 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision) { | 3220 GLRenderer::GetNonPremultipliedTextureProgram(TexCoordPrecision precision, |
| 3221 SamplerType sampler) { |
3214 DCHECK_GE(precision, 0); | 3222 DCHECK_GE(precision, 0); |
3215 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3223 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3224 DCHECK_GE(sampler, 0); |
| 3225 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
3216 NonPremultipliedTextureProgram* program = | 3226 NonPremultipliedTextureProgram* program = |
3217 &nonpremultiplied_texture_program_[precision]; | 3227 &nonpremultiplied_texture_program_[precision][sampler]; |
3218 if (!program->initialized()) { | 3228 if (!program->initialized()) { |
3219 TRACE_EVENT0("cc", | 3229 TRACE_EVENT0("cc", |
3220 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | 3230 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
3221 program->Initialize(output_surface_->context_provider(), precision, | 3231 program->Initialize(output_surface_->context_provider(), precision, |
3222 SAMPLER_TYPE_2D); | 3232 sampler); |
3223 } | 3233 } |
3224 return program; | 3234 return program; |
3225 } | 3235 } |
3226 | 3236 |
3227 const GLRenderer::TextureBackgroundProgram* | 3237 const GLRenderer::TextureBackgroundProgram* |
3228 GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision) { | 3238 GLRenderer::GetTextureBackgroundProgram(TexCoordPrecision precision, |
| 3239 SamplerType sampler) { |
3229 DCHECK_GE(precision, 0); | 3240 DCHECK_GE(precision, 0); |
3230 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3241 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3231 TextureBackgroundProgram* program = &texture_background_program_[precision]; | 3242 DCHECK_GE(sampler, 0); |
| 3243 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3244 TextureBackgroundProgram* program = |
| 3245 &texture_background_program_[precision][sampler]; |
3232 if (!program->initialized()) { | 3246 if (!program->initialized()) { |
3233 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); | 3247 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
3234 program->Initialize(output_surface_->context_provider(), precision, | 3248 program->Initialize(output_surface_->context_provider(), precision, |
3235 SAMPLER_TYPE_2D); | 3249 sampler); |
3236 } | 3250 } |
3237 return program; | 3251 return program; |
3238 } | 3252 } |
3239 | 3253 |
3240 const GLRenderer::NonPremultipliedTextureBackgroundProgram* | 3254 const GLRenderer::NonPremultipliedTextureBackgroundProgram* |
3241 GLRenderer::GetNonPremultipliedTextureBackgroundProgram( | 3255 GLRenderer::GetNonPremultipliedTextureBackgroundProgram( |
3242 TexCoordPrecision precision) { | 3256 TexCoordPrecision precision, |
| 3257 SamplerType sampler) { |
3243 DCHECK_GE(precision, 0); | 3258 DCHECK_GE(precision, 0); |
3244 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3259 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3260 DCHECK_GE(sampler, 0); |
| 3261 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
3245 NonPremultipliedTextureBackgroundProgram* program = | 3262 NonPremultipliedTextureBackgroundProgram* program = |
3246 &nonpremultiplied_texture_background_program_[precision]; | 3263 &nonpremultiplied_texture_background_program_[precision][sampler]; |
3247 if (!program->initialized()) { | 3264 if (!program->initialized()) { |
3248 TRACE_EVENT0("cc", | 3265 TRACE_EVENT0("cc", |
3249 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | 3266 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
3250 program->Initialize(output_surface_->context_provider(), precision, | 3267 program->Initialize(output_surface_->context_provider(), precision, |
3251 SAMPLER_TYPE_2D); | 3268 sampler); |
3252 } | 3269 } |
3253 return program; | 3270 return program; |
3254 } | 3271 } |
3255 | 3272 |
3256 const GLRenderer::TextureProgram* GLRenderer::GetTextureIOSurfaceProgram( | 3273 const GLRenderer::TextureProgram* GLRenderer::GetTextureIOSurfaceProgram( |
3257 TexCoordPrecision precision) { | 3274 TexCoordPrecision precision) { |
3258 DCHECK_GE(precision, 0); | 3275 DCHECK_GE(precision, 0); |
3259 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3276 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3260 TextureProgram* program = &texture_io_surface_program_[precision]; | 3277 TextureProgram* program = &texture_io_surface_program_[precision]; |
3261 if (!program->initialized()) { | 3278 if (!program->initialized()) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3329 } | 3346 } |
3330 } | 3347 } |
3331 } | 3348 } |
3332 for (int j = 0; j <= LAST_BLEND_MODE; j++) { | 3349 for (int j = 0; j <= LAST_BLEND_MODE; j++) { |
3333 render_pass_program_[i][j].Cleanup(gl_); | 3350 render_pass_program_[i][j].Cleanup(gl_); |
3334 render_pass_program_aa_[i][j].Cleanup(gl_); | 3351 render_pass_program_aa_[i][j].Cleanup(gl_); |
3335 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | 3352 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
3336 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | 3353 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
3337 } | 3354 } |
3338 | 3355 |
3339 texture_program_[i].Cleanup(gl_); | 3356 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
3340 nonpremultiplied_texture_program_[i].Cleanup(gl_); | 3357 texture_program_[i][j].Cleanup(gl_); |
3341 texture_background_program_[i].Cleanup(gl_); | 3358 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); |
3342 nonpremultiplied_texture_background_program_[i].Cleanup(gl_); | 3359 texture_background_program_[i][j].Cleanup(gl_); |
| 3360 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); |
| 3361 } |
3343 texture_io_surface_program_[i].Cleanup(gl_); | 3362 texture_io_surface_program_[i].Cleanup(gl_); |
3344 | 3363 |
3345 video_yuv_program_[i].Cleanup(gl_); | 3364 video_yuv_program_[i].Cleanup(gl_); |
3346 video_yuva_program_[i].Cleanup(gl_); | 3365 video_yuva_program_[i].Cleanup(gl_); |
3347 video_stream_texture_program_[i].Cleanup(gl_); | 3366 video_stream_texture_program_[i].Cleanup(gl_); |
3348 } | 3367 } |
3349 | 3368 |
3350 tile_checkerboard_program_.Cleanup(gl_); | 3369 tile_checkerboard_program_.Cleanup(gl_); |
3351 | 3370 |
3352 debug_border_program_.Cleanup(gl_); | 3371 debug_border_program_.Cleanup(gl_); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3436 context_support_->ScheduleOverlayPlane( | 3455 context_support_->ScheduleOverlayPlane( |
3437 overlay.plane_z_order, | 3456 overlay.plane_z_order, |
3438 overlay.transform, | 3457 overlay.transform, |
3439 pending_overlay_resources_.back()->texture_id(), | 3458 pending_overlay_resources_.back()->texture_id(), |
3440 ToNearestRect(overlay.display_rect), | 3459 ToNearestRect(overlay.display_rect), |
3441 overlay.uv_rect); | 3460 overlay.uv_rect); |
3442 } | 3461 } |
3443 } | 3462 } |
3444 | 3463 |
3445 } // namespace cc | 3464 } // namespace cc |
OLD | NEW |