1/* 2 * Copyright (C) 2009, 2010, 2011, 2012 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 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#ifndef CACFLayerTreeHost_h 27#define CACFLayerTreeHost_h 28 29#include "AbstractCACFLayerTreeHost.h" 30#include "COMPtr.h" 31#include "Timer.h" 32 33#include <wtf/HashSet.h> 34#include <wtf/PassRefPtr.h> 35#include <wtf/RefCounted.h> 36#include <wtf/RefPtr.h> 37#include <wtf/RetainPtr.h> 38#include <wtf/Vector.h> 39 40#include <CoreGraphics/CGGeometry.h> 41 42interface IDirect3DDevice9; 43struct WKCACFContext; 44 45typedef struct CGImage* CGImageRef; 46 47#if USE(AVFOUNDATION) 48struct GraphicsDeviceAdapter; 49#endif 50 51namespace WebCore { 52 53class CACFLayerTreeHostClient; 54class PlatformCALayer; 55 56class CACFLayerTreeHost : public RefCounted<CACFLayerTreeHost>, private AbstractCACFLayerTreeHost { 57public: 58 static PassRefPtr<CACFLayerTreeHost> create(); 59 virtual ~CACFLayerTreeHost(); 60 61 static bool acceleratedCompositingAvailable(); 62 63 void setClient(CACFLayerTreeHostClient* client) { m_client = client; } 64 65 void setRootChildLayer(PlatformCALayer*); 66 void setWindow(HWND); 67 virtual void paint(); 68 virtual void resize() = 0; 69 void flushPendingGraphicsLayerChangesSoon(); 70 virtual void setShouldInvertColors(bool); 71#if USE(AVFOUNDATION) 72 virtual GraphicsDeviceAdapter* graphicsDeviceAdapter() const { return 0; } 73#endif 74 75 virtual bool createRenderer() = 0; 76 77 // AbstractCACFLayerTreeHost 78 virtual void flushPendingLayerChangesNow(); 79 80protected: 81 CACFLayerTreeHost(); 82 83 CGRect bounds() const; 84 HWND window() const { return m_window; } 85 void notifyAnimationsStarted(); 86 87 // AbstractCACFLayerTreeHost 88 virtual PlatformCALayer* rootLayer() const; 89 90 virtual void destroyRenderer(); 91 virtual void contextDidChange(); 92 93private: 94 void initialize(); 95 96 // AbstractCACFLayerTreeHost 97 virtual void addPendingAnimatedLayer(PassRefPtr<PlatformCALayer>); 98 virtual void layerTreeDidChange(); 99 100 101 virtual void flushContext() = 0; 102 virtual CFTimeInterval lastCommitTime() const = 0; 103 virtual void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>()) = 0; 104 virtual void initializeContext(void* userData, PlatformCALayer*) = 0; 105 106 CACFLayerTreeHostClient* m_client; 107 RefPtr<PlatformCALayer> m_rootLayer; 108 RefPtr<PlatformCALayer> m_rootChildLayer; 109 HashSet<RefPtr<PlatformCALayer> > m_pendingAnimatedLayers; 110 HWND m_window; 111 bool m_shouldFlushPendingGraphicsLayerChanges; 112 bool m_isFlushingLayerChanges; 113 114#if !ASSERT_DISABLED 115 enum { WindowNotSet, WindowSet, WindowCleared } m_state; 116#endif 117}; 118 119} 120 121#endif // CACFLayerTreeHost_h 122