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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 RendererClient* client, | 46 RendererClient* client, |
47 OutputSurface* output_surface, | 47 OutputSurface* output_surface, |
48 ResourceProvider* resource_provider) { | 48 ResourceProvider* resource_provider) { |
49 return make_scoped_ptr( | 49 return make_scoped_ptr( |
50 new SoftwareRenderer(client, output_surface, resource_provider)); | 50 new SoftwareRenderer(client, output_surface, resource_provider)); |
51 } | 51 } |
52 | 52 |
53 SoftwareRenderer::SoftwareRenderer(RendererClient* client, | 53 SoftwareRenderer::SoftwareRenderer(RendererClient* client, |
54 OutputSurface* output_surface, | 54 OutputSurface* output_surface, |
55 ResourceProvider* resource_provider) | 55 ResourceProvider* resource_provider) |
56 : DirectRenderer(client, resource_provider), | 56 : DirectRenderer(client, output_surface, resource_provider), |
57 visible_(true), | 57 visible_(true), |
58 is_scissor_enabled_(false), | 58 is_scissor_enabled_(false), |
59 is_viewport_changed_(true), | 59 is_viewport_changed_(true), |
60 output_surface_(output_surface), | |
61 output_device_(output_surface->software_device()), | 60 output_device_(output_surface->software_device()), |
62 current_canvas_(NULL) { | 61 current_canvas_(NULL) { |
63 if (resource_provider_) { | 62 if (resource_provider_) { |
64 capabilities_.max_texture_size = resource_provider_->max_texture_size(); | 63 capabilities_.max_texture_size = resource_provider_->max_texture_size(); |
65 capabilities_.best_texture_format = | 64 capabilities_.best_texture_format = |
66 resource_provider_->best_texture_format(); | 65 resource_provider_->best_texture_format(); |
67 } | 66 } |
68 capabilities_.using_set_visibility = true; | 67 capabilities_.using_set_visibility = true; |
69 // The updater can access bitmaps while the SoftwareRenderer is using them. | 68 // The updater can access bitmaps while the SoftwareRenderer is using them. |
70 capabilities_.allow_partial_texture_updates = true; | 69 capabilities_.allow_partial_texture_updates = true; |
(...skipping 10 matching lines...) Expand all Loading... |
81 } | 80 } |
82 | 81 |
83 void SoftwareRenderer::ViewportChanged() { | 82 void SoftwareRenderer::ViewportChanged() { |
84 is_viewport_changed_ = true; | 83 is_viewport_changed_ = true; |
85 } | 84 } |
86 | 85 |
87 void SoftwareRenderer::BeginDrawingFrame(DrawingFrame* frame) { | 86 void SoftwareRenderer::BeginDrawingFrame(DrawingFrame* frame) { |
88 TRACE_EVENT0("cc", "SoftwareRenderer::BeginDrawingFrame"); | 87 TRACE_EVENT0("cc", "SoftwareRenderer::BeginDrawingFrame"); |
89 if (is_viewport_changed_) { | 88 if (is_viewport_changed_) { |
90 is_viewport_changed_ = false; | 89 is_viewport_changed_ = false; |
91 output_device_->Resize(ViewportSize()); | 90 output_device_->Resize(client_->DeviceViewport().size()); |
92 } | 91 } |
93 root_canvas_ = output_device_->BeginPaint( | 92 root_canvas_ = output_device_->BeginPaint( |
94 gfx::ToEnclosingRect(frame->root_damage_rect)); | 93 gfx::ToEnclosingRect(frame->root_damage_rect)); |
95 } | 94 } |
96 | 95 |
97 void SoftwareRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 96 void SoftwareRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
98 TRACE_EVENT0("cc", "SoftwareRenderer::FinishDrawingFrame"); | 97 TRACE_EVENT0("cc", "SoftwareRenderer::FinishDrawingFrame"); |
99 current_framebuffer_lock_.reset(); | 98 current_framebuffer_lock_.reset(); |
100 current_canvas_ = NULL; | 99 current_canvas_ = NULL; |
101 root_canvas_ = NULL; | 100 root_canvas_ = NULL; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void SoftwareRenderer::Finish() {} | 138 void SoftwareRenderer::Finish() {} |
140 | 139 |
141 void SoftwareRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { | 140 void SoftwareRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { |
142 current_framebuffer_lock_.reset(); | 141 current_framebuffer_lock_.reset(); |
143 current_canvas_ = root_canvas_; | 142 current_canvas_ = root_canvas_; |
144 } | 143 } |
145 | 144 |
146 bool SoftwareRenderer::BindFramebufferToTexture( | 145 bool SoftwareRenderer::BindFramebufferToTexture( |
147 DrawingFrame* frame, | 146 DrawingFrame* frame, |
148 const ScopedResource* texture, | 147 const ScopedResource* texture, |
149 gfx::Rect framebuffer_rect) { | 148 gfx::Rect target_rect) { |
150 current_framebuffer_lock_.reset(); | 149 current_framebuffer_lock_.reset(); |
151 current_framebuffer_lock_ = make_scoped_ptr( | 150 current_framebuffer_lock_ = make_scoped_ptr( |
152 new ResourceProvider::ScopedWriteLockSoftware( | 151 new ResourceProvider::ScopedWriteLockSoftware( |
153 resource_provider_, texture->id())); | 152 resource_provider_, texture->id())); |
154 current_canvas_ = current_framebuffer_lock_->sk_canvas(); | 153 current_canvas_ = current_framebuffer_lock_->sk_canvas(); |
155 InitializeMatrices(frame, framebuffer_rect, false); | 154 InitializeViewport(frame, |
156 SetDrawViewportSize(framebuffer_rect.size()); | 155 target_rect, |
157 | 156 gfx::Rect(target_rect.size()), |
| 157 target_rect.size(), |
| 158 false); |
158 return true; | 159 return true; |
159 } | 160 } |
160 | 161 |
161 void SoftwareRenderer::SetScissorTestRect(gfx::Rect scissor_rect) { | 162 void SoftwareRenderer::SetScissorTestRect(gfx::Rect scissor_rect) { |
162 is_scissor_enabled_ = true; | 163 is_scissor_enabled_ = true; |
163 scissor_rect_ = scissor_rect; | 164 scissor_rect_ = scissor_rect; |
164 SetClipRect(scissor_rect); | 165 SetClipRect(scissor_rect); |
165 } | 166 } |
166 | 167 |
167 void SoftwareRenderer::SetClipRect(gfx::Rect rect) { | 168 void SoftwareRenderer::SetClipRect(gfx::Rect rect) { |
(...skipping 18 matching lines...) Expand all Loading... |
186 ClearCanvas(SkColorSetARGB(0, 0, 0, 0)); | 187 ClearCanvas(SkColorSetARGB(0, 0, 0, 0)); |
187 } else { | 188 } else { |
188 #ifndef NDEBUG | 189 #ifndef NDEBUG |
189 // On DEBUG builds, opaque render passes are cleared to blue | 190 // On DEBUG builds, opaque render passes are cleared to blue |
190 // to easily see regions that were not drawn on the screen. | 191 // to easily see regions that were not drawn on the screen. |
191 ClearCanvas(SkColorSetARGB(255, 0, 0, 255)); | 192 ClearCanvas(SkColorSetARGB(255, 0, 0, 255)); |
192 #endif | 193 #endif |
193 } | 194 } |
194 } | 195 } |
195 | 196 |
196 void SoftwareRenderer::SetDrawViewportSize(gfx::Size viewport_size) {} | 197 void SoftwareRenderer::SetDrawViewport(gfx::Rect window_space_viewport) {} |
197 | 198 |
198 bool SoftwareRenderer::IsSoftwareResource( | 199 bool SoftwareRenderer::IsSoftwareResource( |
199 ResourceProvider::ResourceId resource_id) const { | 200 ResourceProvider::ResourceId resource_id) const { |
200 switch (resource_provider_->GetResourceType(resource_id)) { | 201 switch (resource_provider_->GetResourceType(resource_id)) { |
201 case ResourceProvider::GLTexture: | 202 case ResourceProvider::GLTexture: |
202 return false; | 203 return false; |
203 case ResourceProvider::Bitmap: | 204 case ResourceProvider::Bitmap: |
204 return true; | 205 return true; |
205 } | 206 } |
206 | 207 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 current_paint_.setColor(SK_ColorMAGENTA); | 431 current_paint_.setColor(SK_ColorMAGENTA); |
431 #endif | 432 #endif |
432 current_paint_.setAlpha(quad->opacity() * 255); | 433 current_paint_.setAlpha(quad->opacity() * 255); |
433 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), | 434 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), |
434 current_paint_); | 435 current_paint_); |
435 } | 436 } |
436 | 437 |
437 void SoftwareRenderer::CopyCurrentRenderPassToBitmap( | 438 void SoftwareRenderer::CopyCurrentRenderPassToBitmap( |
438 DrawingFrame* frame, | 439 DrawingFrame* frame, |
439 scoped_ptr<CopyOutputRequest> request) { | 440 scoped_ptr<CopyOutputRequest> request) { |
440 gfx::Size render_pass_size = frame->current_render_pass->output_rect.size(); | |
441 | |
442 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 441 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
443 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 442 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
444 render_pass_size.width(), | 443 current_viewport_rect_.width(), |
445 render_pass_size.height()); | 444 current_viewport_rect_.height()); |
446 current_canvas_->readPixels(bitmap.get(), 0, 0); | 445 current_canvas_->readPixels( |
| 446 bitmap.get(), current_viewport_rect_.x(), current_viewport_rect_.y()); |
447 | 447 |
448 request->SendBitmapResult(bitmap.Pass()); | 448 request->SendBitmapResult(bitmap.Pass()); |
449 } | 449 } |
450 | 450 |
451 void SoftwareRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { | 451 void SoftwareRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { |
452 TRACE_EVENT0("cc", "SoftwareRenderer::GetFramebufferPixels"); | 452 TRACE_EVENT0("cc", "SoftwareRenderer::GetFramebufferPixels"); |
453 SkBitmap subset_bitmap; | 453 SkBitmap subset_bitmap; |
| 454 rect += current_viewport_rect_.OffsetFromOrigin(); |
454 output_device_->CopyToBitmap(rect, &subset_bitmap); | 455 output_device_->CopyToBitmap(rect, &subset_bitmap); |
455 subset_bitmap.copyPixelsTo(pixels, | 456 subset_bitmap.copyPixelsTo(pixels, |
456 4 * rect.width() * rect.height(), | 457 4 * rect.width() * rect.height(), |
457 4 * rect.width()); | 458 4 * rect.width()); |
458 } | 459 } |
459 | 460 |
460 void SoftwareRenderer::SetVisible(bool visible) { | 461 void SoftwareRenderer::SetVisible(bool visible) { |
461 if (visible_ == visible) | 462 if (visible_ == visible) |
462 return; | 463 return; |
463 visible_ = visible; | 464 visible_ = visible; |
464 } | 465 } |
465 | 466 |
466 } // namespace cc | 467 } // namespace cc |
OLD | NEW |