| OLD | NEW |
| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
| 11 #include "cc/output/compositor_frame_metadata.h" | 11 #include "cc/output/compositor_frame_metadata.h" |
| 12 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
| 13 #include "cc/output/output_surface.h" | 13 #include "cc/output/output_surface.h" |
| 14 #include "cc/output/render_surface_filters.h" | 14 #include "cc/output/render_surface_filters.h" |
| 15 #include "cc/output/software_output_device.h" | 15 #include "cc/output/software_output_device.h" |
| 16 #include "cc/quads/checkerboard_draw_quad.h" | 16 #include "cc/quads/checkerboard_draw_quad.h" |
| 17 #include "cc/quads/debug_border_draw_quad.h" | 17 #include "cc/quads/debug_border_draw_quad.h" |
| 18 #include "cc/quads/picture_draw_quad.h" | 18 #include "cc/quads/picture_draw_quad.h" |
| 19 #include "cc/quads/render_pass_draw_quad.h" | 19 #include "cc/quads/render_pass_draw_quad.h" |
| 20 #include "cc/quads/solid_color_draw_quad.h" | 20 #include "cc/quads/solid_color_draw_quad.h" |
| 21 #include "cc/quads/texture_draw_quad.h" | 21 #include "cc/quads/texture_draw_quad.h" |
| 22 #include "cc/quads/tile_draw_quad.h" | 22 #include "cc/quads/tile_draw_quad.h" |
| 23 #include "skia/ext/opacity_draw_filter.h" | 23 #include "skia/ext/opacity_draw_filter.h" |
| 24 #include "third_party/skia/include/core/SkBitmapDevice.h" | 24 #include "third_party/skia/include/core/SkBitmapDevice.h" |
| 25 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 26 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
| 27 #include "third_party/skia/include/core/SkImageFilter.h" | 27 #include "third_party/skia/include/core/SkImageFilter.h" |
| 28 #include "third_party/skia/include/core/SkMatrix.h" | 28 #include "third_party/skia/include/core/SkMatrix.h" |
| 29 #include "third_party/skia/include/core/SkPoint.h" |
| 29 #include "third_party/skia/include/core/SkShader.h" | 30 #include "third_party/skia/include/core/SkShader.h" |
| 30 #include "third_party/skia/include/effects/SkLayerRasterizer.h" | 31 #include "third_party/skia/include/effects/SkLayerRasterizer.h" |
| 31 #include "ui/gfx/geometry/rect_conversions.h" | 32 #include "ui/gfx/geometry/rect_conversions.h" |
| 32 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
| 33 #include "ui/gfx/transform.h" | 34 #include "ui/gfx/transform.h" |
| 34 | 35 |
| 35 namespace cc { | 36 namespace cc { |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 static inline bool IsScalarNearlyInteger(SkScalar scalar) { | 39 static inline bool IsScalarNearlyInteger(SkScalar scalar) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 scissor_rect_ = scissor_rect; | 178 scissor_rect_ = scissor_rect; |
| 178 SetClipRect(scissor_rect); | 179 SetClipRect(scissor_rect); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { | 182 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { |
| 182 // Skia applies the current matrix to clip rects so we reset it temporary. | 183 // Skia applies the current matrix to clip rects so we reset it temporary. |
| 183 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); | 184 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); |
| 184 current_canvas_->resetMatrix(); | 185 current_canvas_->resetMatrix(); |
| 185 current_canvas_->clipRect(gfx::RectToSkRect(rect), SkRegion::kReplace_Op); | 186 current_canvas_->clipRect(gfx::RectToSkRect(rect), SkRegion::kReplace_Op); |
| 186 current_canvas_->setMatrix(current_matrix); | 187 current_canvas_->setMatrix(current_matrix); |
| 188 current_canvas_->save(); //TODO(awoloszyn) this seems fishy. |
| 187 } | 189 } |
| 188 | 190 |
| 189 void SoftwareRenderer::ClearCanvas(SkColor color) { | 191 void SoftwareRenderer::ClearCanvas(SkColor color) { |
| 190 // SkCanvas::clear doesn't respect the current clipping region | 192 // SkCanvas::clear doesn't respect the current clipping region |
| 191 // so we SkCanvas::drawColor instead if scissoring is active. | 193 // so we SkCanvas::drawColor instead if scissoring is active. |
| 192 if (is_scissor_enabled_) | 194 if (is_scissor_enabled_) |
| 193 current_canvas_->drawColor(color, SkXfermode::kSrc_Mode); | 195 current_canvas_->drawColor(color, SkXfermode::kSrc_Mode); |
| 194 else | 196 else |
| 195 current_canvas_->clear(color); | 197 current_canvas_->clear(color); |
| 196 } | 198 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 222 case ResourceProvider::Bitmap: | 224 case ResourceProvider::Bitmap: |
| 223 return true; | 225 return true; |
| 224 case ResourceProvider::InvalidType: | 226 case ResourceProvider::InvalidType: |
| 225 break; | 227 break; |
| 226 } | 228 } |
| 227 | 229 |
| 228 LOG(FATAL) << "Invalid resource type."; | 230 LOG(FATAL) << "Invalid resource type."; |
| 229 return false; | 231 return false; |
| 230 } | 232 } |
| 231 | 233 |
| 232 void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { | 234 void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, |
| 235 const DrawQuad* quad, |
| 236 const gfx::QuadF* draw_region) { |
| 237 if (draw_region) { |
| 238 current_canvas_->save(); |
| 239 } |
| 240 |
| 233 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); | 241 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); |
| 234 gfx::Transform quad_rect_matrix; | 242 gfx::Transform quad_rect_matrix; |
| 235 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 243 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
| 236 gfx::Transform contents_device_transform = | 244 gfx::Transform contents_device_transform = |
| 237 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 245 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 238 contents_device_transform.FlattenTo2d(); | 246 contents_device_transform.FlattenTo2d(); |
| 239 SkMatrix sk_device_matrix; | 247 SkMatrix sk_device_matrix; |
| 240 gfx::TransformToFlattenedSkMatrix(contents_device_transform, | 248 gfx::TransformToFlattenedSkMatrix(contents_device_transform, |
| 241 &sk_device_matrix); | 249 &sk_device_matrix); |
| 242 current_canvas_->setMatrix(sk_device_matrix); | 250 current_canvas_->setMatrix(sk_device_matrix); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 255 } | 263 } |
| 256 | 264 |
| 257 if (quad->ShouldDrawWithBlending() || | 265 if (quad->ShouldDrawWithBlending() || |
| 258 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode) { | 266 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode) { |
| 259 current_paint_.setAlpha(quad->opacity() * 255); | 267 current_paint_.setAlpha(quad->opacity() * 255); |
| 260 current_paint_.setXfermodeMode(quad->shared_quad_state->blend_mode); | 268 current_paint_.setXfermodeMode(quad->shared_quad_state->blend_mode); |
| 261 } else { | 269 } else { |
| 262 current_paint_.setXfermodeMode(SkXfermode::kSrc_Mode); | 270 current_paint_.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 263 } | 271 } |
| 264 | 272 |
| 273 if (draw_region) { |
| 274 gfx::QuadF local_draw_region(*draw_region); |
| 275 SkPath draw_region_clip_path; |
| 276 local_draw_region -= |
| 277 gfx::Vector2dF(quad->visible_rect.x(), quad->visible_rect.y()); |
| 278 local_draw_region.Scale(1.0f / quad->visible_rect.width(), |
| 279 1.0f / quad->visible_rect.height()); |
| 280 local_draw_region -= gfx::Vector2dF(0.5f, 0.5f); |
| 281 |
| 282 SkPoint clip_points[4]; |
| 283 QuadFToSkPoints(local_draw_region, clip_points); |
| 284 draw_region_clip_path.addPoly(clip_points, 4, true); |
| 285 |
| 286 current_canvas_->clipPath( |
| 287 draw_region_clip_path, SkRegion::kIntersect_Op, false); |
| 288 } |
| 289 |
| 265 switch (quad->material) { | 290 switch (quad->material) { |
| 266 case DrawQuad::CHECKERBOARD: | 291 case DrawQuad::CHECKERBOARD: |
| 267 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); | 292 // TODO(thildebr) For now since checkerboards shouldn't be part of a 3D |
| 293 // context, clipping regions aren't supported so we skip drawing them |
| 294 // if this becomes the case. |
| 295 if (!draw_region) { |
| 296 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); |
| 297 } |
| 268 break; | 298 break; |
| 269 case DrawQuad::DEBUG_BORDER: | 299 case DrawQuad::DEBUG_BORDER: |
| 270 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 300 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
| 271 break; | 301 break; |
| 272 case DrawQuad::PICTURE_CONTENT: | 302 case DrawQuad::PICTURE_CONTENT: |
| 273 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad)); | 303 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad)); |
| 274 break; | 304 break; |
| 275 case DrawQuad::RENDER_PASS: | 305 case DrawQuad::RENDER_PASS: |
| 276 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); | 306 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); |
| 277 break; | 307 break; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 292 case DrawQuad::INVALID: | 322 case DrawQuad::INVALID: |
| 293 case DrawQuad::IO_SURFACE_CONTENT: | 323 case DrawQuad::IO_SURFACE_CONTENT: |
| 294 case DrawQuad::YUV_VIDEO_CONTENT: | 324 case DrawQuad::YUV_VIDEO_CONTENT: |
| 295 case DrawQuad::STREAM_VIDEO_CONTENT: | 325 case DrawQuad::STREAM_VIDEO_CONTENT: |
| 296 DrawUnsupportedQuad(frame, quad); | 326 DrawUnsupportedQuad(frame, quad); |
| 297 NOTREACHED(); | 327 NOTREACHED(); |
| 298 break; | 328 break; |
| 299 } | 329 } |
| 300 | 330 |
| 301 current_canvas_->resetMatrix(); | 331 current_canvas_->resetMatrix(); |
| 332 if (draw_region) { |
| 333 current_canvas_->restore(); |
| 334 } |
| 302 } | 335 } |
| 303 | 336 |
| 304 void SoftwareRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, | 337 void SoftwareRenderer::DrawCheckerboardQuad(const DrawingFrame* frame, |
| 305 const CheckerboardDrawQuad* quad) { | 338 const CheckerboardDrawQuad* quad) { |
| 306 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 339 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
| 307 QuadVertexRect(), quad->rect, quad->visible_rect); | 340 QuadVertexRect(), quad->rect, quad->visible_rect); |
| 308 current_paint_.setColor(quad->color); | 341 current_paint_.setColor(quad->color); |
| 309 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); | 342 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); |
| 310 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), | 343 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), |
| 311 current_paint_); | 344 current_paint_); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 634 } |
| 602 | 635 |
| 603 void SoftwareRenderer::DidChangeVisibility() { | 636 void SoftwareRenderer::DidChangeVisibility() { |
| 604 if (visible()) | 637 if (visible()) |
| 605 EnsureBackbuffer(); | 638 EnsureBackbuffer(); |
| 606 else | 639 else |
| 607 DiscardBackbuffer(); | 640 DiscardBackbuffer(); |
| 608 } | 641 } |
| 609 | 642 |
| 610 } // namespace cc | 643 } // namespace cc |
| OLD | NEW |