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

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

Issue 1952303002: cc: fix nullptr deref in software renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing test file Created 4 years, 7 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 | « no previous file | cc/test/data/white.png » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/output/software_renderer.h" 5 #include "cc/output/software_renderer.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 MathUtil::ScaleRectProportional(QuadVertexRect(), gfx::RectF(quad->rect), 491 MathUtil::ScaleRectProportional(QuadVertexRect(), gfx::RectF(quad->rect),
492 gfx::RectF(quad->visible_rect))); 492 gfx::RectF(quad->visible_rect)));
493 SkRect content_rect = SkRect::MakeWH(quad->rect.width(), quad->rect.height()); 493 SkRect content_rect = SkRect::MakeWH(quad->rect.width(), quad->rect.height());
494 494
495 const SkBitmap* content = lock.sk_bitmap(); 495 const SkBitmap* content = lock.sk_bitmap();
496 496
497 sk_sp<SkImage> filter_image; 497 sk_sp<SkImage> filter_image;
498 if (!quad->filters.IsEmpty()) { 498 if (!quad->filters.IsEmpty()) {
499 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter( 499 sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
500 quad->filters, gfx::SizeF(content_texture->size())); 500 quad->filters, gfx::SizeF(content_texture->size()));
501 SkIRect result_rect; 501 if (filter) {
502 // TODO(ajuma): Apply the filter in the same pass as the content where 502 SkIRect result_rect;
503 // possible (e.g. when there's no origin offset). See crbug.com/308201. 503 // TODO(ajuma): Apply the filter in the same pass as the content where
504 filter_image = ApplyImageFilter(filter.get(), quad, *content, &result_rect); 504 // possible (e.g. when there's no origin offset). See crbug.com/308201.
505 if (filter_image) { 505 filter_image =
506 gfx::RectF rect = gfx::SkRectToRectF(SkRect::Make(result_rect)); 506 ApplyImageFilter(filter.get(), quad, *content, &result_rect);
507 dest_rect = dest_visible_rect = 507 if (result_rect.isEmpty()) {
508 gfx::RectFToSkRect(MathUtil::ScaleRectProportional( 508 return;
509 QuadVertexRect(), gfx::RectF(quad->rect), rect)); 509 }
510 content_rect = SkRect::MakeWH(result_rect.width(), result_rect.height()); 510 if (filter_image) {
511 gfx::RectF rect = gfx::SkRectToRectF(SkRect::Make(result_rect));
512 dest_rect = dest_visible_rect =
513 gfx::RectFToSkRect(MathUtil::ScaleRectProportional(
514 QuadVertexRect(), gfx::RectF(quad->rect), rect));
515 content_rect =
516 SkRect::MakeWH(result_rect.width(), result_rect.height());
517 }
511 } 518 }
512 } 519 }
513 520
514 SkMatrix content_mat; 521 SkMatrix content_mat;
515 content_mat.setRectToRect(content_rect, dest_rect, 522 content_mat.setRectToRect(content_rect, dest_rect,
516 SkMatrix::kFill_ScaleToFit); 523 SkMatrix::kFill_ScaleToFit);
517 524
518 sk_sp<SkShader> shader; 525 sk_sp<SkShader> shader;
519 if (!filter_image) { 526 if (!filter_image) {
520 shader = 527 shader =
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 SkImageFilter::kForward_MapDirection); 663 SkImageFilter::kForward_MapDirection);
657 *auto_bounds = dst_rect; 664 *auto_bounds = dst_rect;
658 } else { 665 } else {
659 dst_rect = to_filter.bounds(); 666 dst_rect = to_filter.bounds();
660 } 667 }
661 668
662 SkImageInfo dst_info = 669 SkImageInfo dst_info =
663 SkImageInfo::MakeN32Premul(dst_rect.width(), dst_rect.height()); 670 SkImageInfo::MakeN32Premul(dst_rect.width(), dst_rect.height());
664 sk_sp<SkSurface> surface = SkSurface::MakeRaster(dst_info); 671 sk_sp<SkSurface> surface = SkSurface::MakeRaster(dst_info);
665 672
673 if (!surface) {
674 return nullptr;
675 }
676
666 SkPaint paint; 677 SkPaint paint;
667 paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix)); 678 paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix));
668 surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y()); 679 surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y());
669 surface->getCanvas()->drawBitmap(to_filter, quad->rect.x(), quad->rect.y(), 680 surface->getCanvas()->drawBitmap(to_filter, quad->rect.x(), quad->rect.y(),
670 &paint); 681 &paint);
671 682
672 return surface->makeImageSnapshot(); 683 return surface->makeImageSnapshot();
673 } 684 }
674 685
675 SkBitmap SoftwareRenderer::GetBackdropBitmap( 686 SkBitmap SoftwareRenderer::GetBackdropBitmap(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr); 747 ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr);
737 748
738 if (!filter_backdrop_image) 749 if (!filter_backdrop_image)
739 return nullptr; 750 return nullptr;
740 751
741 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, 752 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode,
742 &filter_backdrop_transform); 753 &filter_backdrop_transform);
743 } 754 }
744 755
745 } // namespace cc 756 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/test/data/white.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698