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

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp

  • 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) 2011 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
#include "PlatformCALayer.h"
 
31
 
 
32
#include "AbstractCACFLayerTreeHost.h"
 
33
#include "Font.h"
 
34
#include "GraphicsContext.h"
 
35
#include "PlatformCALayerWinInternal.h"
 
36
#include <QuartzCore/CoreAnimationCF.h>
 
37
#include <WebKitSystemInterface/WebKitSystemInterface.h>
 
38
#include <wtf/CurrentTime.h>
 
39
#include <wtf/text/CString.h>
 
40
 
 
41
using namespace WebCore;
 
42
 
 
43
bool PlatformCALayer::isValueFunctionSupported()
 
44
{
 
45
    return true;
 
46
}
 
47
 
 
48
void PlatformCALayer::setOwner(PlatformCALayerClient* owner)
 
49
{
 
50
    m_owner = owner;
 
51
}
 
52
 
 
53
static CFStringRef toCACFLayerType(PlatformCALayer::LayerType type)
 
54
{
 
55
    return (type == PlatformCALayer::LayerTypeTransformLayer) ? kCACFTransformLayer : kCACFLayer;
 
56
}
 
57
 
 
58
static CFStringRef toCACFFilterType(PlatformCALayer::FilterType type)
 
59
{
 
60
    switch (type) {
 
61
    case PlatformCALayer::Linear: return kCACFFilterLinear;
 
62
    case PlatformCALayer::Nearest: return kCACFFilterNearest;
 
63
    case PlatformCALayer::Trilinear: return kCACFFilterTrilinear;
 
64
    default: return 0;
 
65
    }
 
66
}
 
67
 
 
68
static AbstractCACFLayerTreeHost* layerTreeHostForLayer(const PlatformCALayer* layer)
 
69
{
 
70
    // We need the AbstractCACFLayerTreeHost associated with this layer, which is stored in the UserData of the CACFContext
 
71
    void* userData = wkCACFLayerGetContextUserData(layer->platformLayer());
 
72
    if (!userData)
 
73
        return 0;
 
74
 
 
75
    return static_cast<AbstractCACFLayerTreeHost*>(userData);
 
76
}
 
77
 
 
78
static PlatformCALayerWinInternal* intern(const PlatformCALayer* layer)
 
79
{
 
80
    return static_cast<PlatformCALayerWinInternal*>(CACFLayerGetUserData(layer->platformLayer()));
 
81
}
 
82
 
 
83
static PlatformCALayerWinInternal* intern(void* layer)
 
84
{
 
85
    return static_cast<PlatformCALayerWinInternal*>(CACFLayerGetUserData(static_cast<CACFLayerRef>(layer)));
 
86
}
 
87
 
 
88
PassRefPtr<PlatformCALayer> PlatformCALayer::create(LayerType layerType, PlatformCALayerClient* owner)
 
89
{
 
90
    return adoptRef(new PlatformCALayer(layerType, 0, owner));
 
91
}
 
92
 
 
93
PassRefPtr<PlatformCALayer> PlatformCALayer::create(void* platformLayer, PlatformCALayerClient* owner)
 
94
{
 
95
    return adoptRef(new PlatformCALayer(LayerTypeCustom, static_cast<PlatformLayer*>(platformLayer), owner));
 
96
}
 
97
 
 
98
static void displayCallback(CACFLayerRef caLayer, CGContextRef context)
 
99
{
 
100
    ASSERT_ARG(caLayer, CACFLayerGetUserData(caLayer));
 
101
    intern(caLayer)->displayCallback(caLayer, context);
 
102
}
 
103
 
 
104
static void layoutSublayersProc(CACFLayerRef caLayer) 
 
105
{
 
106
    PlatformCALayer* layer = PlatformCALayer::platformCALayer(caLayer);
 
107
    if (layer && layer->owner())
 
108
        layer->owner()->platformCALayerLayoutSublayersOfLayer(layer);
 
109
}
 
110
 
 
111
PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformLayer* layer, PlatformCALayerClient* owner)
 
112
    : m_owner(owner)
 
113
{
 
114
    if (layer) {
 
115
        m_layerType = LayerTypeCustom;
 
116
        m_layer = layer;
 
117
    } else {
 
118
        m_layerType = layerType;
 
119
        m_layer.adoptCF(CACFLayerCreate(toCACFLayerType(layerType)));
 
120
 
 
121
        // Create the PlatformCALayerWinInternal object and point to it in the userdata.
 
122
        PlatformCALayerWinInternal* intern = new PlatformCALayerWinInternal(this);
 
123
        CACFLayerSetUserData(m_layer.get(), intern);
 
124
 
 
125
        // Set the display callback
 
126
        CACFLayerSetDisplayCallback(m_layer.get(), displayCallback);
 
127
        CACFLayerSetLayoutCallback(m_layer.get(), layoutSublayersProc);    
 
128
    }
 
129
}
 
130
 
 
131
PlatformCALayer::~PlatformCALayer()
 
132
{
 
133
    // Toss all the kids
 
134
    removeAllSublayers();
 
135
 
 
136
    // Get rid of the user data
 
137
    PlatformCALayerWinInternal* layerIntern = intern(this);
 
138
    CACFLayerSetUserData(m_layer.get(), 0);
 
139
 
 
140
    delete layerIntern;
 
141
}
 
142
 
 
143
PlatformCALayer* PlatformCALayer::platformCALayer(void* platformLayer)
 
144
{
 
145
    if (!platformLayer)
 
146
        return 0;
 
147
    
 
148
    PlatformCALayerWinInternal* layerIntern = intern(platformLayer);
 
149
    return layerIntern ? layerIntern->owner() : 0;
 
150
}
 
151
 
 
152
PlatformLayer* PlatformCALayer::platformLayer() const
 
153
{
 
154
    return m_layer.get();
 
155
}
 
156
 
 
157
PlatformCALayer* PlatformCALayer::rootLayer() const
 
158
{
 
159
    AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
 
160
    return host ? host->rootLayer() : 0;
 
161
}
 
162
 
 
163
void PlatformCALayer::animationStarted(CFTimeInterval beginTime)
 
164
{
 
165
    // Update start time for any animation not yet started
 
166
    CFTimeInterval cacfBeginTime = currentTimeToMediaTime(beginTime);
 
167
 
 
168
    HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator end = m_animations.end();
 
169
    for (HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator it = m_animations.begin(); it != end; ++it)
 
170
        it->value->setActualStartTimeIfNeeded(cacfBeginTime);
 
171
 
 
172
    if (m_owner)
 
173
        m_owner->platformCALayerAnimationStarted(beginTime);
 
174
}
 
175
 
 
176
static void resubmitAllAnimations(PlatformCALayer* layer)
 
177
{
 
178
    HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator end = layer->animations().end();
 
179
    for (HashMap<String, RefPtr<PlatformCAAnimation> >::const_iterator it = layer->animations().begin(); it != end; ++it)
 
180
        CACFLayerAddAnimation(layer->platformLayer(), it->key.createCFString().get(), it->value->platformAnimation());
 
181
}
 
182
 
 
183
void PlatformCALayer::ensureAnimationsSubmitted()
 
184
{
 
185
    resubmitAllAnimations(this);
 
186
 
 
187
    PlatformCALayerList children;
 
188
    intern(this)->getSublayers(children);
 
189
    for (size_t i = 0; i < children.size(); ++i)
 
190
        children[i]->ensureAnimationsSubmitted();
 
191
}
 
192
 
 
193
void PlatformCALayer::setNeedsDisplay(const FloatRect* dirtyRect)
 
194
{
 
195
    intern(this)->setNeedsDisplay(dirtyRect);
 
196
}
 
197
    
 
198
void PlatformCALayer::setNeedsCommit()
 
199
{
 
200
    AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
 
201
    if (host)
 
202
        host->layerTreeDidChange();
 
203
}
 
204
 
 
205
void PlatformCALayer::setContentsChanged()
 
206
{
 
207
    // FIXME: There is no equivalent of setContentsChanged in CACF. For now I will
 
208
    // set contents to 0 and then back to its original value to see if that
 
209
    // kicks CACF into redisplaying.
 
210
    RetainPtr<CFTypeRef> contents = CACFLayerGetContents(m_layer.get());
 
211
    CACFLayerSetContents(m_layer.get(), 0);
 
212
    CACFLayerSetContents(m_layer.get(), contents.get());
 
213
    setNeedsCommit();
 
214
}
 
215
 
 
216
void PlatformCALayer::setNeedsLayout()
 
217
{
 
218
    if (!m_owner || !m_owner->platformCALayerRespondsToLayoutChanges())
 
219
        return;
 
220
 
 
221
    CACFLayerSetNeedsLayout(m_layer.get());
 
222
    setNeedsCommit();
 
223
}
 
224
 
 
225
PlatformCALayer* PlatformCALayer::superlayer() const
 
226
{
 
227
    return platformCALayer(CACFLayerGetSuperlayer(m_layer.get()));
 
228
}
 
229
 
 
230
void PlatformCALayer::removeFromSuperlayer()
 
231
{
 
232
    CACFLayerRemoveFromSuperlayer(m_layer.get());
 
233
    setNeedsCommit();
 
234
}
 
235
 
 
236
void PlatformCALayer::setSublayers(const PlatformCALayerList& list)
 
237
{
 
238
    intern(this)->setSublayers(list);
 
239
}
 
240
 
 
241
void PlatformCALayer::removeAllSublayers()
 
242
{
 
243
    intern(this)->removeAllSublayers();
 
244
}
 
245
 
 
246
void PlatformCALayer::appendSublayer(PlatformCALayer* layer)
 
247
{
 
248
    // This must be in terms of insertSublayer instead of a direct call so PlatformCALayerInternal can override.
 
249
    insertSublayer(layer, sublayerCount());
 
250
}
 
251
 
 
252
void PlatformCALayer::insertSublayer(PlatformCALayer* layer, size_t index)
 
253
{
 
254
    intern(this)->insertSublayer(layer, index);
 
255
}
 
256
 
 
257
void PlatformCALayer::replaceSublayer(PlatformCALayer* reference, PlatformCALayer* newLayer)
 
258
{
 
259
    // This must not use direct calls to allow PlatformCALayerInternal to override.
 
260
    ASSERT_ARG(reference, reference);
 
261
    ASSERT_ARG(reference, reference->superlayer() == this);
 
262
 
 
263
    if (reference == newLayer)
 
264
        return;
 
265
 
 
266
    int referenceIndex = intern(this)->indexOfSublayer(reference);
 
267
    ASSERT(referenceIndex != -1);
 
268
    if (referenceIndex == -1)
 
269
        return;
 
270
 
 
271
    reference->removeFromSuperlayer();
 
272
 
 
273
    if (newLayer) {
 
274
        newLayer->removeFromSuperlayer();
 
275
        insertSublayer(newLayer, referenceIndex);
 
276
    }
 
277
}
 
278
 
 
279
size_t PlatformCALayer::sublayerCount() const
 
280
{
 
281
    return intern(this)->sublayerCount();
 
282
}
 
283
 
 
284
void PlatformCALayer::adoptSublayers(PlatformCALayer* source)
 
285
{
 
286
    PlatformCALayerList sublayers;
 
287
    intern(source)->getSublayers(sublayers);
 
288
 
 
289
    // Use setSublayers() because it properly nulls out the superlayer pointers.
 
290
    setSublayers(sublayers);
 
291
}
 
292
 
 
293
void PlatformCALayer::addAnimationForKey(const String& key, PlatformCAAnimation* animation)
 
294
{
 
295
    // Add it to the animation list
 
296
    m_animations.add(key, animation);
 
297
 
 
298
    CACFLayerAddAnimation(m_layer.get(), key.createCFString().get(), animation->platformAnimation());
 
299
    setNeedsCommit();
 
300
 
 
301
    // Tell the host about it so we can fire the start animation event
 
302
    AbstractCACFLayerTreeHost* host = layerTreeHostForLayer(this);
 
303
    if (host)
 
304
        host->addPendingAnimatedLayer(this);
 
305
}
 
306
 
 
307
void PlatformCALayer::removeAnimationForKey(const String& key)
 
308
{
 
309
    // Remove it from the animation list
 
310
    m_animations.remove(key);
 
311
 
 
312
    CACFLayerRemoveAnimation(m_layer.get(), key.createCFString().get());
 
313
 
 
314
    // We don't "remove" a layer from AbstractCACFLayerTreeHost when it loses an animation.
 
315
    // There may be other active animations on the layer and if an animation
 
316
    // callback is fired on a layer without any animations no harm is done.
 
317
 
 
318
    setNeedsCommit();
 
319
}
 
320
 
 
321
PassRefPtr<PlatformCAAnimation> PlatformCALayer::animationForKey(const String& key)
 
322
{
 
323
    HashMap<String, RefPtr<PlatformCAAnimation> >::iterator it = m_animations.find(key);
 
324
    if (it == m_animations.end())
 
325
        return 0;
 
326
 
 
327
    return it->value;
 
328
}
 
329
 
 
330
PlatformCALayer* PlatformCALayer::mask() const
 
331
{
 
332
    return platformCALayer(CACFLayerGetMask(m_layer.get()));
 
333
}
 
334
 
 
335
void PlatformCALayer::setMask(PlatformCALayer* layer)
 
336
{
 
337
    CACFLayerSetMask(m_layer.get(), layer ? layer->platformLayer() : 0);
 
338
    setNeedsCommit();
 
339
}
 
340
 
 
341
bool PlatformCALayer::isOpaque() const
 
342
{
 
343
    return CACFLayerIsOpaque(m_layer.get());
 
344
}
 
345
 
 
346
void PlatformCALayer::setOpaque(bool value)
 
347
{
 
348
    CACFLayerSetOpaque(m_layer.get(), value);
 
349
    setNeedsCommit();
 
350
}
 
351
 
 
352
FloatRect PlatformCALayer::bounds() const
 
353
{
 
354
    return CACFLayerGetBounds(m_layer.get());
 
355
}
 
356
 
 
357
void PlatformCALayer::setBounds(const FloatRect& value)
 
358
{
 
359
    intern(this)->setBounds(value);
 
360
    setNeedsLayout();
 
361
}
 
362
 
 
363
FloatPoint3D PlatformCALayer::position() const
 
364
{
 
365
    CGPoint point = CACFLayerGetPosition(m_layer.get());
 
366
    return FloatPoint3D(point.x, point.y, CACFLayerGetZPosition(m_layer.get()));
 
367
}
 
368
 
 
369
void PlatformCALayer::setPosition(const FloatPoint3D& value)
 
370
{
 
371
    CACFLayerSetPosition(m_layer.get(), CGPointMake(value.x(), value.y()));
 
372
    CACFLayerSetZPosition(m_layer.get(), value.z());
 
373
    setNeedsCommit();
 
374
}
 
375
 
 
376
FloatPoint3D PlatformCALayer::anchorPoint() const
 
377
{
 
378
    CGPoint point = CACFLayerGetAnchorPoint(m_layer.get());
 
379
    float z = CACFLayerGetAnchorPointZ(m_layer.get());
 
380
    return FloatPoint3D(point.x, point.y, z);
 
381
}
 
382
 
 
383
void PlatformCALayer::setAnchorPoint(const FloatPoint3D& value)
 
384
{
 
385
    CACFLayerSetAnchorPoint(m_layer.get(), CGPointMake(value.x(), value.y()));
 
386
    CACFLayerSetAnchorPointZ(m_layer.get(), value.z());
 
387
    setNeedsCommit();
 
388
}
 
389
 
 
390
TransformationMatrix PlatformCALayer::transform() const
 
391
{
 
392
    return CACFLayerGetTransform(m_layer.get());
 
393
}
 
394
 
 
395
void PlatformCALayer::setTransform(const TransformationMatrix& value)
 
396
{
 
397
    CACFLayerSetTransform(m_layer.get(), value);
 
398
    setNeedsCommit();
 
399
}
 
400
 
 
401
TransformationMatrix PlatformCALayer::sublayerTransform() const
 
402
{
 
403
    return CACFLayerGetSublayerTransform(m_layer.get());
 
404
}
 
405
 
 
406
void PlatformCALayer::setSublayerTransform(const TransformationMatrix& value)
 
407
{
 
408
    CACFLayerSetSublayerTransform(m_layer.get(), value);
 
409
    setNeedsCommit();
 
410
}
 
411
 
 
412
TransformationMatrix PlatformCALayer::contentsTransform() const
 
413
{
 
414
    // ContentsTransform is not used
 
415
    return TransformationMatrix();
 
416
}
 
417
 
 
418
void PlatformCALayer::setContentsTransform(const TransformationMatrix&)
 
419
{
 
420
    // ContentsTransform is not used
 
421
}
 
422
 
 
423
bool PlatformCALayer::isHidden() const
 
424
{
 
425
    return CACFLayerIsHidden(m_layer.get());
 
426
}
 
427
 
 
428
void PlatformCALayer::setHidden(bool value)
 
429
{
 
430
    CACFLayerSetHidden(m_layer.get(), value);
 
431
    setNeedsCommit();
 
432
}
 
433
 
 
434
bool PlatformCALayer::isGeometryFlipped() const
 
435
{
 
436
    return CACFLayerIsGeometryFlipped(m_layer.get());
 
437
}
 
438
 
 
439
void PlatformCALayer::setGeometryFlipped(bool value)
 
440
{
 
441
    CACFLayerSetGeometryFlipped(m_layer.get(), value);
 
442
    setNeedsCommit();
 
443
}
 
444
 
 
445
bool PlatformCALayer::isDoubleSided() const
 
446
{
 
447
    return CACFLayerIsDoubleSided(m_layer.get());
 
448
}
 
449
 
 
450
void PlatformCALayer::setDoubleSided(bool value)
 
451
{
 
452
    CACFLayerSetDoubleSided(m_layer.get(), value);
 
453
    setNeedsCommit();
 
454
}
 
455
 
 
456
bool PlatformCALayer::masksToBounds() const
 
457
{
 
458
    return CACFLayerGetMasksToBounds(m_layer.get());
 
459
}
 
460
 
 
461
void PlatformCALayer::setMasksToBounds(bool value)
 
462
{
 
463
    CACFLayerSetMasksToBounds(m_layer.get(), value);
 
464
    setNeedsCommit();
 
465
}
 
466
 
 
467
bool PlatformCALayer::acceleratesDrawing() const
 
468
{
 
469
    return false;
 
470
}
 
471
 
 
472
void PlatformCALayer::setAcceleratesDrawing(bool)
 
473
{
 
474
}
 
475
 
 
476
CFTypeRef PlatformCALayer::contents() const
 
477
{
 
478
    return CACFLayerGetContents(m_layer.get());
 
479
}
 
480
 
 
481
void PlatformCALayer::setContents(CFTypeRef value)
 
482
{
 
483
    CACFLayerSetContents(m_layer.get(), value);
 
484
    setNeedsCommit();
 
485
}
 
486
 
 
487
FloatRect PlatformCALayer::contentsRect() const
 
488
{
 
489
    return CACFLayerGetContentsRect(m_layer.get());
 
490
}
 
491
 
 
492
void PlatformCALayer::setContentsRect(const FloatRect& value)
 
493
{
 
494
    CACFLayerSetContentsRect(m_layer.get(), value);
 
495
    setNeedsCommit();
 
496
}
 
497
 
 
498
void PlatformCALayer::setMinificationFilter(FilterType value)
 
499
{
 
500
    CACFLayerSetMinificationFilter(m_layer.get(), toCACFFilterType(value));
 
501
}
 
502
 
 
503
void PlatformCALayer::setMagnificationFilter(FilterType value)
 
504
{
 
505
    CACFLayerSetMagnificationFilter(m_layer.get(), toCACFFilterType(value));
 
506
    setNeedsCommit();
 
507
}
 
508
 
 
509
Color PlatformCALayer::backgroundColor() const
 
510
{
 
511
    return CACFLayerGetBackgroundColor(m_layer.get());
 
512
}
 
513
 
 
514
void PlatformCALayer::setBackgroundColor(const Color& value)
 
515
{
 
516
    CGFloat components[4];
 
517
    value.getRGBA(components[0], components[1], components[2], components[3]);
 
518
 
 
519
    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
 
520
    RetainPtr<CGColorRef> color(AdoptCF, CGColorCreate(colorSpace.get(), components));
 
521
 
 
522
    CACFLayerSetBackgroundColor(m_layer.get(), color.get());
 
523
    setNeedsCommit();
 
524
}
 
525
 
 
526
float PlatformCALayer::borderWidth() const
 
527
{
 
528
    return CACFLayerGetBorderWidth(m_layer.get());
 
529
}
 
530
 
 
531
void PlatformCALayer::setBorderWidth(float value)
 
532
{
 
533
    CACFLayerSetBorderWidth(m_layer.get(), value);
 
534
    setNeedsCommit();
 
535
}
 
536
 
 
537
Color PlatformCALayer::borderColor() const
 
538
{
 
539
    return CACFLayerGetBorderColor(m_layer.get());
 
540
}
 
541
 
 
542
void PlatformCALayer::setBorderColor(const Color& value)
 
543
{
 
544
    CGFloat components[4];
 
545
    value.getRGBA(components[0], components[1], components[2], components[3]);
 
546
 
 
547
    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
 
548
    RetainPtr<CGColorRef> color(AdoptCF, CGColorCreate(colorSpace.get(), components));
 
549
 
 
550
    CACFLayerSetBorderColor(m_layer.get(), color.get());
 
551
    setNeedsCommit();
 
552
}
 
553
 
 
554
float PlatformCALayer::opacity() const
 
555
{
 
556
    return CACFLayerGetOpacity(m_layer.get());
 
557
}
 
558
 
 
559
void PlatformCALayer::setOpacity(float value)
 
560
{
 
561
    CACFLayerSetOpacity(m_layer.get(), value);
 
562
    setNeedsCommit();
 
563
}
 
564
 
 
565
#if ENABLE(CSS_FILTERS)
 
566
 
 
567
void PlatformCALayer::setFilters(const FilterOperations&)
 
568
{
 
569
}
 
570
 
 
571
void PlatformCALayer::copyFiltersFrom(const PlatformCALayer*)
 
572
{
 
573
}
 
574
 
 
575
bool PlatformCALayer::filtersCanBeComposited(const FilterOperations&)
 
576
{
 
577
    return false;
 
578
}
 
579
 
 
580
#endif // ENABLE(CSS_FILTERS)
 
581
 
 
582
String PlatformCALayer::name() const
 
583
{
 
584
    return CACFLayerGetName(m_layer.get());
 
585
}
 
586
 
 
587
void PlatformCALayer::setName(const String& value)
 
588
{
 
589
    CACFLayerSetName(m_layer.get(), value.createCFString().get());
 
590
    setNeedsCommit();
 
591
}
 
592
 
 
593
FloatRect PlatformCALayer::frame() const
 
594
{
 
595
    return CACFLayerGetFrame(m_layer.get());
 
596
}
 
597
 
 
598
void PlatformCALayer::setFrame(const FloatRect& value)
 
599
{
 
600
    intern(this)->setFrame(value);
 
601
    setNeedsLayout();
 
602
}
 
603
 
 
604
float PlatformCALayer::speed() const
 
605
{
 
606
    return CACFLayerGetSpeed(m_layer.get());
 
607
}
 
608
 
 
609
void PlatformCALayer::setSpeed(float value)
 
610
{
 
611
    CACFLayerSetSpeed(m_layer.get(), value);
 
612
    setNeedsCommit();
 
613
}
 
614
 
 
615
CFTimeInterval PlatformCALayer::timeOffset() const
 
616
{
 
617
    return CACFLayerGetTimeOffset(m_layer.get());
 
618
}
 
619
 
 
620
void PlatformCALayer::setTimeOffset(CFTimeInterval value)
 
621
{
 
622
    CACFLayerSetTimeOffset(m_layer.get(), value);
 
623
    setNeedsCommit();
 
624
}
 
625
 
 
626
float PlatformCALayer::contentsScale() const
 
627
{
 
628
    return 1;
 
629
}
 
630
 
 
631
void PlatformCALayer::setContentsScale(float)
 
632
{
 
633
}
 
634
 
 
635
TiledBacking* PlatformCALayer::tiledBacking()
 
636
{
 
637
    return 0;
 
638
}
 
639
 
 
640
#ifndef NDEBUG
 
641
static void printIndent(int indent)
 
642
{
 
643
    for ( ; indent > 0; --indent)
 
644
        fprintf(stderr, "  ");
 
645
}
 
646
 
 
647
static void printTransform(const CATransform3D& transform)
 
648
{
 
649
    fprintf(stderr, "[%g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g]",
 
650
                    transform.m11, transform.m12, transform.m13, transform.m14, 
 
651
                    transform.m21, transform.m22, transform.m23, transform.m24, 
 
652
                    transform.m31, transform.m32, transform.m33, transform.m34, 
 
653
                    transform.m41, transform.m42, transform.m43, transform.m44);
 
654
}
 
655
 
 
656
static void printLayer(const PlatformCALayer* layer, int indent)
 
657
{
 
658
    FloatPoint3D layerPosition = layer->position();
 
659
    FloatPoint3D layerAnchorPoint = layer->anchorPoint();
 
660
    FloatRect layerBounds = layer->bounds();
 
661
    printIndent(indent);
 
662
 
 
663
    char* layerTypeName = 0;
 
664
    switch (layer->layerType()) {
 
665
    case PlatformCALayer::LayerTypeLayer: layerTypeName = "layer"; break;
 
666
    case PlatformCALayer::LayerTypeWebLayer: layerTypeName = "web-layer"; break;
 
667
    case PlatformCALayer::LayerTypeTransformLayer: layerTypeName = "transform-layer"; break;
 
668
    case PlatformCALayer::LayerTypeWebTiledLayer: layerTypeName = "web-tiled-layer"; break;
 
669
    case PlatformCALayer::LayerTypeRootLayer: layerTypeName = "root-layer"; break;
 
670
    case PlatformCALayer::LayerTypeCustom: layerTypeName = "custom-layer"; break;
 
671
    }
 
672
 
 
673
    fprintf(stderr, "(%s [%g %g %g] [%g %g %g %g] [%g %g %g] superlayer=%p\n",
 
674
        layerTypeName,
 
675
        layerPosition.x(), layerPosition.y(), layerPosition.z(), 
 
676
        layerBounds.x(), layerBounds.y(), layerBounds.width(), layerBounds.height(),
 
677
        layerAnchorPoint.x(), layerAnchorPoint.y(), layerAnchorPoint.z(), layer->superlayer());
 
678
 
 
679
    // Print name if needed
 
680
    String layerName = layer->name();
 
681
    if (!layerName.isEmpty()) {
 
682
        printIndent(indent + 1);
 
683
        fprintf(stderr, "(name %s)\n", layerName.utf8().data());
 
684
    }
 
685
 
 
686
    // Print masksToBounds if needed
 
687
    bool layerMasksToBounds = layer->masksToBounds();
 
688
    if (layerMasksToBounds) {
 
689
        printIndent(indent + 1);
 
690
        fprintf(stderr, "(masksToBounds true)\n");
 
691
    }
 
692
 
 
693
    // Print opacity if needed
 
694
    float layerOpacity = layer->opacity();
 
695
    if (layerOpacity != 1) {
 
696
        printIndent(indent + 1);
 
697
        fprintf(stderr, "(opacity %hf)\n", layerOpacity);
 
698
    }
 
699
 
 
700
    // Print sublayerTransform if needed
 
701
    TransformationMatrix layerTransform = layer->sublayerTransform();
 
702
    if (!layerTransform.isIdentity()) {
 
703
        printIndent(indent + 1);
 
704
        fprintf(stderr, "(sublayerTransform ");
 
705
        printTransform(layerTransform);
 
706
        fprintf(stderr, ")\n");
 
707
    }
 
708
 
 
709
    // Print transform if needed
 
710
    layerTransform = layer->transform();
 
711
    if (!layerTransform.isIdentity()) {
 
712
        printIndent(indent + 1);
 
713
        fprintf(stderr, "(transform ");
 
714
        printTransform(layerTransform);
 
715
        fprintf(stderr, ")\n");
 
716
    }
 
717
 
 
718
    // Print contents if needed
 
719
    CFTypeRef layerContents = layer->contents();
 
720
    if (layerContents) {
 
721
        if (CFGetTypeID(layerContents) == CGImageGetTypeID()) {
 
722
            CGImageRef imageContents = static_cast<CGImageRef>(const_cast<void*>(layerContents));
 
723
            printIndent(indent + 1);
 
724
            fprintf(stderr, "(contents (image [%d %d]))\n",
 
725
                CGImageGetWidth(imageContents), CGImageGetHeight(imageContents));
 
726
        }
 
727
    }
 
728
 
 
729
    // Print sublayers if needed
 
730
    int n = layer->sublayerCount();
 
731
    if (n > 0) {
 
732
        printIndent(indent + 1);
 
733
        fprintf(stderr, "(sublayers\n");
 
734
 
 
735
        PlatformCALayerList sublayers;
 
736
        intern(layer)->getSublayers(sublayers);
 
737
        ASSERT(n == sublayers.size());
 
738
        for (int i = 0; i < n; ++i)
 
739
            printLayer(sublayers[i].get(), indent + 2);
 
740
 
 
741
        printIndent(indent + 1);
 
742
        fprintf(stderr, ")\n");
 
743
    }
 
744
 
 
745
    printIndent(indent);
 
746
    fprintf(stderr, ")\n");
 
747
}
 
748
 
 
749
void PlatformCALayer::printTree() const
 
750
{
 
751
    // Print heading info
 
752
    CGRect rootBounds = bounds();
 
753
    fprintf(stderr, "\n\n** Render tree at time %g (bounds %g, %g %gx%g) **\n\n", 
 
754
        currentTime(), rootBounds.origin.x, rootBounds.origin.y, rootBounds.size.width, rootBounds.size.height);
 
755
 
 
756
    // Print layer tree from the root
 
757
    printLayer(this, 0);
 
758
}
 
759
#endif // #ifndef NDEBUG
 
760
 
 
761
#endif // USE(ACCELERATED_COMPOSITING)