~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/ca/mac/PlatformCAAnimationMac.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
 
 
28
#if USE(ACCELERATED_COMPOSITING)
 
29
 
 
30
#import "PlatformCAAnimation.h"
 
31
 
 
32
#import "FloatConversion.h"
 
33
#import "LengthFunctions.h"
 
34
#import "TimingFunction.h"
 
35
#import <QuartzCore/QuartzCore.h>
 
36
#import <wtf/UnusedParam.h>
 
37
#import <wtf/text/WTFString.h>
 
38
 
 
39
using namespace WebCore;
 
40
 
 
41
// This value must be the same as in PlatformCALayerMac.mm
 
42
static NSString * const WKNonZeroBeginTimeFlag = @"WKPlatformCAAnimationNonZeroBeginTimeFlag";
 
43
 
 
44
static bool hasNonZeroBeginTimeFlag(const PlatformCAAnimation* animation)
 
45
{
 
46
    return [[animation->platformAnimation() valueForKey:WKNonZeroBeginTimeFlag] boolValue];
 
47
}
 
48
 
 
49
static void setNonZeroBeginTimeFlag(PlatformCAAnimation* animation, bool value)
 
50
{
 
51
    [animation->platformAnimation() setValue:[NSNumber numberWithBool:value] forKey:WKNonZeroBeginTimeFlag];
 
52
}
 
53
    
 
54
static NSString* toCAFillModeType(PlatformCAAnimation::FillModeType type)
 
55
{
 
56
    switch (type) {
 
57
    case PlatformCAAnimation::NoFillMode:
 
58
    case PlatformCAAnimation::Forwards: return kCAFillModeForwards;
 
59
    case PlatformCAAnimation::Backwards: return kCAFillModeBackwards;
 
60
    case PlatformCAAnimation::Both: return kCAFillModeBoth;
 
61
    }
 
62
    return @"";
 
63
}
 
64
 
 
65
static PlatformCAAnimation::FillModeType fromCAFillModeType(NSString* string)
 
66
{
 
67
    if ([string isEqualToString:kCAFillModeBackwards])
 
68
        return PlatformCAAnimation::Backwards;
 
69
 
 
70
    if ([string isEqualToString:kCAFillModeBoth])
 
71
        return PlatformCAAnimation::Both;
 
72
 
 
73
    return PlatformCAAnimation::Forwards;
 
74
}
 
75
 
 
76
static NSString* toCAValueFunctionType(PlatformCAAnimation::ValueFunctionType type)
 
77
{
 
78
    switch (type) {
 
79
    case PlatformCAAnimation::NoValueFunction: return @"";
 
80
    case PlatformCAAnimation::RotateX: return kCAValueFunctionRotateX;
 
81
    case PlatformCAAnimation::RotateY: return kCAValueFunctionRotateY;
 
82
    case PlatformCAAnimation::RotateZ: return kCAValueFunctionRotateZ;
 
83
    case PlatformCAAnimation::ScaleX: return kCAValueFunctionScaleX;
 
84
    case PlatformCAAnimation::ScaleY: return kCAValueFunctionScaleY;
 
85
    case PlatformCAAnimation::ScaleZ: return kCAValueFunctionScaleZ;
 
86
    case PlatformCAAnimation::Scale: return kCAValueFunctionScale;
 
87
    case PlatformCAAnimation::TranslateX: return kCAValueFunctionTranslateX;
 
88
    case PlatformCAAnimation::TranslateY: return kCAValueFunctionTranslateY;
 
89
    case PlatformCAAnimation::TranslateZ: return kCAValueFunctionTranslateZ;
 
90
    case PlatformCAAnimation::Translate: return kCAValueFunctionTranslate;
 
91
    }
 
92
    return @"";
 
93
}
 
94
 
 
95
static PlatformCAAnimation::ValueFunctionType fromCAValueFunctionType(NSString* string)
 
96
{
 
97
    if ([string isEqualToString:kCAValueFunctionRotateX])
 
98
        return PlatformCAAnimation::RotateX;
 
99
 
 
100
    if ([string isEqualToString:kCAValueFunctionRotateY])
 
101
        return PlatformCAAnimation::RotateY;
 
102
 
 
103
    if ([string isEqualToString:kCAValueFunctionRotateZ])
 
104
        return PlatformCAAnimation::RotateZ;
 
105
 
 
106
    if ([string isEqualToString:kCAValueFunctionScaleX])
 
107
        return PlatformCAAnimation::ScaleX;
 
108
 
 
109
    if ([string isEqualToString:kCAValueFunctionScaleY])
 
110
        return PlatformCAAnimation::ScaleY;
 
111
 
 
112
    if ([string isEqualToString:kCAValueFunctionScaleZ])
 
113
        return PlatformCAAnimation::ScaleZ;
 
114
 
 
115
    if ([string isEqualToString:kCAValueFunctionScale])
 
116
        return PlatformCAAnimation::Scale;
 
117
 
 
118
    if ([string isEqualToString:kCAValueFunctionTranslateX])
 
119
        return PlatformCAAnimation::TranslateX;
 
120
 
 
121
    if ([string isEqualToString:kCAValueFunctionTranslateY])
 
122
        return PlatformCAAnimation::TranslateY;
 
123
 
 
124
    if ([string isEqualToString:kCAValueFunctionTranslateZ])
 
125
        return PlatformCAAnimation::TranslateZ;
 
126
 
 
127
    if ([string isEqualToString:kCAValueFunctionTranslate])
 
128
        return PlatformCAAnimation::Translate;
 
129
 
 
130
    return PlatformCAAnimation::NoValueFunction;
 
131
}
 
132
 
 
133
static CAMediaTimingFunction* toCAMediaTimingFunction(const TimingFunction* timingFunction, bool reverse)
 
134
{
 
135
    ASSERT(timingFunction);
 
136
    if (timingFunction->isCubicBezierTimingFunction()) {
 
137
        const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimingFunction*>(timingFunction);
 
138
        float x1 = static_cast<float>(ctf->x1());
 
139
        float y1 = static_cast<float>(ctf->y1());
 
140
        float x2 = static_cast<float>(ctf->x2());
 
141
        float y2 = static_cast<float>(ctf->y2());
 
142
        return [CAMediaTimingFunction functionWithControlPoints:(reverse ? 1 - x2 : x1)
 
143
                                                               :(reverse ? 1 - y2 : y1)
 
144
                                                               :(reverse ? 1 - x1 : x2)
 
145
                                                               :(reverse ? 1 - y1 : y2)];
 
146
    }
 
147
    
 
148
    return [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
 
149
}
 
150
 
 
151
PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::create(AnimationType type, const String& keyPath)
 
152
{
 
153
    return adoptRef(new PlatformCAAnimation(type, keyPath));
 
154
}
 
155
 
 
156
PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::create(PlatformAnimationRef animation)
 
157
{
 
158
    return adoptRef(new PlatformCAAnimation(animation));
 
159
}
 
160
 
 
161
PlatformCAAnimation::PlatformCAAnimation(AnimationType type, const String& keyPath)
 
162
    : m_type(type)
 
163
{
 
164
    if (type == Basic)
 
165
        m_animation.adoptNS([[CABasicAnimation animationWithKeyPath:keyPath] retain]);
 
166
    else
 
167
        m_animation.adoptNS([[CAKeyframeAnimation animationWithKeyPath:keyPath] retain]);
 
168
}
 
169
 
 
170
PlatformCAAnimation::PlatformCAAnimation(PlatformAnimationRef animation)
 
171
{
 
172
    if ([static_cast<CAAnimation*>(animation) isKindOfClass:[CABasicAnimation class]])
 
173
        m_type = Basic;
 
174
    else if ([static_cast<CAAnimation*>(animation) isKindOfClass:[CAKeyframeAnimation class]])
 
175
        m_type = Keyframe;
 
176
    else {
 
177
        ASSERT(0);
 
178
        return;
 
179
    }
 
180
    
 
181
    m_animation = static_cast<CAPropertyAnimation*>(animation);
 
182
}
 
183
 
 
184
PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::copy() const
 
185
{
 
186
    RefPtr<PlatformCAAnimation> animation = create(animationType(), keyPath());
 
187
    
 
188
    animation->setBeginTime(beginTime());
 
189
    animation->setDuration(duration());
 
190
    animation->setSpeed(speed());
 
191
    animation->setTimeOffset(timeOffset());
 
192
    animation->setRepeatCount(repeatCount());
 
193
    animation->setAutoreverses(autoreverses());
 
194
    animation->setFillMode(fillMode());
 
195
    animation->setRemovedOnCompletion(isRemovedOnCompletion());
 
196
    animation->setAdditive(isAdditive());
 
197
    animation->copyTimingFunctionFrom(this);
 
198
    animation->setValueFunction(valueFunction());
 
199
 
 
200
    setNonZeroBeginTimeFlag(animation.get(), hasNonZeroBeginTimeFlag(this));
 
201
    
 
202
    // Copy the specific Basic or Keyframe values
 
203
    if (animationType() == Keyframe) {
 
204
        animation->copyValuesFrom(this);
 
205
        animation->copyKeyTimesFrom(this);
 
206
        animation->copyTimingFunctionsFrom(this);
 
207
    } else {
 
208
        animation->copyFromValueFrom(this);
 
209
        animation->copyToValueFrom(this);
 
210
    }
 
211
    
 
212
    return animation;
 
213
}
 
214
PlatformCAAnimation::~PlatformCAAnimation()
 
215
{
 
216
}
 
217
 
 
218
bool PlatformCAAnimation::supportsValueFunction()
 
219
{
 
220
    static bool sHaveValueFunction = [CAPropertyAnimation instancesRespondToSelector:@selector(setValueFunction:)];
 
221
    return sHaveValueFunction;
 
222
}
 
223
 
 
224
PlatformAnimationRef PlatformCAAnimation::platformAnimation() const
 
225
{
 
226
    return m_animation.get();
 
227
}
 
228
 
 
229
String PlatformCAAnimation::keyPath() const
 
230
{
 
231
    return [m_animation.get() keyPath];
 
232
}
 
233
 
 
234
CFTimeInterval PlatformCAAnimation::beginTime() const
 
235
{
 
236
    return [m_animation.get() beginTime];
 
237
}
 
238
 
 
239
void PlatformCAAnimation::setBeginTime(CFTimeInterval value)
 
240
{
 
241
    [m_animation.get() setBeginTime:value];
 
242
    
 
243
    // Also set a flag to tell us if we've passed in a 0 value. 
 
244
    // The flag is needed because later beginTime will get changed
 
245
    // to the time at which it fired and we need to know whether
 
246
    // or not it was 0 to begin with.
 
247
    if (value)
 
248
        setNonZeroBeginTimeFlag(this, true);
 
249
}
 
250
 
 
251
CFTimeInterval PlatformCAAnimation::duration() const
 
252
{
 
253
    return [m_animation.get() duration];
 
254
}
 
255
 
 
256
void PlatformCAAnimation::setDuration(CFTimeInterval value)
 
257
{
 
258
    [m_animation.get() setDuration:value];
 
259
}
 
260
 
 
261
float PlatformCAAnimation::speed() const
 
262
{
 
263
    return [m_animation.get() speed];
 
264
}
 
265
 
 
266
void PlatformCAAnimation::setSpeed(float value)
 
267
{
 
268
    [m_animation.get() setSpeed:value];
 
269
}
 
270
 
 
271
CFTimeInterval PlatformCAAnimation::timeOffset() const
 
272
{
 
273
    return [m_animation.get() timeOffset];
 
274
}
 
275
 
 
276
void PlatformCAAnimation::setTimeOffset(CFTimeInterval value)
 
277
{
 
278
    [m_animation.get() setTimeOffset:value];
 
279
}
 
280
 
 
281
float PlatformCAAnimation::repeatCount() const
 
282
{
 
283
    return [m_animation.get() repeatCount];
 
284
}
 
285
 
 
286
void PlatformCAAnimation::setRepeatCount(float value)
 
287
{
 
288
    [m_animation.get() setRepeatCount:value];
 
289
}
 
290
 
 
291
bool PlatformCAAnimation::autoreverses() const
 
292
{
 
293
    return [m_animation.get() autoreverses];
 
294
}
 
295
 
 
296
void PlatformCAAnimation::setAutoreverses(bool value)
 
297
{
 
298
    [m_animation.get() setAutoreverses:value];
 
299
}
 
300
 
 
301
PlatformCAAnimation::FillModeType PlatformCAAnimation::fillMode() const
 
302
{
 
303
    return fromCAFillModeType([m_animation.get() fillMode]);
 
304
}
 
305
 
 
306
void PlatformCAAnimation::setFillMode(FillModeType value)
 
307
{
 
308
    [m_animation.get() setFillMode:toCAFillModeType(value)];
 
309
}
 
310
 
 
311
void PlatformCAAnimation::setTimingFunction(const TimingFunction* value, bool reverse)
 
312
{
 
313
    [m_animation.get() setTimingFunction:toCAMediaTimingFunction(value, reverse)];
 
314
}
 
315
 
 
316
void PlatformCAAnimation::copyTimingFunctionFrom(const PlatformCAAnimation* value)
 
317
{
 
318
    [m_animation.get() setTimingFunction:[value->m_animation.get() timingFunction]];
 
319
}
 
320
 
 
321
bool PlatformCAAnimation::isRemovedOnCompletion() const
 
322
{
 
323
    return [m_animation.get() isRemovedOnCompletion];
 
324
}
 
325
 
 
326
void PlatformCAAnimation::setRemovedOnCompletion(bool value)
 
327
{
 
328
    [m_animation.get() setRemovedOnCompletion:value];
 
329
}
 
330
 
 
331
bool PlatformCAAnimation::isAdditive() const
 
332
{
 
333
    return [m_animation.get() isAdditive];
 
334
}
 
335
 
 
336
void PlatformCAAnimation::setAdditive(bool value)
 
337
{
 
338
    [m_animation.get() setAdditive:value];
 
339
}
 
340
 
 
341
PlatformCAAnimation::ValueFunctionType PlatformCAAnimation::valueFunction() const
 
342
{
 
343
    CAValueFunction* vf = [m_animation.get() valueFunction];
 
344
    return fromCAValueFunctionType([vf name]);
 
345
}
 
346
 
 
347
void PlatformCAAnimation::setValueFunction(ValueFunctionType value)
 
348
{
 
349
    [m_animation.get() setValueFunction:[CAValueFunction functionWithName:toCAValueFunctionType(value)]];
 
350
}
 
351
 
 
352
void PlatformCAAnimation::setFromValue(float value)
 
353
{
 
354
    if (animationType() != Basic)
 
355
        return;
 
356
    [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:[NSNumber numberWithDouble:value]];
 
357
}
 
358
 
 
359
void PlatformCAAnimation::setFromValue(const WebCore::TransformationMatrix& value)
 
360
{
 
361
    if (animationType() != Basic)
 
362
        return;
 
363
        
 
364
    [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:[NSValue valueWithCATransform3D:value]];
 
365
}
 
366
 
 
367
void PlatformCAAnimation::setFromValue(const FloatPoint3D& value)
 
368
{
 
369
    if (animationType() != Basic)
 
370
        return;
 
371
 
 
372
    NSArray* array = [NSArray arrayWithObjects:
 
373
                        [NSNumber numberWithDouble:value.x()],
 
374
                        [NSNumber numberWithDouble:value.y()],
 
375
                        [NSNumber numberWithDouble:value.z()],
 
376
                        nil];
 
377
    [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:array];
 
378
}
 
379
 
 
380
void PlatformCAAnimation::setFromValue(const WebCore::Color& value)
 
381
{
 
382
    if (animationType() != Basic)
 
383
        return;
 
384
 
 
385
    NSArray* array = [NSArray arrayWithObjects:
 
386
                        [NSNumber numberWithDouble:value.red()],
 
387
                        [NSNumber numberWithDouble:value.green()],
 
388
                        [NSNumber numberWithDouble:value.blue()],
 
389
                        [NSNumber numberWithDouble:value.alpha()],
 
390
                        nil];
 
391
    [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:array];
 
392
}
 
393
 
 
394
#if ENABLE(CSS_FILTERS)
 
395
static double sepiaFullConstants[3][3] = {
 
396
    { 0.393, 0.769, 0.189 },
 
397
    { 0.349, 0.686, 0.168 },
 
398
    { 0.272, 0.534, 0.131 }
 
399
};
 
400
 
 
401
static double sepiaNoneConstants[3][3] = {
 
402
    { 1, 0, 0 },
 
403
    { 0, 1, 0 },
 
404
    { 0, 0, 1 }
 
405
};
 
406
 
 
407
static double invertConstants[3][3] = {
 
408
    { 1, 0, 0 },
 
409
    { 0, 1, 0 },
 
410
    { 0, 0, 1 }
 
411
};
 
412
 
 
413
static RetainPtr<id> filterValueForOperation(const FilterOperation* operation, int internalFilterPropertyIndex)
 
414
{
 
415
    FilterOperation::OperationType type = operation->getOperationType();
 
416
    RetainPtr<id> value;
 
417
    
 
418
    switch(type) {
 
419
    case FilterOperation::GRAYSCALE:
 
420
    case FilterOperation::SATURATE:
 
421
    case FilterOperation::HUE_ROTATE: {
 
422
        double amount = 0;
 
423
        
 
424
        if (!operation->isDefault()) {
 
425
            const BasicColorMatrixFilterOperation* op = static_cast<const BasicColorMatrixFilterOperation*>(operation);
 
426
            amount = op->amount();
 
427
        }
 
428
        
 
429
        if (type == FilterOperation::HUE_ROTATE)
 
430
            amount = deg2rad(amount);
 
431
 
 
432
        value.adoptNS([[NSNumber numberWithDouble:amount] retain]);
 
433
        break;
 
434
    }
 
435
    case FilterOperation::SEPIA: {
 
436
        double amount = 0;
 
437
 
 
438
        if (!operation->isDefault()) {
 
439
            const BasicColorMatrixFilterOperation* op = static_cast<const BasicColorMatrixFilterOperation*>(operation);
 
440
            amount = op->amount();
 
441
        }
 
442
        
 
443
        value.adoptNS([[NSArray arrayWithObjects:
 
444
            [NSNumber numberWithDouble:WebCore::blend(sepiaNoneConstants[internalFilterPropertyIndex][0], sepiaFullConstants[0][internalFilterPropertyIndex], amount)],
 
445
            [NSNumber numberWithDouble:WebCore::blend(sepiaNoneConstants[internalFilterPropertyIndex][1], sepiaFullConstants[1][internalFilterPropertyIndex], amount)],
 
446
            [NSNumber numberWithDouble:WebCore::blend(sepiaNoneConstants[internalFilterPropertyIndex][2], sepiaFullConstants[2][internalFilterPropertyIndex], amount)],
 
447
            [NSNumber numberWithDouble:0],
 
448
            nil] retain]);
 
449
        break;
 
450
    }
 
451
    case FilterOperation::INVERT: {
 
452
        double amount = 0;
 
453
 
 
454
        if (!operation->isDefault()) {
 
455
            const BasicComponentTransferFilterOperation* op = static_cast<const BasicComponentTransferFilterOperation*>(operation);
 
456
            amount = op->amount();
 
457
        }
 
458
        
 
459
        // The color matrix animation for invert does a scale of each color component by a value that goes from 
 
460
        // 1 (when amount is 0) to -1 (when amount is 1). Then the color values are offset by amount. This has the
 
461
        // effect of performing the operation: c' = c * -1 + 1, which inverts the color.
 
462
        if (internalFilterPropertyIndex < 3) {
 
463
            // the first 3 properties are the red, green and blue multipliers
 
464
            double multiplier = 1 - amount * 2;
 
465
            value.adoptNS([[NSArray arrayWithObjects:
 
466
                [NSNumber numberWithDouble:invertConstants[internalFilterPropertyIndex][0] * multiplier],
 
467
                [NSNumber numberWithDouble:invertConstants[internalFilterPropertyIndex][1] * multiplier],
 
468
                [NSNumber numberWithDouble:invertConstants[internalFilterPropertyIndex][2] * multiplier],
 
469
                [NSNumber numberWithDouble:0],
 
470
                nil] retain]);
 
471
        } else {
 
472
            // the last property is the color offset
 
473
            value.adoptNS([[NSArray arrayWithObjects:
 
474
                [NSNumber numberWithDouble:amount],
 
475
                [NSNumber numberWithDouble:amount],
 
476
                [NSNumber numberWithDouble:amount],
 
477
                [NSNumber numberWithDouble:0],
 
478
                nil] retain]);
 
479
        }
 
480
        break;
 
481
    }
 
482
    case FilterOperation::OPACITY:
 
483
    case FilterOperation::CONTRAST:
 
484
    case FilterOperation::BRIGHTNESS: {
 
485
        double amount = 0;
 
486
 
 
487
        if (!operation->isDefault()) {
 
488
            const BasicComponentTransferFilterOperation* op = static_cast<const BasicComponentTransferFilterOperation*>(operation);
 
489
            amount = op->amount();
 
490
        }
 
491
        
 
492
        value.adoptNS([[NSNumber numberWithDouble:amount] retain]);
 
493
        break;
 
494
    }
 
495
    case FilterOperation::BLUR: {
 
496
        double amount = 0;
 
497
 
 
498
        if (!operation->isDefault()) {
 
499
            const BlurFilterOperation* op = static_cast<const BlurFilterOperation*>(operation);
 
500
            amount = floatValueForLength(op->stdDeviation(), 0);
 
501
        }
 
502
        
 
503
        value.adoptNS([[NSNumber numberWithDouble:amount] retain]);
 
504
        break;
 
505
    }
 
506
    default: break;
 
507
    }
 
508
    
 
509
    return value;
 
510
}
 
511
 
 
512
void PlatformCAAnimation::setFromValue(const FilterOperation* operation, int internalFilterPropertyIndex)
 
513
{
 
514
    RetainPtr<id> value = filterValueForOperation(operation, internalFilterPropertyIndex);
 
515
    [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:value.get()];
 
516
}
 
517
#endif
 
518
 
 
519
void PlatformCAAnimation::copyFromValueFrom(const PlatformCAAnimation* value)
 
520
{
 
521
    if (animationType() != Basic || value->animationType() != Basic)
 
522
        return;
 
523
        
 
524
    CABasicAnimation* otherAnimation = static_cast<CABasicAnimation*>(value->m_animation.get());
 
525
    [static_cast<CABasicAnimation*>(m_animation.get()) setFromValue:[otherAnimation fromValue]];
 
526
}
 
527
 
 
528
void PlatformCAAnimation::setToValue(float value)
 
529
{
 
530
    if (animationType() != Basic)
 
531
        return;
 
532
    [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:[NSNumber numberWithDouble:value]];
 
533
}
 
534
 
 
535
void PlatformCAAnimation::setToValue(const WebCore::TransformationMatrix& value)
 
536
{
 
537
    if (animationType() != Basic)
 
538
        return;
 
539
 
 
540
    [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:[NSValue valueWithCATransform3D:value]];
 
541
}
 
542
 
 
543
void PlatformCAAnimation::setToValue(const FloatPoint3D& value)
 
544
{
 
545
    if (animationType() != Basic)
 
546
        return;
 
547
 
 
548
    NSArray* array = [NSArray arrayWithObjects:
 
549
                        [NSNumber numberWithDouble:value.x()],
 
550
                        [NSNumber numberWithDouble:value.y()],
 
551
                        [NSNumber numberWithDouble:value.z()],
 
552
                        nil];
 
553
    [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:array];
 
554
}
 
555
 
 
556
void PlatformCAAnimation::setToValue(const WebCore::Color& value)
 
557
{
 
558
    if (animationType() != Basic)
 
559
        return;
 
560
 
 
561
    NSArray* array = [NSArray arrayWithObjects:
 
562
                        [NSNumber numberWithDouble:value.red()],
 
563
                        [NSNumber numberWithDouble:value.green()],
 
564
                        [NSNumber numberWithDouble:value.blue()],
 
565
                        [NSNumber numberWithDouble:value.alpha()],
 
566
                        nil];
 
567
    [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:array];
 
568
}
 
569
 
 
570
#if ENABLE(CSS_FILTERS)
 
571
void PlatformCAAnimation::setToValue(const FilterOperation* operation, int internalFilterPropertyIndex)
 
572
{
 
573
    RetainPtr<id> value = filterValueForOperation(operation, internalFilterPropertyIndex);
 
574
    [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:value.get()];
 
575
}
 
576
#endif
 
577
 
 
578
void PlatformCAAnimation::copyToValueFrom(const PlatformCAAnimation* value)
 
579
{
 
580
    if (animationType() != Basic || value->animationType() != Basic)
 
581
        return;
 
582
        
 
583
    CABasicAnimation* otherAnimation = static_cast<CABasicAnimation*>(value->m_animation.get());
 
584
    [static_cast<CABasicAnimation*>(m_animation.get()) setToValue:[otherAnimation toValue]];
 
585
}
 
586
 
 
587
 
 
588
// Keyframe-animation properties.
 
589
void PlatformCAAnimation::setValues(const Vector<float>& value)
 
590
{
 
591
    if (animationType() != Keyframe)
 
592
        return;
 
593
        
 
594
    NSMutableArray* array = [NSMutableArray array];
 
595
    for (size_t i = 0; i < value.size(); ++i)
 
596
        [array addObject:[NSNumber numberWithDouble:value[i]]];
 
597
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:array];
 
598
}
 
599
 
 
600
void PlatformCAAnimation::setValues(const Vector<WebCore::TransformationMatrix>& value)
 
601
{
 
602
    if (animationType() != Keyframe)
 
603
        return;
 
604
        
 
605
    NSMutableArray* array = [NSMutableArray array];
 
606
 
 
607
    for (size_t i = 0; i < value.size(); ++i)
 
608
        [array addObject:[NSValue valueWithCATransform3D:value[i]]];
 
609
        
 
610
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:array];
 
611
}
 
612
 
 
613
void PlatformCAAnimation::setValues(const Vector<FloatPoint3D>& value)
 
614
{
 
615
    if (animationType() != Keyframe)
 
616
        return;
 
617
        
 
618
    NSMutableArray* array = [NSMutableArray array];
 
619
 
 
620
    for (size_t i = 0; i < value.size(); ++i) {
 
621
        NSArray* object = [NSArray arrayWithObjects:
 
622
                        [NSNumber numberWithDouble:value[i].x()],
 
623
                        [NSNumber numberWithDouble:value[i].y()],
 
624
                        [NSNumber numberWithDouble:value[i].z()],
 
625
                        nil];
 
626
        [array addObject:object];
 
627
    }
 
628
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:array];
 
629
}
 
630
 
 
631
void PlatformCAAnimation::setValues(const Vector<WebCore::Color>& value)
 
632
{
 
633
    if (animationType() != Keyframe)
 
634
        return;
 
635
        
 
636
    NSMutableArray* array = [NSMutableArray array];
 
637
 
 
638
    for (size_t i = 0; i < value.size(); ++i) {
 
639
        NSArray* object = [NSArray arrayWithObjects:
 
640
                        [NSNumber numberWithDouble:value[i].red()],
 
641
                        [NSNumber numberWithDouble:value[i].green()],
 
642
                        [NSNumber numberWithDouble:value[i].blue()],
 
643
                        [NSNumber numberWithDouble:value[i].alpha()],
 
644
                        nil];
 
645
        [array addObject:object];
 
646
    }
 
647
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:array];
 
648
}
 
649
 
 
650
#if ENABLE(CSS_FILTERS)
 
651
void PlatformCAAnimation::setValues(const Vector<RefPtr<FilterOperation> >& values, int internalFilterPropertyIndex)
 
652
{
 
653
    if (animationType() != Keyframe)
 
654
        return;
 
655
        
 
656
    NSMutableArray* array = [NSMutableArray array];
 
657
 
 
658
    for (size_t i = 0; i < values.size(); ++i) {
 
659
        RetainPtr<id> value = filterValueForOperation(values[i].get(), internalFilterPropertyIndex);
 
660
        [array addObject:value.get()];
 
661
    }
 
662
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:array];
 
663
}
 
664
#endif
 
665
 
 
666
void PlatformCAAnimation::copyValuesFrom(const PlatformCAAnimation* value)
 
667
{
 
668
    if (animationType() != Keyframe || value->animationType() != Keyframe)
 
669
        return;
 
670
        
 
671
    CAKeyframeAnimation* otherAnimation = static_cast<CAKeyframeAnimation*>(value->m_animation.get());
 
672
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setValues:[otherAnimation values]];
 
673
}
 
674
 
 
675
void PlatformCAAnimation::setKeyTimes(const Vector<float>& value)
 
676
{
 
677
    NSMutableArray* array = [NSMutableArray array];
 
678
 
 
679
    for (size_t i = 0; i < value.size(); ++i)
 
680
        [array addObject:[NSNumber numberWithFloat:value[i]]];
 
681
    
 
682
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setKeyTimes:array];
 
683
}
 
684
 
 
685
void PlatformCAAnimation::copyKeyTimesFrom(const PlatformCAAnimation* value)
 
686
{
 
687
    CAKeyframeAnimation* other = static_cast<CAKeyframeAnimation*>(value->m_animation.get());
 
688
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setKeyTimes:[other keyTimes]];
 
689
}
 
690
 
 
691
void PlatformCAAnimation::setTimingFunctions(const Vector<const TimingFunction*>& value, bool reverse)
 
692
{
 
693
    NSMutableArray* array = [NSMutableArray array];
 
694
 
 
695
    for (size_t i = 0; i < value.size(); ++i)
 
696
        [array addObject:toCAMediaTimingFunction(value[i], reverse)];
 
697
    
 
698
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setTimingFunctions:array];
 
699
}
 
700
 
 
701
void PlatformCAAnimation::copyTimingFunctionsFrom(const PlatformCAAnimation* value)
 
702
{
 
703
    CAKeyframeAnimation* other = static_cast<CAKeyframeAnimation*>(value->m_animation.get());
 
704
    [static_cast<CAKeyframeAnimation*>(m_animation.get()) setTimingFunctions:[other timingFunctions]];
 
705
}
 
706
 
 
707
#if ENABLE(CSS_FILTERS)
 
708
int PlatformCAAnimation::numAnimatedFilterProperties(FilterOperation::OperationType type)
 
709
{
 
710
    switch(type) {
 
711
    case FilterOperation::GRAYSCALE: return 1;
 
712
    case FilterOperation::SEPIA: return 3;
 
713
    case FilterOperation::SATURATE: return 1;
 
714
    case FilterOperation::HUE_ROTATE: return 1;
 
715
    case FilterOperation::INVERT: return 4;
 
716
    case FilterOperation::OPACITY: return 1;
 
717
    case FilterOperation::BLUR: return 1;
 
718
    case FilterOperation::CONTRAST: return 1;
 
719
    case FilterOperation::BRIGHTNESS: return 1;
 
720
    default: return 0;
 
721
    }
 
722
}
 
723
 
 
724
const char* PlatformCAAnimation::animatedFilterPropertyName(FilterOperation::OperationType type, int internalFilterPropertyIndex)
 
725
{
 
726
    switch(type) {
 
727
    case FilterOperation::GRAYSCALE: return "inputIntensity";
 
728
    case FilterOperation::SEPIA:
 
729
        switch(internalFilterPropertyIndex) {
 
730
        case 0: return "inputRVector";
 
731
        case 1: return "inputGVector";
 
732
        case 2: return "inputBVector";
 
733
        default: return "";
 
734
        }
 
735
    case FilterOperation::SATURATE: return "inputSaturation";
 
736
    case FilterOperation::HUE_ROTATE: return "inputAngle";
 
737
    case FilterOperation::INVERT:
 
738
        switch(internalFilterPropertyIndex) {
 
739
        case 0: return "inputRVector";
 
740
        case 1: return "inputGVector";
 
741
        case 2: return "inputBVector";
 
742
        case 3: return "inputBiasVector";
 
743
        default: return "";
 
744
        }
 
745
    case FilterOperation::OPACITY: return "inputAVector";
 
746
    case FilterOperation::BLUR: return "inputRadius";
 
747
    case FilterOperation::CONTRAST: return "inputContrast";
 
748
    case FilterOperation::BRIGHTNESS: return "inputBrightness";
 
749
    default: return "";
 
750
    }
 
751
}
 
752
#endif
 
753
 
 
754
#endif // USE(ACCELERATED_COMPOSITING)