| 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/trace_event/trace_event.h" | 7 #include "base/trace_event/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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 // Explicitly release lock, otherwise we can crash when try to lock | 166 // Explicitly release lock, otherwise we can crash when try to lock |
| 167 // same texture again. | 167 // same texture again. |
| 168 current_framebuffer_lock_ = nullptr; | 168 current_framebuffer_lock_ = nullptr; |
| 169 current_framebuffer_lock_ = make_scoped_ptr( | 169 current_framebuffer_lock_ = make_scoped_ptr( |
| 170 new ResourceProvider::ScopedWriteLockSoftware( | 170 new ResourceProvider::ScopedWriteLockSoftware( |
| 171 resource_provider_, texture->id())); | 171 resource_provider_, texture->id())); |
| 172 current_framebuffer_canvas_ = | 172 current_framebuffer_canvas_ = |
| 173 skia::AdoptRef(new SkCanvas(current_framebuffer_lock_->sk_bitmap())); | 173 skia::AdoptRef(new SkCanvas(current_framebuffer_lock_->sk_bitmap())); |
| 174 current_canvas_ = current_framebuffer_canvas_.get(); | 174 current_canvas_ = current_framebuffer_canvas_.get(); |
| 175 InitializeViewport(frame, | |
| 176 target_rect, | |
| 177 gfx::Rect(target_rect.size()), | |
| 178 target_rect.size()); | |
| 179 return true; | 175 return true; |
| 180 } | 176 } |
| 181 | 177 |
| 182 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { | 178 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { |
| 183 is_scissor_enabled_ = true; | 179 is_scissor_enabled_ = true; |
| 184 scissor_rect_ = scissor_rect; | 180 scissor_rect_ = scissor_rect; |
| 185 SetClipRect(scissor_rect); | 181 SetClipRect(scissor_rect); |
| 186 } | 182 } |
| 187 | 183 |
| 188 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { | 184 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { |
| 189 // Skia applies the current matrix to clip rects so we reset it temporary. | 185 // Skia applies the current matrix to clip rects so we reset it temporary. |
| 190 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); | 186 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); |
| 191 current_canvas_->resetMatrix(); | 187 current_canvas_->resetMatrix(); |
| 192 current_canvas_->clipRect(gfx::RectToSkRect(rect), SkRegion::kReplace_Op); | 188 current_canvas_->clipRect(gfx::RectToSkRect(rect), SkRegion::kReplace_Op); |
| 193 current_canvas_->setMatrix(current_matrix); | 189 current_canvas_->setMatrix(current_matrix); |
| 194 } | 190 } |
| 195 | 191 |
| 196 void SoftwareRenderer::ClearCanvas(SkColor color) { | 192 void SoftwareRenderer::ClearCanvas(SkColor color) { |
| 197 // SkCanvas::clear doesn't respect the current clipping region | 193 // SkCanvas::clear doesn't respect the current clipping region |
| 198 // so we SkCanvas::drawColor instead if scissoring is active. | 194 // so we SkCanvas::drawColor instead if scissoring is active. |
| 199 if (is_scissor_enabled_) | 195 if (is_scissor_enabled_) |
| 200 current_canvas_->drawColor(color, SkXfermode::kSrc_Mode); | 196 current_canvas_->drawColor(color, SkXfermode::kSrc_Mode); |
| 201 else | 197 else |
| 202 current_canvas_->clear(color); | 198 current_canvas_->clear(color); |
| 203 } | 199 } |
| 204 | 200 |
| 205 void SoftwareRenderer::DiscardPixels(bool has_external_stencil_test, | 201 void SoftwareRenderer::ClearFramebuffer(DrawingFrame* frame) { |
| 206 bool draw_rect_covers_full_surface) {} | |
| 207 | |
| 208 void SoftwareRenderer::ClearFramebuffer(DrawingFrame* frame, | |
| 209 bool has_external_stencil_test) { | |
| 210 if (frame->current_render_pass->has_transparent_background) { | 202 if (frame->current_render_pass->has_transparent_background) { |
| 211 ClearCanvas(SkColorSetARGB(0, 0, 0, 0)); | 203 ClearCanvas(SkColorSetARGB(0, 0, 0, 0)); |
| 212 } else { | 204 } else { |
| 213 #ifndef NDEBUG | 205 #ifndef NDEBUG |
| 214 // On DEBUG builds, opaque render passes are cleared to blue | 206 // On DEBUG builds, opaque render passes are cleared to blue |
| 215 // to easily see regions that were not drawn on the screen. | 207 // to easily see regions that were not drawn on the screen. |
| 216 ClearCanvas(SkColorSetARGB(255, 0, 0, 255)); | 208 ClearCanvas(SkColorSetARGB(255, 0, 0, 255)); |
| 217 #endif | 209 #endif |
| 218 } | 210 } |
| 219 } | 211 } |
| 220 | 212 |
| 213 void SoftwareRenderer::PrepareSurfaceForPass( |
| 214 DrawingFrame* frame, |
| 215 SurfaceInitializationMode initialization_mode, |
| 216 const gfx::Rect& render_pass_scissor) { |
| 217 switch (initialization_mode) { |
| 218 case SURFACE_INITIALIZATION_MODE_PRESERVE: |
| 219 EnsureScissorTestDisabled(); |
| 220 return; |
| 221 case SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR: |
| 222 EnsureScissorTestDisabled(); |
| 223 ClearFramebuffer(frame); |
| 224 break; |
| 225 case SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR: |
| 226 SetScissorTestRect(render_pass_scissor); |
| 227 ClearFramebuffer(frame); |
| 228 break; |
| 229 } |
| 230 } |
| 231 |
| 221 void SoftwareRenderer::SetDrawViewport( | 232 void SoftwareRenderer::SetDrawViewport( |
| 222 const gfx::Rect& window_space_viewport) {} | 233 const gfx::Rect& window_space_viewport) {} |
| 223 | 234 |
| 224 bool SoftwareRenderer::IsSoftwareResource( | 235 bool SoftwareRenderer::IsSoftwareResource( |
| 225 ResourceProvider::ResourceId resource_id) const { | 236 ResourceProvider::ResourceId resource_id) const { |
| 226 switch (resource_provider_->GetResourceType(resource_id)) { | 237 switch (resource_provider_->GetResourceType(resource_id)) { |
| 227 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: | 238 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: |
| 228 return false; | 239 return false; |
| 229 case ResourceProvider::RESOURCE_TYPE_BITMAP: | 240 case ResourceProvider::RESOURCE_TYPE_BITMAP: |
| 230 return true; | 241 return true; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 } | 654 } |
| 644 | 655 |
| 645 void SoftwareRenderer::DidChangeVisibility() { | 656 void SoftwareRenderer::DidChangeVisibility() { |
| 646 if (visible()) | 657 if (visible()) |
| 647 EnsureBackbuffer(); | 658 EnsureBackbuffer(); |
| 648 else | 659 else |
| 649 DiscardBackbuffer(); | 660 DiscardBackbuffer(); |
| 650 } | 661 } |
| 651 | 662 |
| 652 } // namespace cc | 663 } // namespace cc |
| OLD | NEW |