Skip to content

Commit

Permalink
viz: Support mask in SkiaRenderer
Browse files Browse the repository at this point in the history
BUG=644851

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I0b8e91c23d022c54121c656b37abec1732a7765b
Reviewed-on: https://chromium-review.googlesource.com/1023790
Reviewed-by: enne <enne@chromium.org>
Commit-Queue: Xing Xu <xing.xu@intel.com>
Cr-Commit-Position: refs/heads/master@{#554276}
  • Loading branch information
axinging authored and Commit Bot committed Apr 27, 2018
1 parent 3880fc0 commit e80ef29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions components/viz/service/display/renderer_pixeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ TYPED_TEST(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {

// This tests the case where we have a RenderPass with a mask, but the quad
// for the masked surface does not include the full surface texture.
TYPED_TEST(NonSkiaRendererPixelTest, RenderPassAndMaskWithPartialQuad) {
TYPED_TEST(RendererPixelTest, RenderPassAndMaskWithPartialQuad) {
gfx::Rect viewport_rect(this->device_viewport_size_);

int root_pass_id = 1;
Expand Down Expand Up @@ -2342,7 +2342,7 @@ TYPED_TEST(NonSkiaRendererPixelTest, RenderPassAndMaskWithPartialQuad) {

// This tests the case where we have a RenderPass with a mask, but the quad
// for the masked surface does not include the full surface texture.
TYPED_TEST(NonSkiaRendererPixelTest, RenderPassAndMaskWithPartialQuad2) {
TYPED_TEST(RendererPixelTest, RenderPassAndMaskWithPartialQuad2) {
gfx::Rect viewport_rect(this->device_viewport_size_);

int root_pass_id = 1;
Expand Down
30 changes: 23 additions & 7 deletions components/viz/service/display/skia_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/effects/SkOverdrawColorFilter.h"
#include "third_party/skia/include/effects/SkShaderMaskFilter.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "ui/gfx/geometry/axis_transform2d.h"
#include "ui/gfx/geometry/rect_conversions.h"
Expand Down Expand Up @@ -766,12 +767,27 @@ void SkiaRenderer::DrawRenderPassQuad(const RenderPassDrawQuad* quad) {
SkMatrix::kFill_ScaleToFit);

sk_sp<SkShader> shader;
shader = content->makeShader(SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode, &content_mat);
shader = content->makeShader(&content_mat);

// TODO(weiliangc): Implement mask. (https://crbug.com/644851)
if (quad->mask_resource_id()) {
NOTIMPLEMENTED();
cc::DisplayResourceProvider::ScopedReadLockSkImage mask_lock(
resource_provider_, quad->mask_resource_id());
const SkImage* image = mask_lock.sk_image();
if (!mask_lock.valid())
return;

// Scale normalized uv rect into absolute texel coordinates.
SkRect mask_rect = gfx::RectFToSkRect(
gfx::ScaleRect(quad->mask_uv_rect, quad->mask_texture_size.width(),
quad->mask_texture_size.height()));

SkMatrix mask_mat;
mask_mat.setRectToRect(mask_rect, dest_rect, SkMatrix::kFill_ScaleToFit);
current_paint_.setMaskFilter(
SkShaderMaskFilter::Make((image->makeShader(&mask_mat))));
current_paint_.setShader(std::move(shader));
current_canvas_->drawRect(dest_visible_rect, current_paint_);
return;
}

// If we have a background filter shader, render its results first.
Expand All @@ -784,10 +800,10 @@ void SkiaRenderer::DrawRenderPassQuad(const RenderPassDrawQuad* quad) {
current_canvas_->drawRect(dest_visible_rect, paint);
current_paint_.setShader(std::move(shader));
current_canvas_->drawRect(dest_visible_rect, current_paint_);
} else {
current_canvas_->drawImageRect(content, content_rect, dest_visible_rect,
&current_paint_);
return;
}
current_canvas_->drawImageRect(content, content_rect, dest_visible_rect,
&current_paint_);
}

void SkiaRenderer::DrawUnsupportedQuad(const DrawQuad* quad) {
Expand Down

0 comments on commit e80ef29

Please sign in to comment.