| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // The time line code does not expect a timeConstant of 0. (IT | 195 // The time line code does not expect a timeConstant of 0. (IT |
| 196 // returns NaN or Infinity due to division by zero. The caller | 196 // returns NaN or Infinity due to division by zero. The caller |
| 197 // should have converted this to a SetValueEvent. | 197 // should have converted this to a SetValueEvent. |
| 198 DCHECK_NE(time_constant, 0); | 198 DCHECK_NE(time_constant, 0); |
| 199 return WTF::WrapUnique( | 199 return WTF::WrapUnique( |
| 200 new ParamEvent(ParamEvent::kSetTarget, value, time, time_constant)); | 200 new ParamEvent(ParamEvent::kSetTarget, value, time, time_constant)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 std::unique_ptr<AudioParamTimeline::ParamEvent> | 203 std::unique_ptr<AudioParamTimeline::ParamEvent> |
| 204 AudioParamTimeline::ParamEvent::CreateSetValueCurveEvent( | 204 AudioParamTimeline::ParamEvent::CreateSetValueCurveEvent( |
| 205 const DOMFloat32Array* curve, | 205 const Vector<float>& curve, |
| 206 double time, | 206 double time, |
| 207 double duration) { | 207 double duration) { |
| 208 double curve_points = (curve->length() - 1) / duration; | 208 double curve_points = (curve.size() - 1) / duration; |
| 209 float end_value = curve->Data()[curve->length() - 1]; | 209 float end_value = curve.Data()[curve.size() - 1]; |
| 210 | 210 |
| 211 return WTF::WrapUnique(new ParamEvent(ParamEvent::kSetValueCurve, time, | 211 return WTF::WrapUnique(new ParamEvent(ParamEvent::kSetValueCurve, time, |
| 212 duration, curve, curve_points, | 212 duration, curve, curve_points, |
| 213 end_value)); | 213 end_value)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 std::unique_ptr<AudioParamTimeline::ParamEvent> | 216 std::unique_ptr<AudioParamTimeline::ParamEvent> |
| 217 AudioParamTimeline::ParamEvent::CreateCancelValuesEvent( | 217 AudioParamTimeline::ParamEvent::CreateCancelValuesEvent( |
| 218 double time, | 218 double time, |
| 219 std::unique_ptr<ParamEvent> saved_event) { | 219 std::unique_ptr<ParamEvent> saved_event) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 saved_event_(nullptr), | 354 saved_event_(nullptr), |
| 355 needs_time_clamp_check_(true), | 355 needs_time_clamp_check_(true), |
| 356 has_default_cancelled_value_(false) { | 356 has_default_cancelled_value_(false) { |
| 357 DCHECK_EQ(type, ParamEvent::kSetTarget); | 357 DCHECK_EQ(type, ParamEvent::kSetTarget); |
| 358 } | 358 } |
| 359 | 359 |
| 360 // Create a setValueCurve event | 360 // Create a setValueCurve event |
| 361 AudioParamTimeline::ParamEvent::ParamEvent(ParamEvent::Type type, | 361 AudioParamTimeline::ParamEvent::ParamEvent(ParamEvent::Type type, |
| 362 double time, | 362 double time, |
| 363 double duration, | 363 double duration, |
| 364 const DOMFloat32Array* curve, | 364 const Vector<float>& curve, |
| 365 double curve_points_per_second, | 365 double curve_points_per_second, |
| 366 float curve_end_value) | 366 float curve_end_value) |
| 367 : type_(type), | 367 : type_(type), |
| 368 value_(0), | 368 value_(0), |
| 369 time_(time), | 369 time_(time), |
| 370 initial_value_(0), | 370 initial_value_(0), |
| 371 call_time_(0), | 371 call_time_(0), |
| 372 time_constant_(0), | 372 time_constant_(0), |
| 373 duration_(duration), | 373 duration_(duration), |
| 374 curve_points_per_second_(curve_points_per_second), | 374 curve_points_per_second_(curve_points_per_second), |
| 375 curve_end_value_(curve_end_value), | 375 curve_end_value_(curve_end_value), |
| 376 saved_event_(nullptr), | 376 saved_event_(nullptr), |
| 377 needs_time_clamp_check_(true), | 377 needs_time_clamp_check_(true), |
| 378 has_default_cancelled_value_(false) { | 378 has_default_cancelled_value_(false) { |
| 379 DCHECK_EQ(type, ParamEvent::kSetValueCurve); | 379 DCHECK_EQ(type, ParamEvent::kSetValueCurve); |
| 380 if (curve) { | 380 unsigned curve_length = curve.size(); |
| 381 unsigned curve_length = curve->length(); | 381 curve_.Resize(curve_length); |
| 382 curve_.Resize(curve->length()); | 382 memcpy(curve_.Data(), curve.Data(), curve_length * sizeof(float)); |
| 383 memcpy(curve_.Data(), curve->Data(), curve_length * sizeof(float)); | |
| 384 } | |
| 385 } | 383 } |
| 386 | 384 |
| 387 // Create CancelValues event | 385 // Create CancelValues event |
| 388 AudioParamTimeline::ParamEvent::ParamEvent( | 386 AudioParamTimeline::ParamEvent::ParamEvent( |
| 389 ParamEvent::Type type, | 387 ParamEvent::Type type, |
| 390 double time, | 388 double time, |
| 391 std::unique_ptr<ParamEvent> saved_event) | 389 std::unique_ptr<ParamEvent> saved_event) |
| 392 : type_(type), | 390 : type_(type), |
| 393 value_(0), | 391 value_(0), |
| 394 time_(time), | 392 time_(time), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 // If timeConstant = 0, we instantly jump to the target value, so | 474 // If timeConstant = 0, we instantly jump to the target value, so |
| 477 // insert a SetValueEvent instead of SetTargetEvent. | 475 // insert a SetValueEvent instead of SetTargetEvent. |
| 478 if (time_constant == 0) { | 476 if (time_constant == 0) { |
| 479 InsertEvent(ParamEvent::CreateSetValueEvent(target, time), exception_state); | 477 InsertEvent(ParamEvent::CreateSetValueEvent(target, time), exception_state); |
| 480 } else { | 478 } else { |
| 481 InsertEvent(ParamEvent::CreateSetTargetEvent(target, time, time_constant), | 479 InsertEvent(ParamEvent::CreateSetTargetEvent(target, time, time_constant), |
| 482 exception_state); | 480 exception_state); |
| 483 } | 481 } |
| 484 } | 482 } |
| 485 | 483 |
| 486 void AudioParamTimeline::SetValueCurveAtTime(DOMFloat32Array* curve, | 484 void AudioParamTimeline::SetValueCurveAtTime(const Vector<float>& curve, |
| 487 double time, | 485 double time, |
| 488 double duration, | 486 double duration, |
| 489 ExceptionState& exception_state) { | 487 ExceptionState& exception_state) { |
| 490 DCHECK(IsMainThread()); | 488 DCHECK(IsMainThread()); |
| 491 DCHECK(curve); | |
| 492 | 489 |
| 493 if (!IsNonNegativeAudioParamTime(time, exception_state) || | 490 if (!IsNonNegativeAudioParamTime(time, exception_state) || |
| 494 !IsPositiveAudioParamTime(duration, exception_state, "Duration")) | 491 !IsPositiveAudioParamTime(duration, exception_state, "Duration")) |
| 495 return; | 492 return; |
| 496 | 493 |
| 497 if (curve->length() < 2) { | 494 if (curve.size() < 2) { |
| 498 exception_state.ThrowDOMException( | 495 exception_state.ThrowDOMException( |
| 499 kInvalidStateError, ExceptionMessages::IndexExceedsMinimumBound( | 496 kInvalidStateError, |
| 500 "curve length", curve->length(), 2U)); | 497 ExceptionMessages::IndexExceedsMinimumBound( |
| 498 "curve length", curve.size(), static_cast<size_t>(2))); |
| 501 return; | 499 return; |
| 502 } | 500 } |
| 503 | 501 |
| 504 MutexLocker locker(events_lock_); | 502 MutexLocker locker(events_lock_); |
| 505 InsertEvent(ParamEvent::CreateSetValueCurveEvent(curve, time, duration), | 503 InsertEvent(ParamEvent::CreateSetValueCurveEvent(curve, time, duration), |
| 506 exception_state); | 504 exception_state); |
| 507 | 505 |
| 508 // Insert a setValueAtTime event too to establish an event so that all | 506 // Insert a setValueAtTime event too to establish an event so that all |
| 509 // following events will process from the end of the curve instead of the | 507 // following events will process from the end of the curve instead of the |
| 510 // beginning. | 508 // beginning. |
| 511 InsertEvent(ParamEvent::CreateSetValueEvent( | 509 InsertEvent(ParamEvent::CreateSetValueEvent(curve.Data()[curve.size() - 1], |
| 512 curve->Data()[curve->length() - 1], time + duration), | 510 time + duration), |
| 513 exception_state); | 511 exception_state); |
| 514 } | 512 } |
| 515 | 513 |
| 516 void AudioParamTimeline::InsertEvent(std::unique_ptr<ParamEvent> event, | 514 void AudioParamTimeline::InsertEvent(std::unique_ptr<ParamEvent> event, |
| 517 ExceptionState& exception_state) { | 515 ExceptionState& exception_state) { |
| 518 DCHECK(IsMainThread()); | 516 DCHECK(IsMainThread()); |
| 519 | 517 |
| 520 // Sanity check the event. Be super careful we're not getting infected with | 518 // Sanity check the event. Be super careful we're not getting infected with |
| 521 // NaN or Inf. These should have been handled by the caller. | 519 // NaN or Inf. These should have been handled by the caller. |
| 522 bool is_valid = event->GetType() < ParamEvent::kLastType && | 520 bool is_valid = event->GetType() < ParamEvent::kLastType && |
| (...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 unsigned write_index) { | 1774 unsigned write_index) { |
| 1777 size_t index = write_index; | 1775 size_t index = write_index; |
| 1778 | 1776 |
| 1779 for (; index < end_frame; ++index) | 1777 for (; index < end_frame; ++index) |
| 1780 values[index] = default_value; | 1778 values[index] = default_value; |
| 1781 | 1779 |
| 1782 return index; | 1780 return index; |
| 1783 } | 1781 } |
| 1784 | 1782 |
| 1785 } // namespace blink | 1783 } // namespace blink |
| OLD | NEW |