| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 // Whether a color matrix needs to be applied by the shaders when drawing | 220 // Whether a color matrix needs to be applied by the shaders when drawing |
| 221 // the RPDQ. | 221 // the RPDQ. |
| 222 bool use_color_matrix = false; | 222 bool use_color_matrix = false; |
| 223 | 223 |
| 224 gfx::QuadF surface_quad; | 224 gfx::QuadF surface_quad; |
| 225 | 225 |
| 226 gfx::Transform contents_device_transform; | 226 gfx::Transform contents_device_transform; |
| 227 | 227 |
| 228 gfx::RectF tex_coord_rect; | 228 gfx::RectF tex_coord_rect; |
| 229 |
| 230 // The color space of the texture bound for sampling (from filter_image or |
| 231 // contents_resource_lock, depending on the path taken). |
| 232 gfx::ColorSpace contents_color_space; |
| 229 }; | 233 }; |
| 230 | 234 |
| 231 static GLint GetActiveTextureUnit(GLES2Interface* gl) { | 235 static GLint GetActiveTextureUnit(GLES2Interface* gl) { |
| 232 GLint active_unit = 0; | 236 GLint active_unit = 0; |
| 233 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 237 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 234 return active_unit; | 238 return active_unit; |
| 235 } | 239 } |
| 236 | 240 |
| 237 class GLRenderer::ScopedUseGrContext { | 241 class GLRenderer::ScopedUseGrContext { |
| 238 public: | 242 public: |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 backend_texture_description.fTextureHandle = | 647 backend_texture_description.fTextureHandle = |
| 644 skia::GrGLTextureInfoToGrBackendObject(texture_info); | 648 skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 645 backend_texture_description.fOrigin = | 649 backend_texture_description.fOrigin = |
| 646 flip_texture ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; | 650 flip_texture ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
| 647 | 651 |
| 648 return SkImage::MakeFromTexture(context, backend_texture_description); | 652 return SkImage::MakeFromTexture(context, backend_texture_description); |
| 649 } | 653 } |
| 650 | 654 |
| 651 static sk_sp<SkImage> ApplyImageFilter( | 655 static sk_sp<SkImage> ApplyImageFilter( |
| 652 std::unique_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, | 656 std::unique_ptr<GLRenderer::ScopedUseGrContext> use_gr_context, |
| 653 ResourceProvider* resource_provider, | |
| 654 const gfx::RectF& src_rect, | 657 const gfx::RectF& src_rect, |
| 655 const gfx::RectF& dst_rect, | 658 const gfx::RectF& dst_rect, |
| 656 const gfx::Vector2dF& scale, | 659 const gfx::Vector2dF& scale, |
| 657 sk_sp<SkImageFilter> filter, | 660 sk_sp<SkImageFilter> filter, |
| 658 const Resource* source_texture_resource, | 661 const ResourceProvider::ScopedReadLockGL& source_texture_lock, |
| 659 SkIPoint* offset, | 662 SkIPoint* offset, |
| 660 SkIRect* subset, | 663 SkIRect* subset, |
| 661 bool flip_texture, | 664 bool flip_texture, |
| 662 const gfx::PointF& origin) { | 665 const gfx::PointF& origin) { |
| 663 if (!filter || !use_gr_context) | 666 if (!filter || !use_gr_context) |
| 664 return nullptr; | 667 return nullptr; |
| 665 | 668 |
| 666 ResourceProvider::ScopedReadLockGL lock(resource_provider, | |
| 667 source_texture_resource->id()); | |
| 668 | |
| 669 sk_sp<SkImage> src_image = | 669 sk_sp<SkImage> src_image = |
| 670 WrapTexture(lock, use_gr_context->context(), flip_texture); | 670 WrapTexture(source_texture_lock, use_gr_context->context(), flip_texture); |
| 671 | 671 |
| 672 if (!src_image) { | 672 if (!src_image) { |
| 673 TRACE_EVENT_INSTANT0("cc", | 673 TRACE_EVENT_INSTANT0("cc", |
| 674 "ApplyImageFilter wrap background texture failed", | 674 "ApplyImageFilter wrap background texture failed", |
| 675 TRACE_EVENT_SCOPE_THREAD); | 675 TRACE_EVENT_SCOPE_THREAD); |
| 676 return nullptr; | 676 return nullptr; |
| 677 } | 677 } |
| 678 | 678 |
| 679 SkMatrix local_matrix; | 679 SkMatrix local_matrix; |
| 680 local_matrix.setTranslate(origin.x(), origin.y()); | 680 local_matrix.setTranslate(origin.x(), origin.y()); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 const gfx::QuadF* clip_region) { | 1037 const gfx::QuadF* clip_region) { |
| 1038 auto bypass = render_pass_bypass_quads_.find(quad->render_pass_id); | 1038 auto bypass = render_pass_bypass_quads_.find(quad->render_pass_id); |
| 1039 DrawRenderPassDrawQuadParams params; | 1039 DrawRenderPassDrawQuadParams params; |
| 1040 params.quad = quad; | 1040 params.quad = quad; |
| 1041 params.clip_region = clip_region; | 1041 params.clip_region = clip_region; |
| 1042 params.window_matrix = current_frame()->window_matrix; | 1042 params.window_matrix = current_frame()->window_matrix; |
| 1043 params.projection_matrix = current_frame()->projection_matrix; | 1043 params.projection_matrix = current_frame()->projection_matrix; |
| 1044 params.tex_coord_rect = quad->tex_coord_rect; | 1044 params.tex_coord_rect = quad->tex_coord_rect; |
| 1045 if (bypass != render_pass_bypass_quads_.end()) { | 1045 if (bypass != render_pass_bypass_quads_.end()) { |
| 1046 TileDrawQuad* tile_quad = &bypass->second; | 1046 TileDrawQuad* tile_quad = &bypass->second; |
| 1047 // RGBA_8888 here is arbitrary and unused. | 1047 // RGBA_8888 and the gfx::ColorSpace() here are arbitrary and unused. |
| 1048 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, | 1048 Resource tile_resource(tile_quad->resource_id(), tile_quad->texture_size, |
| 1049 ResourceFormat::RGBA_8888, | 1049 ResourceFormat::RGBA_8888, gfx::ColorSpace()); |
| 1050 current_frame()->current_render_pass->color_space); | |
| 1051 // The projection matrix used by GLRenderer has a flip. As tile texture | 1050 // The projection matrix used by GLRenderer has a flip. As tile texture |
| 1052 // inputs are oriented opposite to framebuffer outputs, don't flip via | 1051 // inputs are oriented opposite to framebuffer outputs, don't flip via |
| 1053 // texture coords and let the projection matrix naturallyd o it. | 1052 // texture coords and let the projection matrix naturallyd o it. |
| 1054 params.flip_texture = false; | 1053 params.flip_texture = false; |
| 1055 params.contents_texture = &tile_resource; | 1054 params.contents_texture = &tile_resource; |
| 1056 DrawRenderPassQuadInternal(¶ms); | 1055 DrawRenderPassQuadInternal(¶ms); |
| 1057 } else { | 1056 } else { |
| 1058 ScopedResource* contents_texture = | 1057 ScopedResource* contents_texture = |
| 1059 render_pass_textures_[quad->render_pass_id].get(); | 1058 render_pass_textures_[quad->render_pass_id].get(); |
| 1060 DCHECK(contents_texture); | 1059 DCHECK(contents_texture); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); | 1233 gfx::QuadF local_clip = MapQuadToLocalSpace(transform, clip_quad); |
| 1235 params->dst_rect.Intersect(local_clip.BoundingBox()); | 1234 params->dst_rect.Intersect(local_clip.BoundingBox()); |
| 1236 // If we've been fully clipped out (by crop rect or clipping), there's | 1235 // If we've been fully clipped out (by crop rect or clipping), there's |
| 1237 // nothing to draw. | 1236 // nothing to draw. |
| 1238 if (params->dst_rect.IsEmpty()) { | 1237 if (params->dst_rect.IsEmpty()) { |
| 1239 return false; | 1238 return false; |
| 1240 } | 1239 } |
| 1241 SkIPoint offset; | 1240 SkIPoint offset; |
| 1242 SkIRect subset; | 1241 SkIRect subset; |
| 1243 gfx::RectF src_rect(quad->rect); | 1242 gfx::RectF src_rect(quad->rect); |
| 1243 |
| 1244 ResourceProvider::ScopedReadLockGL prefilter_contents_texture_lock( |
| 1245 resource_provider_, params->contents_texture->id()); |
| 1246 params->contents_color_space = |
| 1247 prefilter_contents_texture_lock.color_space(); |
| 1244 params->filter_image = ApplyImageFilter( | 1248 params->filter_image = ApplyImageFilter( |
| 1245 ScopedUseGrContext::Create(this), resource_provider_, src_rect, | 1249 ScopedUseGrContext::Create(this), src_rect, params->dst_rect, |
| 1246 params->dst_rect, quad->filters_scale, std::move(filter), | 1250 quad->filters_scale, std::move(filter), |
| 1247 params->contents_texture, &offset, &subset, params->flip_texture, | 1251 prefilter_contents_texture_lock, &offset, &subset, |
| 1248 quad->filters_origin); | 1252 params->flip_texture, quad->filters_origin); |
| 1249 if (!params->filter_image) | 1253 if (!params->filter_image) |
| 1250 return false; | 1254 return false; |
| 1251 params->dst_rect = | 1255 params->dst_rect = |
| 1252 gfx::RectF(src_rect.x() + offset.fX, src_rect.y() + offset.fY, | 1256 gfx::RectF(src_rect.x() + offset.fX, src_rect.y() + offset.fY, |
| 1253 subset.width(), subset.height()); | 1257 subset.width(), subset.height()); |
| 1254 params->src_offset.SetPoint(subset.x(), subset.y()); | 1258 params->src_offset.SetPoint(subset.x(), subset.y()); |
| 1255 gfx::RectF tex_rect = gfx::RectF(gfx::PointF(params->src_offset), | 1259 gfx::RectF tex_rect = gfx::RectF(gfx::PointF(params->src_offset), |
| 1256 params->dst_rect.size()); | 1260 params->dst_rect.size()); |
| 1257 params->tex_coord_rect = tex_rect; | 1261 params->tex_coord_rect = tex_rect; |
| 1258 } | 1262 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1273 GrSurfaceOrigin origin; | 1277 GrSurfaceOrigin origin; |
| 1274 GLuint filter_image_id = | 1278 GLuint filter_image_id = |
| 1275 skia::GrBackendObjectToGrGLTextureInfo( | 1279 skia::GrBackendObjectToGrGLTextureInfo( |
| 1276 params->filter_image->getTextureHandle(true, &origin)) | 1280 params->filter_image->getTextureHandle(true, &origin)) |
| 1277 ->fID; | 1281 ->fID; |
| 1278 DCHECK(filter_image_id); | 1282 DCHECK(filter_image_id); |
| 1279 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | 1283 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 1280 gl_->BindTexture(GL_TEXTURE_2D, filter_image_id); | 1284 gl_->BindTexture(GL_TEXTURE_2D, filter_image_id); |
| 1281 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 1285 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1282 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 1286 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1283 | 1287 // |params->contents_color_space| was populated when |params->filter_image| |
| 1288 // was populated. |
| 1284 params->source_needs_flip = kBottomLeft_GrSurfaceOrigin == origin; | 1289 params->source_needs_flip = kBottomLeft_GrSurfaceOrigin == origin; |
| 1285 } else { | 1290 } else { |
| 1286 params->contents_resource_lock = | 1291 params->contents_resource_lock = |
| 1287 base::MakeUnique<ResourceProvider::ScopedSamplerGL>( | 1292 base::MakeUnique<ResourceProvider::ScopedSamplerGL>( |
| 1288 resource_provider_, params->contents_texture->id(), GL_LINEAR); | 1293 resource_provider_, params->contents_texture->id(), GL_LINEAR); |
| 1289 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), | 1294 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), |
| 1290 params->contents_resource_lock->target()); | 1295 params->contents_resource_lock->target()); |
| 1296 params->contents_color_space = |
| 1297 params->contents_resource_lock->color_space(); |
| 1291 params->source_needs_flip = params->flip_texture; | 1298 params->source_needs_flip = params->flip_texture; |
| 1292 } | 1299 } |
| 1293 } | 1300 } |
| 1294 | 1301 |
| 1295 void GLRenderer::UpdateRPDQBlendMode(DrawRenderPassDrawQuadParams* params) { | 1302 void GLRenderer::UpdateRPDQBlendMode(DrawRenderPassDrawQuadParams* params) { |
| 1296 SkBlendMode blend_mode = params->quad->shared_quad_state->blend_mode; | 1303 SkBlendMode blend_mode = params->quad->shared_quad_state->blend_mode; |
| 1297 SetBlendEnabled(!params->use_shaders_for_blending && | 1304 SetBlendEnabled(!params->use_shaders_for_blending && |
| 1298 (params->quad->ShouldDrawWithBlending() || | 1305 (params->quad->ShouldDrawWithBlending() || |
| 1299 !IsDefaultBlendMode(blend_mode))); | 1306 !IsDefaultBlendMode(blend_mode))); |
| 1300 if (!params->use_shaders_for_blending) { | 1307 if (!params->use_shaders_for_blending) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1316 : BLEND_MODE_NONE; | 1323 : BLEND_MODE_NONE; |
| 1317 | 1324 |
| 1318 SamplerType sampler_type = SAMPLER_TYPE_2D; | 1325 SamplerType sampler_type = SAMPLER_TYPE_2D; |
| 1319 MaskMode mask_mode = NO_MASK; | 1326 MaskMode mask_mode = NO_MASK; |
| 1320 bool mask_for_background = params->mask_for_background; | 1327 bool mask_for_background = params->mask_for_background; |
| 1321 if (params->mask_resource_lock) { | 1328 if (params->mask_resource_lock) { |
| 1322 mask_mode = HAS_MASK; | 1329 mask_mode = HAS_MASK; |
| 1323 sampler_type = | 1330 sampler_type = |
| 1324 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); | 1331 SamplerTypeFromTextureTarget(params->mask_resource_lock->target()); |
| 1325 } | 1332 } |
| 1326 | |
| 1327 SetUseProgram(ProgramKey::RenderPass( | 1333 SetUseProgram(ProgramKey::RenderPass( |
| 1328 tex_coord_precision, sampler_type, shader_blend_mode, | 1334 tex_coord_precision, sampler_type, shader_blend_mode, |
| 1329 params->use_aa ? USE_AA : NO_AA, mask_mode, | 1335 params->use_aa ? USE_AA : NO_AA, mask_mode, |
| 1330 mask_for_background, params->use_color_matrix), | 1336 mask_for_background, params->use_color_matrix), |
| 1331 params->contents_resource_lock | 1337 params->contents_color_space); |
| 1332 ? params->contents_resource_lock->color_space() | |
| 1333 : gfx::ColorSpace()); | |
| 1334 } | 1338 } |
| 1335 | 1339 |
| 1336 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { | 1340 void GLRenderer::UpdateRPDQUniforms(DrawRenderPassDrawQuadParams* params) { |
| 1337 gfx::RectF tex_rect = params->tex_coord_rect; | 1341 gfx::RectF tex_rect = params->tex_coord_rect; |
| 1338 | 1342 |
| 1339 gfx::Size texture_size; | 1343 gfx::Size texture_size; |
| 1340 if (params->filter_image) { | 1344 if (params->filter_image) { |
| 1341 texture_size.set_width(params->filter_image->width()); | 1345 texture_size.set_width(params->filter_image->width()); |
| 1342 texture_size.set_height(params->filter_image->height()); | 1346 texture_size.set_height(params->filter_image->height()); |
| 1343 } else { | 1347 } else { |
| (...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3611 return; | 3615 return; |
| 3612 | 3616 |
| 3613 // Report GPU overdraw as a percentage of |max_result|. | 3617 // Report GPU overdraw as a percentage of |max_result|. |
| 3614 TRACE_COUNTER1( | 3618 TRACE_COUNTER1( |
| 3615 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3619 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
| 3616 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | 3620 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
| 3617 max_result); | 3621 max_result); |
| 3618 } | 3622 } |
| 3619 | 3623 |
| 3620 } // namespace cc | 3624 } // namespace cc |
| OLD | NEW |