| 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/memory/ptr_util.h" |
| 7 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 8 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 9 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/output/compositor_frame_ack.h" | 11 #include "cc/output/compositor_frame_ack.h" |
| 11 #include "cc/output/compositor_frame_metadata.h" | 12 #include "cc/output/compositor_frame_metadata.h" |
| 12 #include "cc/output/copy_output_request.h" | 13 #include "cc/output/copy_output_request.h" |
| 13 #include "cc/output/output_surface.h" | 14 #include "cc/output/output_surface.h" |
| 14 #include "cc/output/render_surface_filters.h" | 15 #include "cc/output/render_surface_filters.h" |
| 15 #include "cc/output/software_output_device.h" | 16 #include "cc/output/software_output_device.h" |
| 16 #include "cc/quads/debug_border_draw_quad.h" | 17 #include "cc/quads/debug_border_draw_quad.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 IsScalarNearlyInteger(matrix[SkMatrix::kMTransY]) && | 45 IsScalarNearlyInteger(matrix[SkMatrix::kMTransY]) && |
| 45 SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && | 46 SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && |
| 46 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && | 47 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && |
| 47 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && | 48 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && |
| 48 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && | 49 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && |
| 49 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); | 50 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); |
| 50 } | 51 } |
| 51 | 52 |
| 52 } // anonymous namespace | 53 } // anonymous namespace |
| 53 | 54 |
| 54 scoped_ptr<SoftwareRenderer> SoftwareRenderer::Create( | 55 std::unique_ptr<SoftwareRenderer> SoftwareRenderer::Create( |
| 55 RendererClient* client, | 56 RendererClient* client, |
| 56 const RendererSettings* settings, | 57 const RendererSettings* settings, |
| 57 OutputSurface* output_surface, | 58 OutputSurface* output_surface, |
| 58 ResourceProvider* resource_provider) { | 59 ResourceProvider* resource_provider) { |
| 59 return make_scoped_ptr(new SoftwareRenderer( | 60 return base::WrapUnique(new SoftwareRenderer(client, settings, output_surface, |
| 60 client, settings, output_surface, resource_provider)); | 61 resource_provider)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 SoftwareRenderer::SoftwareRenderer(RendererClient* client, | 64 SoftwareRenderer::SoftwareRenderer(RendererClient* client, |
| 64 const RendererSettings* settings, | 65 const RendererSettings* settings, |
| 65 OutputSurface* output_surface, | 66 OutputSurface* output_surface, |
| 66 ResourceProvider* resource_provider) | 67 ResourceProvider* resource_provider) |
| 67 : DirectRenderer(client, settings, output_surface, resource_provider), | 68 : DirectRenderer(client, settings, output_surface, resource_provider), |
| 68 is_scissor_enabled_(false), | 69 is_scissor_enabled_(false), |
| 69 is_backbuffer_discarded_(false), | 70 is_backbuffer_discarded_(false), |
| 70 output_device_(output_surface->software_device()), | 71 output_device_(output_surface->software_device()), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool SoftwareRenderer::BindFramebufferToTexture( | 145 bool SoftwareRenderer::BindFramebufferToTexture( |
| 145 DrawingFrame* frame, | 146 DrawingFrame* frame, |
| 146 const ScopedResource* texture) { | 147 const ScopedResource* texture) { |
| 147 DCHECK(texture->id()); | 148 DCHECK(texture->id()); |
| 148 | 149 |
| 149 // Explicitly release lock, otherwise we can crash when try to lock | 150 // Explicitly release lock, otherwise we can crash when try to lock |
| 150 // same texture again. | 151 // same texture again. |
| 151 current_framebuffer_lock_ = nullptr; | 152 current_framebuffer_lock_ = nullptr; |
| 152 current_framebuffer_lock_ = make_scoped_ptr( | 153 current_framebuffer_lock_ = |
| 153 new ResourceProvider::ScopedWriteLockSoftware( | 154 base::WrapUnique(new ResourceProvider::ScopedWriteLockSoftware( |
| 154 resource_provider_, texture->id())); | 155 resource_provider_, texture->id())); |
| 155 current_framebuffer_canvas_ = | 156 current_framebuffer_canvas_ = |
| 156 skia::AdoptRef(new SkCanvas(current_framebuffer_lock_->sk_bitmap())); | 157 skia::AdoptRef(new SkCanvas(current_framebuffer_lock_->sk_bitmap())); |
| 157 current_canvas_ = current_framebuffer_canvas_.get(); | 158 current_canvas_ = current_framebuffer_canvas_.get(); |
| 158 return true; | 159 return true; |
| 159 } | 160 } |
| 160 | 161 |
| 161 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { | 162 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { |
| 162 is_scissor_enabled_ = true; | 163 is_scissor_enabled_ = true; |
| 163 scissor_rect_ = scissor_rect; | 164 scissor_rect_ = scissor_rect; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 sk_sp<SkShader> shader; | 510 sk_sp<SkShader> shader; |
| 510 if (!filter_image) { | 511 if (!filter_image) { |
| 511 shader = | 512 shader = |
| 512 SkShader::MakeBitmapShader(*content, SkShader::kClamp_TileMode, | 513 SkShader::MakeBitmapShader(*content, SkShader::kClamp_TileMode, |
| 513 SkShader::kClamp_TileMode, &content_mat); | 514 SkShader::kClamp_TileMode, &content_mat); |
| 514 } else { | 515 } else { |
| 515 shader = filter_image->makeShader(SkShader::kClamp_TileMode, | 516 shader = filter_image->makeShader(SkShader::kClamp_TileMode, |
| 516 SkShader::kClamp_TileMode, &content_mat); | 517 SkShader::kClamp_TileMode, &content_mat); |
| 517 } | 518 } |
| 518 | 519 |
| 519 scoped_ptr<ResourceProvider::ScopedReadLockSoftware> mask_lock; | 520 std::unique_ptr<ResourceProvider::ScopedReadLockSoftware> mask_lock; |
| 520 if (quad->mask_resource_id()) { | 521 if (quad->mask_resource_id()) { |
| 521 mask_lock = scoped_ptr<ResourceProvider::ScopedReadLockSoftware>( | 522 mask_lock = std::unique_ptr<ResourceProvider::ScopedReadLockSoftware>( |
| 522 new ResourceProvider::ScopedReadLockSoftware(resource_provider_, | 523 new ResourceProvider::ScopedReadLockSoftware(resource_provider_, |
| 523 quad->mask_resource_id())); | 524 quad->mask_resource_id())); |
| 524 | 525 |
| 525 if (!mask_lock->valid()) | 526 if (!mask_lock->valid()) |
| 526 return; | 527 return; |
| 527 | 528 |
| 528 const SkBitmap* mask = mask_lock->sk_bitmap(); | 529 const SkBitmap* mask = mask_lock->sk_bitmap(); |
| 529 | 530 |
| 530 // Scale normalized uv rect into absolute texel coordinates. | 531 // Scale normalized uv rect into absolute texel coordinates. |
| 531 SkRect mask_rect = | 532 SkRect mask_rect = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 #else | 568 #else |
| 568 current_paint_.setColor(SK_ColorMAGENTA); | 569 current_paint_.setColor(SK_ColorMAGENTA); |
| 569 #endif | 570 #endif |
| 570 current_paint_.setAlpha(quad->shared_quad_state->opacity * 255); | 571 current_paint_.setAlpha(quad->shared_quad_state->opacity * 255); |
| 571 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), | 572 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), |
| 572 current_paint_); | 573 current_paint_); |
| 573 } | 574 } |
| 574 | 575 |
| 575 void SoftwareRenderer::CopyCurrentRenderPassToBitmap( | 576 void SoftwareRenderer::CopyCurrentRenderPassToBitmap( |
| 576 DrawingFrame* frame, | 577 DrawingFrame* frame, |
| 577 scoped_ptr<CopyOutputRequest> request) { | 578 std::unique_ptr<CopyOutputRequest> request) { |
| 578 gfx::Rect copy_rect = frame->current_render_pass->output_rect; | 579 gfx::Rect copy_rect = frame->current_render_pass->output_rect; |
| 579 if (request->has_area()) | 580 if (request->has_area()) |
| 580 copy_rect.Intersect(request->area()); | 581 copy_rect.Intersect(request->area()); |
| 581 gfx::Rect window_copy_rect = MoveFromDrawToWindowSpace(frame, copy_rect); | 582 gfx::Rect window_copy_rect = MoveFromDrawToWindowSpace(frame, copy_rect); |
| 582 | 583 |
| 583 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 584 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); |
| 584 bitmap->setInfo(SkImageInfo::MakeN32Premul(window_copy_rect.width(), | 585 bitmap->setInfo(SkImageInfo::MakeN32Premul(window_copy_rect.width(), |
| 585 window_copy_rect.height())); | 586 window_copy_rect.height())); |
| 586 current_canvas_->readPixels( | 587 current_canvas_->readPixels( |
| 587 bitmap.get(), window_copy_rect.x(), window_copy_rect.y()); | 588 bitmap.get(), window_copy_rect.x(), window_copy_rect.y()); |
| 588 | 589 |
| 589 request->SendBitmapResult(std::move(bitmap)); | 590 request->SendBitmapResult(std::move(bitmap)); |
| 590 } | 591 } |
| 591 | 592 |
| 592 void SoftwareRenderer::DiscardBackbuffer() { | 593 void SoftwareRenderer::DiscardBackbuffer() { |
| 593 if (is_backbuffer_discarded_) | 594 if (is_backbuffer_discarded_) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 ApplyImageFilter(filter.get(), quad, &backdrop_bitmap); | 715 ApplyImageFilter(filter.get(), quad, &backdrop_bitmap); |
| 715 | 716 |
| 716 if (!filter_backdrop_image) | 717 if (!filter_backdrop_image) |
| 717 return nullptr; | 718 return nullptr; |
| 718 | 719 |
| 719 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, | 720 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, |
| 720 &filter_backdrop_transform); | 721 &filter_backdrop_transform); |
| 721 } | 722 } |
| 722 | 723 |
| 723 } // namespace cc | 724 } // namespace cc |
| OLD | NEW |