| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "platform/graphics/RecordingImageBufferSurface.h" | 5 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "platform/Histogram.h" | 9 #include "platform/Histogram.h" |
| 10 #include "platform/graphics/CanvasMetrics.h" | 10 #include "platform/graphics/CanvasMetrics.h" |
| 11 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 11 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 12 #include "platform/graphics/GraphicsContext.h" | 12 #include "platform/graphics/GraphicsContext.h" |
| 13 #include "platform/graphics/ImageBuffer.h" | 13 #include "platform/graphics/ImageBuffer.h" |
| 14 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 14 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 15 #include "platform/graphics/paint/PaintRecorder.h" | 15 #include "platform/graphics/paint/PaintRecorder.h" |
| 16 #include "platform/wtf/PassRefPtr.h" | 16 #include "platform/wtf/PassRefPtr.h" |
| 17 #include "platform/wtf/PtrUtil.h" | 17 #include "platform/wtf/PtrUtil.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 RecordingImageBufferSurface::RecordingImageBufferSurface( | 21 RecordingImageBufferSurface::RecordingImageBufferSurface( |
| 22 const IntSize& size, | 22 const IntSize& size, |
| 23 AllowFallback allow_fallback, |
| 23 OpacityMode opacity_mode, | 24 OpacityMode opacity_mode, |
| 24 const CanvasColorParams& color_params) | 25 const CanvasColorParams& color_params) |
| 25 : ImageBufferSurface(size, opacity_mode, color_params), | 26 : ImageBufferSurface(size, opacity_mode, color_params), |
| 27 allow_fallback_(allow_fallback), |
| 26 image_buffer_(0), | 28 image_buffer_(0), |
| 27 current_frame_pixel_count_(0), | 29 current_frame_pixel_count_(0), |
| 28 previous_frame_pixel_count_(0), | 30 previous_frame_pixel_count_(0), |
| 29 frame_was_cleared_(true), | 31 frame_was_cleared_(true), |
| 30 did_record_draw_commands_in_current_frame_(false), | 32 did_record_draw_commands_in_current_frame_(false), |
| 31 current_frame_has_expensive_op_(false), | 33 current_frame_has_expensive_op_(false), |
| 32 previous_frame_has_expensive_op_(false) { | 34 previous_frame_has_expensive_op_(false) { |
| 33 InitializeCurrentFrame(); | 35 InitializeCurrentFrame(); |
| 34 } | 36 } |
| 35 | 37 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 IntRect write_rect(x, y, orig_info.width(), orig_info.height()); | 72 IntRect write_rect(x, y, orig_info.width(), orig_info.height()); |
| 71 if (write_rect.Contains(IntRect(IntPoint(), size()))) | 73 if (write_rect.Contains(IntRect(IntPoint(), size()))) |
| 72 WillOverwriteCanvas(); | 74 WillOverwriteCanvas(); |
| 73 FallBackToRasterCanvas(kFallbackReasonWritePixels); | 75 FallBackToRasterCanvas(kFallbackReasonWritePixels); |
| 74 } | 76 } |
| 75 return fallback_surface_->WritePixels(orig_info, pixels, row_bytes, x, y); | 77 return fallback_surface_->WritePixels(orig_info, pixels, row_bytes, x, y); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void RecordingImageBufferSurface::FallBackToRasterCanvas( | 80 void RecordingImageBufferSurface::FallBackToRasterCanvas( |
| 79 FallbackReason reason) { | 81 FallbackReason reason) { |
| 82 DCHECK(allow_fallback_ == kAllowFallback); |
| 80 CHECK(reason != kFallbackReasonUnknown); | 83 CHECK(reason != kFallbackReasonUnknown); |
| 81 | 84 |
| 82 if (fallback_surface_) { | 85 if (fallback_surface_) { |
| 83 DCHECK(!current_frame_); | 86 DCHECK(!current_frame_); |
| 84 return; | 87 return; |
| 85 } | 88 } |
| 86 | 89 |
| 87 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 90 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 88 EnumerationHistogram, canvas_fallback_histogram, | 91 EnumerationHistogram, canvas_fallback_histogram, |
| 89 new EnumerationHistogram("Canvas.DisplayListFallbackReason", | 92 new EnumerationHistogram("Canvas.DisplayListFallbackReason", |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 311 } |
| 309 CHECK(current_frame_); | 312 CHECK(current_frame_); |
| 310 return true; | 313 return true; |
| 311 } | 314 } |
| 312 | 315 |
| 313 if (!frame_was_cleared_) { | 316 if (!frame_was_cleared_) { |
| 314 *fallback_reason = kFallbackReasonCanvasNotClearedBetweenFrames; | 317 *fallback_reason = kFallbackReasonCanvasNotClearedBetweenFrames; |
| 315 return false; | 318 return false; |
| 316 } | 319 } |
| 317 | 320 |
| 318 if (current_frame_->getRecordingCanvas()->getSaveCount() - 1 > | 321 if (allow_fallback_ == kAllowFallback && |
| 319 ExpensiveCanvasHeuristicParameters::kExpensiveRecordingStackDepth) { | 322 current_frame_->getRecordingCanvas()->getSaveCount() - 1 > |
| 323 ExpensiveCanvasHeuristicParameters::kExpensiveRecordingStackDepth) { |
| 320 // (getSaveCount() decremented to account for the intial recording canvas | 324 // (getSaveCount() decremented to account for the intial recording canvas |
| 321 // save frame.) | 325 // save frame.) |
| 322 *fallback_reason = kFallbackReasonRunawayStateStack; | 326 *fallback_reason = kFallbackReasonRunawayStateStack; |
| 323 return false; | 327 return false; |
| 324 } | 328 } |
| 325 | 329 |
| 326 previous_frame_ = current_frame_->finishRecordingAsPicture(); | 330 previous_frame_ = current_frame_->finishRecordingAsPicture(); |
| 327 previous_frame_has_expensive_op_ = current_frame_has_expensive_op_; | 331 previous_frame_has_expensive_op_ = current_frame_has_expensive_op_; |
| 328 previous_frame_pixel_count_ = current_frame_pixel_count_; | 332 previous_frame_pixel_count_ = current_frame_pixel_count_; |
| 329 InitializeCurrentFrame(); | 333 InitializeCurrentFrame(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } | 404 } |
| 401 | 405 |
| 402 void RecordingImageBufferSurface::SetIsHidden(bool hidden) { | 406 void RecordingImageBufferSurface::SetIsHidden(bool hidden) { |
| 403 if (fallback_surface_) | 407 if (fallback_surface_) |
| 404 fallback_surface_->SetIsHidden(hidden); | 408 fallback_surface_->SetIsHidden(hidden); |
| 405 else | 409 else |
| 406 ImageBufferSurface::SetIsHidden(hidden); | 410 ImageBufferSurface::SetIsHidden(hidden); |
| 407 } | 411 } |
| 408 | 412 |
| 409 } // namespace blink | 413 } // namespace blink |
| OLD | NEW |