summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/ca
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-18 13:36:51 +0100
committerSteve Block <steveblock@google.com>2011-05-24 15:38:28 +0100
commit2fc2651226baac27029e38c9d6ef883fa32084db (patch)
treee396d4bf89dcce6ed02071be66212495b1df1dec /Source/WebCore/platform/graphics/ca
parentb3725cedeb43722b3b175aaeff70552e562d2c94 (diff)
downloadexternal_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.zip
external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.gz
external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.bz2
Merge WebKit at r78450: Initial merge by git.
Change-Id: I6d3e5f1f868ec266a0aafdef66182ddc3f265dc1
Diffstat (limited to 'Source/WebCore/platform/graphics/ca')
-rw-r--r--Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp4
-rw-r--r--Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h8
-rw-r--r--Source/WebCore/platform/graphics/ca/mac/PlatformCAAnimationMac.mm55
-rw-r--r--Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp401
-rw-r--r--Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.h58
-rw-r--r--Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHostClient.h43
-rw-r--r--Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.cpp401
-rw-r--r--Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.h82
-rw-r--r--Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp51
-rw-r--r--Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.cpp160
-rw-r--r--Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.h65
11 files changed, 880 insertions, 448 deletions
diff --git a/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp b/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
index 01e25e9..2b4a39e 100644
--- a/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
+++ b/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
@@ -1507,7 +1507,7 @@ void GraphicsLayerCA::pauseCAAnimationOnLayer(AnimatedPropertyID property, const
return;
// Animations on the layer are immutable, so we have to clone and modify.
- RefPtr<PlatformCAAnimation> newAnim = PlatformCAAnimation::create(curAnim.get());
+ RefPtr<PlatformCAAnimation> newAnim = curAnim->copy();
newAnim->setSpeed(0);
newAnim->setTimeOffset(timeOffset);
@@ -1646,7 +1646,7 @@ void GraphicsLayerCA::setupAnimation(PlatformCAAnimation* propertyAnim, const An
float repeatCount = anim->iterationCount();
if (repeatCount == Animation::IterationCountInfinite)
- repeatCount = FLT_MAX;
+ repeatCount = numeric_limits<float>::max();
else if (anim->direction() == Animation::AnimationDirectionAlternate)
repeatCount /= 2;
diff --git a/Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h b/Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h
index 4bfce63..a8528fd 100644
--- a/Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h
+++ b/Source/WebCore/platform/graphics/ca/PlatformCAAnimation.h
@@ -63,13 +63,14 @@ public:
enum ValueFunctionType { NoValueFunction, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, Scale, TranslateX, TranslateY, TranslateZ, Translate };
static PassRefPtr<PlatformCAAnimation> create(AnimationType, const String& keyPath);
- static PassRefPtr<PlatformCAAnimation> create(PlatformAnimationRef animation);
- static PassRefPtr<PlatformCAAnimation> create(const PlatformCAAnimation* animation);
+ static PassRefPtr<PlatformCAAnimation> create(PlatformAnimationRef);
~PlatformCAAnimation();
static bool supportsValueFunction();
+ PassRefPtr<PlatformCAAnimation> copy() const;
+
PlatformAnimationRef platformAnimation() const;
AnimationType animationType() const { return m_type; }
@@ -136,8 +137,7 @@ public:
protected:
PlatformCAAnimation(AnimationType, const String& keyPath);
- PlatformCAAnimation(PlatformAnimationRef animation);
- PlatformCAAnimation(const PlatformCAAnimation* animation);
+ PlatformCAAnimation(PlatformAnimationRef);
private:
AnimationType m_type;
diff --git a/Source/WebCore/platform/graphics/ca/mac/PlatformCAAnimationMac.mm b/Source/WebCore/platform/graphics/ca/mac/PlatformCAAnimationMac.mm
index 2a00857..506bd40 100644
--- a/Source/WebCore/platform/graphics/ca/mac/PlatformCAAnimationMac.mm
+++ b/Source/WebCore/platform/graphics/ca/mac/PlatformCAAnimationMac.mm
@@ -159,11 +159,6 @@ PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::create(PlatformAnimationRef
return adoptRef(new PlatformCAAnimation(animation));
}
-PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::create(const PlatformCAAnimation* animation)
-{
- return adoptRef(new PlatformCAAnimation(animation));
-}
-
PlatformCAAnimation::PlatformCAAnimation(AnimationType type, const String& keyPath)
: m_type(type)
{
@@ -187,38 +182,36 @@ PlatformCAAnimation::PlatformCAAnimation(PlatformAnimationRef animation)
m_animation = static_cast<CAPropertyAnimation*>(animation);
}
-PlatformCAAnimation::PlatformCAAnimation(const PlatformCAAnimation* animation)
+PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::copy() const
{
- PlatformCAAnimation* newAnimation = new PlatformCAAnimation(animation->animationType(), animation->keyPath());
-
- newAnimation->setBeginTime(animation->beginTime());
- newAnimation->setDuration(animation->duration());
- newAnimation->setSpeed(animation->speed());
- newAnimation->setTimeOffset(animation->timeOffset());
- newAnimation->setRepeatCount(animation->repeatCount());
- newAnimation->setAutoreverses(animation->autoreverses());
- newAnimation->setFillMode(animation->fillMode());
- newAnimation->setRemovedOnCompletion(animation->isRemovedOnCompletion());
- newAnimation->setAdditive(animation->isAdditive());
- newAnimation->copyTimingFunctionFrom(animation);
-
-#if HAVE_MODERN_QUARTZCORE
- newAnimation->setValueFunction(animation->valueFunction());
-#endif
-
- setNonZeroBeginTimeFlag(newAnimation, hasNonZeroBeginTimeFlag(animation));
+ RefPtr<PlatformCAAnimation> animation = create(animationType(), keyPath());
+
+ animation->setBeginTime(beginTime());
+ animation->setDuration(duration());
+ animation->setSpeed(speed());
+ animation->setTimeOffset(timeOffset());
+ animation->setRepeatCount(repeatCount());
+ animation->setAutoreverses(autoreverses());
+ animation->setFillMode(fillMode());
+ animation->setRemovedOnCompletion(isRemovedOnCompletion());
+ animation->setAdditive(isAdditive());
+ animation->copyTimingFunctionFrom(this);
+ animation->setValueFunction(valueFunction());
+
+ setNonZeroBeginTimeFlag(animation.get(), hasNonZeroBeginTimeFlag(this));
// Copy the specific Basic or Keyframe values
- if (animation->animationType() == Keyframe) {
- newAnimation->copyValuesFrom(animation);
- newAnimation->copyKeyTimesFrom(animation);
- newAnimation->copyTimingFunctionsFrom(animation);
+ if (animationType() == Keyframe) {
+ animation->copyValuesFrom(this);
+ animation->copyKeyTimesFrom(this);
+ animation->copyTimingFunctionsFrom(this);
} else {
- newAnimation->copyFromValueFrom(animation);
- newAnimation->copyToValueFrom(animation);
+ animation->copyFromValueFrom(this);
+ animation->copyToValueFrom(this);
}
+
+ return animation;
}
-
PlatformCAAnimation::~PlatformCAAnimation()
{
}
diff --git a/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp b/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp
index 1d27608..9dc30ea 100644
--- a/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp
+++ b/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.cpp
@@ -28,49 +28,22 @@
#if USE(ACCELERATED_COMPOSITING)
+#include "CACFLayerTreeHostClient.h"
#include "LayerChangesFlusher.h"
+#include "LegacyCACFLayerTreeHost.h"
#include "PlatformCALayer.h"
+#include "WKCACFViewLayerTreeHost.h"
#include "WebCoreInstanceHandle.h"
-#include <WebKitSystemInterface/WebKitSystemInterface.h>
#include <limits.h>
#include <wtf/CurrentTime.h>
-#include <wtf/HashMap.h>
#include <wtf/OwnArrayPtr.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
-#include <wtf/StdLibExtras.h>
-#ifndef NDEBUG
-#define D3D_DEBUG_INFO
-#endif
-
-#include <d3d9.h>
-#include <d3dx9.h>
-
-using namespace std;
-
-#pragma comment(lib, "d3d9")
-#pragma comment(lib, "d3dx9")
#ifdef DEBUG_ALL
#pragma comment(lib, "QuartzCore_debug")
#else
#pragma comment(lib, "QuartzCore")
#endif
-static IDirect3D9* s_d3d = 0;
-static IDirect3D9* d3d()
-{
- if (s_d3d)
- return s_d3d;
-
- if (!LoadLibrary(TEXT("d3d9.dll")))
- return 0;
-
- s_d3d = Direct3DCreate9(D3D_SDK_VERSION);
-
- return s_d3d;
-}
-
inline static CGRect winRectToCGRect(RECT rc)
{
return CGRectMake(rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top));
@@ -83,40 +56,6 @@ inline static CGRect winRectToCGRect(RECT rc, RECT relativeToRect)
namespace WebCore {
-static D3DPRESENT_PARAMETERS initialPresentationParameters()
-{
- D3DPRESENT_PARAMETERS parameters = {0};
- parameters.Windowed = TRUE;
- parameters.SwapEffect = D3DSWAPEFFECT_COPY;
- parameters.BackBufferCount = 1;
- parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
- parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
-
- return parameters;
-}
-
-// FIXME: <rdar://6507851> Share this code with CoreAnimation.
-static bool hardwareCapabilitiesIndicateCoreAnimationSupport(const D3DCAPS9& caps)
-{
- // CoreAnimation needs two or more texture units.
- if (caps.MaxTextureBlendStages < 2)
- return false;
-
- // CoreAnimation needs non-power-of-two textures.
- if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
- return false;
-
- // CoreAnimation needs vertex shader 2.0 or greater.
- if (D3DSHADER_VERSION_MAJOR(caps.VertexShaderVersion) < 2)
- return false;
-
- // CoreAnimation needs pixel shader 2.0 or greater.
- if (D3DSHADER_VERSION_MAJOR(caps.PixelShaderVersion) < 2)
- return false;
-
- return true;
-}
-
bool CACFLayerTreeHost::acceleratedCompositingAvailable()
{
static bool available;
@@ -158,7 +97,7 @@ bool CACFLayerTreeHost::acceleratedCompositingAvailable()
wcex.hInstance = WebCore::instanceHandle();
wcex.lpszClassName = L"CoreAnimationTesterWindowClass";
::RegisterClassEx(&wcex);
- HWND testWindow = ::CreateWindow(L"CoreAnimationTesterWindowClass", L"CoreAnimationTesterWindow", WS_POPUP, -500, -500, 0, 0, 0, 0, 0, 0);
+ HWND testWindow = ::CreateWindow(L"CoreAnimationTesterWindowClass", L"CoreAnimationTesterWindow", WS_POPUP, -500, -500, 20, 20, 0, 0, 0, 0);
if (!testWindow) {
available = false;
@@ -168,6 +107,7 @@ bool CACFLayerTreeHost::acceleratedCompositingAvailable()
RefPtr<CACFLayerTreeHost> host = CACFLayerTreeHost::create();
host->setWindow(testWindow);
available = host->createRenderer();
+ host->setWindow(0);
::DestroyWindow(testWindow);
return available;
@@ -177,22 +117,29 @@ PassRefPtr<CACFLayerTreeHost> CACFLayerTreeHost::create()
{
if (!acceleratedCompositingAvailable())
return 0;
- return adoptRef(new CACFLayerTreeHost());
+ RefPtr<CACFLayerTreeHost> host = WKCACFViewLayerTreeHost::create();
+ if (!host)
+ host = LegacyCACFLayerTreeHost::create();
+ host->initialize();
+ return host.release();
}
CACFLayerTreeHost::CACFLayerTreeHost()
: m_client(0)
- , m_mightBeAbleToCreateDeviceLater(true)
, m_rootLayer(PlatformCALayer::create(PlatformCALayer::LayerTypeRootLayer, 0))
- , m_context(wkCACFContextCreate())
, m_window(0)
- , m_renderTimer(this, &CACFLayerTreeHost::renderTimerFired)
- , m_mustResetLostDeviceBeforeRendering(false)
, m_shouldFlushPendingGraphicsLayerChanges(false)
, m_isFlushingLayerChanges(false)
+#if !ASSERT_DISABLED
+ , m_state(WindowNotSet)
+#endif
+{
+}
+
+void CACFLayerTreeHost::initialize()
{
// Point the CACFContext to this
- wkCACFContextSetUserData(m_context, this);
+ initializeContext(this, m_rootLayer.get());
// Under the root layer, we have a clipping layer to clip the content,
// that contains a scroll layer that we use for scrolling the content.
@@ -212,20 +159,11 @@ CACFLayerTreeHost::CACFLayerTreeHost()
m_rootLayer->setBackgroundColor(debugColor);
CGColorRelease(debugColor);
#endif
-
- if (m_context)
- wkCACFContextSetLayer(m_context, m_rootLayer->platformLayer());
-
-#ifndef NDEBUG
- char* printTreeFlag = getenv("CA_PRINT_TREE");
- m_printTree = printTreeFlag && atoi(printTreeFlag);
-#endif
}
CACFLayerTreeHost::~CACFLayerTreeHost()
{
- setWindow(0);
- wkCACFContextDestroy(m_context);
+ ASSERT_WITH_MESSAGE(m_state != WindowSet, "Must call setWindow(0) before destroying CACFLayerTreeHost");
}
void CACFLayerTreeHost::setWindow(HWND window)
@@ -233,13 +171,28 @@ void CACFLayerTreeHost::setWindow(HWND window)
if (window == m_window)
return;
+#if !ASSERT_DISABLED
+ switch (m_state) {
+ case WindowNotSet:
+ ASSERT_ARG(window, window);
+ ASSERT(!m_window);
+ m_state = WindowSet;
+ break;
+ case WindowSet:
+ ASSERT_ARG(window, !window);
+ ASSERT(m_window);
+ m_state = WindowCleared;
+ break;
+ case WindowCleared:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+#endif
+
if (m_window)
destroyRenderer();
m_window = window;
-
- if (m_window)
- createRenderer();
}
PlatformCALayer* CACFLayerTreeHost::rootLayer() const
@@ -275,109 +228,11 @@ void CACFLayerTreeHost::layerTreeDidChange()
LayerChangesFlusher::shared().flushPendingLayerChangesSoon(this);
}
-bool CACFLayerTreeHost::createRenderer()
-{
- if (m_d3dDevice || !m_mightBeAbleToCreateDeviceLater)
- return m_d3dDevice;
-
- m_mightBeAbleToCreateDeviceLater = false;
- D3DPRESENT_PARAMETERS parameters = initialPresentationParameters();
-
- if (!d3d() || !::IsWindow(m_window))
- return false;
-
- // D3D doesn't like to make back buffers for 0 size windows. We skirt this problem if we make the
- // passed backbuffer width and height non-zero. The window will necessarily get set to a non-zero
- // size eventually, and then the backbuffer size will get reset.
- RECT rect;
- GetClientRect(m_window, &rect);
-
- if (rect.left-rect.right == 0 || rect.bottom-rect.top == 0) {
- parameters.BackBufferWidth = 1;
- parameters.BackBufferHeight = 1;
- }
-
- D3DCAPS9 d3dCaps;
- if (FAILED(d3d()->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps)))
- return false;
-
- DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE;
- if ((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && d3dCaps.VertexProcessingCaps)
- behaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
- else
- behaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
-
- COMPtr<IDirect3DDevice9> device;
- if (FAILED(d3d()->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_window, behaviorFlags, &parameters, &device))) {
- // In certain situations (e.g., shortly after waking from sleep), Direct3DCreate9() will
- // return an IDirect3D9 for which IDirect3D9::CreateDevice will always fail. In case we
- // have one of these bad IDirect3D9s, get rid of it so we'll fetch a new one the next time
- // we want to call CreateDevice.
- s_d3d->Release();
- s_d3d = 0;
-
- // Even if we don't have a bad IDirect3D9, in certain situations (e.g., shortly after
- // waking from sleep), CreateDevice will fail, but will later succeed if called again.
- m_mightBeAbleToCreateDeviceLater = true;
-
- return false;
- }
-
- // Now that we've created the IDirect3DDevice9 based on the capabilities we
- // got from the IDirect3D9 global object, we requery the device for its
- // actual capabilities. The capabilities returned by the device can
- // sometimes be more complete, for example when using software vertex
- // processing.
- D3DCAPS9 deviceCaps;
- if (FAILED(device->GetDeviceCaps(&deviceCaps)))
- return false;
-
- if (!hardwareCapabilitiesIndicateCoreAnimationSupport(deviceCaps))
- return false;
-
- m_d3dDevice = device;
-
- initD3DGeometry();
-
- wkCACFContextSetD3DDevice(m_context, m_d3dDevice.get());
-
- if (IsWindow(m_window))
- m_rootLayer->setBounds(bounds());
-
- return true;
-}
-
void CACFLayerTreeHost::destroyRenderer()
{
- LayerChangesFlusher::shared().cancelPendingFlush(this);
-
- wkCACFContextSetLayer(m_context, 0);
-
- wkCACFContextSetD3DDevice(m_context, 0);
- m_d3dDevice = 0;
- if (s_d3d)
- s_d3d->Release();
-
- s_d3d = 0;
m_rootLayer = 0;
m_rootChildLayer = 0;
-
- m_mightBeAbleToCreateDeviceLater = true;
-}
-
-void CACFLayerTreeHost::resize()
-{
- if (!m_d3dDevice)
- return;
-
- // Resetting the device might fail here. But that's OK, because if it does it we will attempt to
- // reset the device the next time we try to render.
- resetDevice(ChangedWindowSize);
-
- if (m_rootLayer) {
- m_rootLayer->setBounds(bounds());
- wkCACFContextFlush(m_context);
- }
+ LayerChangesFlusher::shared().cancelPendingFlush(this);
}
static void getDirtyRects(HWND window, Vector<CGRect>& outRects)
@@ -398,7 +253,7 @@ static void getDirtyRects(HWND window, Vector<CGRect>& outRects)
}
DWORD dataSize = GetRegionData(region.get(), 0, 0);
- OwnArrayPtr<unsigned char> regionDataBuffer(new unsigned char[dataSize]);
+ OwnArrayPtr<unsigned char> regionDataBuffer = adoptArrayPtr(new unsigned char[dataSize]);
RGNDATA* regionData = reinterpret_cast<RGNDATA*>(regionDataBuffer.get());
if (!GetRegionData(region.get(), dataSize, regionData))
return;
@@ -410,120 +265,13 @@ static void getDirtyRects(HWND window, Vector<CGRect>& outRects)
outRects[i] = winRectToCGRect(*rect, clientRect);
}
-void CACFLayerTreeHost::renderTimerFired(Timer<CACFLayerTreeHost>*)
-{
- paint();
-}
-
void CACFLayerTreeHost::paint()
{
- createRenderer();
- if (!m_d3dDevice) {
- if (m_mightBeAbleToCreateDeviceLater)
- renderSoon();
- return;
- }
-
Vector<CGRect> dirtyRects;
getDirtyRects(m_window, dirtyRects);
render(dirtyRects);
}
-void CACFLayerTreeHost::render(const Vector<CGRect>& windowDirtyRects)
-{
- ASSERT(m_d3dDevice);
-
- if (m_mustResetLostDeviceBeforeRendering && !resetDevice(LostDevice)) {
- // We can't reset the device right now. Try again soon.
- renderSoon();
- return;
- }
-
- // All pending animations will have been started with the flush. Fire the animationStarted calls
- double currentTime = WTF::currentTime();
- double currentMediaTime = CACurrentMediaTime();
- double t = currentTime + wkCACFContextGetLastCommitTime(m_context) - currentMediaTime;
- ASSERT(t <= currentTime);
-
- HashSet<RefPtr<PlatformCALayer> >::iterator end = m_pendingAnimatedLayers.end();
- for (HashSet<RefPtr<PlatformCALayer> >::iterator it = m_pendingAnimatedLayers.begin(); it != end; ++it) {
- PlatformCALayerClient* owner = (*it)->owner();
- owner->platformCALayerAnimationStarted(t);
- }
-
- m_pendingAnimatedLayers.clear();
-
- CGRect bounds = this->bounds();
-
- // Give the renderer some space to use. This needs to be valid until the
- // wkCACFContextFinishUpdate() call below.
- char space[4096];
- if (!wkCACFContextBeginUpdate(m_context, space, sizeof(space), currentMediaTime, bounds, windowDirtyRects.data(), windowDirtyRects.size()))
- return;
-
- HRESULT err = S_OK;
- CFTimeInterval timeToNextRender = numeric_limits<CFTimeInterval>::infinity();
-
- do {
- // FIXME: don't need to clear dirty region if layer tree is opaque.
-
- WKCACFUpdateRectEnumerator* e = wkCACFContextCopyUpdateRectEnumerator(m_context);
- if (!e)
- break;
-
- Vector<D3DRECT, 64> rects;
- for (const CGRect* r = wkCACFUpdateRectEnumeratorNextRect(e); r; r = wkCACFUpdateRectEnumeratorNextRect(e)) {
- D3DRECT rect;
- rect.x1 = r->origin.x;
- rect.x2 = rect.x1 + r->size.width;
- rect.y1 = bounds.origin.y + bounds.size.height - (r->origin.y + r->size.height);
- rect.y2 = rect.y1 + r->size.height;
-
- rects.append(rect);
- }
- wkCACFUpdateRectEnumeratorRelease(e);
-
- timeToNextRender = wkCACFContextGetNextUpdateTime(m_context);
-
- if (rects.isEmpty())
- break;
-
- m_d3dDevice->Clear(rects.size(), rects.data(), D3DCLEAR_TARGET, 0, 1.0f, 0);
-
- m_d3dDevice->BeginScene();
- wkCACFContextRenderUpdate(m_context);
- m_d3dDevice->EndScene();
-
- err = m_d3dDevice->Present(0, 0, 0, 0);
-
- if (err == D3DERR_DEVICELOST) {
- wkCACFContextAddUpdateRect(m_context, bounds);
- if (!resetDevice(LostDevice)) {
- // We can't reset the device right now. Try again soon.
- renderSoon();
- return;
- }
- }
- } while (err == D3DERR_DEVICELOST);
-
- wkCACFContextFinishUpdate(m_context);
-
-#ifndef NDEBUG
- if (m_printTree)
- m_rootLayer->printTree();
-#endif
-
- // If timeToNextRender is not infinity, it means animations are running, so queue up to render again
- if (timeToNextRender != numeric_limits<CFTimeInterval>::infinity())
- renderSoon();
-}
-
-void CACFLayerTreeHost::renderSoon()
-{
- if (!m_renderTimer.isActive())
- m_renderTimer.startOneShot(0);
-}
-
void CACFLayerTreeHost::flushPendingGraphicsLayerChangesSoon()
{
m_shouldFlushPendingGraphicsLayerChanges = true;
@@ -545,75 +293,36 @@ void CACFLayerTreeHost::flushPendingLayerChangesNow()
}
// Flush changes stored up in PlatformCALayers to the context so they will be rendered.
- wkCACFContextFlush(m_context);
-
- renderSoon();
+ flushContext();
m_isFlushingLayerChanges = false;
}
-CGRect CACFLayerTreeHost::bounds() const
+void CACFLayerTreeHost::contextDidChange()
{
- RECT clientRect;
- GetClientRect(m_window, &clientRect);
-
- return winRectToCGRect(clientRect);
+ // All pending animations will have been started with the flush. Fire the animationStarted calls.
+ notifyAnimationsStarted();
}
-void CACFLayerTreeHost::initD3DGeometry()
+void CACFLayerTreeHost::notifyAnimationsStarted()
{
- ASSERT(m_d3dDevice);
-
- CGRect bounds = this->bounds();
-
- float x0 = bounds.origin.x;
- float y0 = bounds.origin.y;
- float x1 = x0 + bounds.size.width;
- float y1 = y0 + bounds.size.height;
+ double currentTime = WTF::currentTime();
+ double time = currentTime + lastCommitTime() - CACurrentMediaTime();
+ ASSERT(time <= currentTime);
- D3DXMATRIXA16 projection;
- D3DXMatrixOrthoOffCenterRH(&projection, x0, x1, y0, y1, -1.0f, 1.0f);
+ HashSet<RefPtr<PlatformCALayer> >::iterator end = m_pendingAnimatedLayers.end();
+ for (HashSet<RefPtr<PlatformCALayer> >::iterator it = m_pendingAnimatedLayers.begin(); it != end; ++it)
+ (*it)->animationStarted(time);
- m_d3dDevice->SetTransform(D3DTS_PROJECTION, &projection);
+ m_pendingAnimatedLayers.clear();
}
-bool CACFLayerTreeHost::resetDevice(ResetReason reason)
+CGRect CACFLayerTreeHost::bounds() const
{
- ASSERT(m_d3dDevice);
- ASSERT(m_context);
-
- HRESULT hr = m_d3dDevice->TestCooperativeLevel();
-
- if (hr == D3DERR_DEVICELOST || hr == D3DERR_DRIVERINTERNALERROR) {
- // The device cannot be reset at this time. Try again soon.
- m_mustResetLostDeviceBeforeRendering = true;
- return false;
- }
-
- m_mustResetLostDeviceBeforeRendering = false;
-
- if (reason == LostDevice && hr == D3D_OK) {
- // The device wasn't lost after all.
- return true;
- }
-
- // We can reset the device.
-
- // We have to release the context's D3D resrouces whenever we reset the IDirect3DDevice9 in order to
- // destroy any D3DPOOL_DEFAULT resources that Core Animation has allocated (e.g., textures used
- // for mask layers). See <http://msdn.microsoft.com/en-us/library/bb174425(v=VS.85).aspx>.
- wkCACFContextReleaseD3DResources(m_context);
-
- D3DPRESENT_PARAMETERS parameters = initialPresentationParameters();
- hr = m_d3dDevice->Reset(&parameters);
-
- // TestCooperativeLevel told us the device may be reset now, so we should
- // not be told here that the device is lost.
- ASSERT(hr != D3DERR_DEVICELOST);
-
- initD3DGeometry();
+ RECT clientRect;
+ GetClientRect(m_window, &clientRect);
- return true;
+ return winRectToCGRect(clientRect);
}
}
diff --git a/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.h b/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.h
index fc61f39..6d91a73 100644
--- a/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.h
+++ b/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHost.h
@@ -47,75 +47,59 @@ typedef struct CGImage* CGImageRef;
namespace WebCore {
+class CACFLayerTreeHostClient;
class PlatformCALayer;
-class CACFLayerTreeHostClient {
-public:
- virtual ~CACFLayerTreeHostClient() { }
- virtual void flushPendingGraphicsLayerChanges() { }
-};
-
-// FIXME: Currently there is a CACFLayerTreeHost for each WebView and each
-// has its own CARenderOGLContext and Direct3DDevice9, which is inefficient.
-// (https://bugs.webkit.org/show_bug.cgi?id=31855)
class CACFLayerTreeHost : public RefCounted<CACFLayerTreeHost> {
friend PlatformCALayer;
public:
static PassRefPtr<CACFLayerTreeHost> create();
- ~CACFLayerTreeHost();
+ virtual ~CACFLayerTreeHost();
static bool acceleratedCompositingAvailable();
void setClient(CACFLayerTreeHostClient* client) { m_client = client; }
void setRootChildLayer(PlatformCALayer*);
- void layerTreeDidChange();
void setWindow(HWND);
- void paint();
- void resize();
+ virtual void paint();
+ virtual void resize() = 0;
void flushPendingGraphicsLayerChangesSoon();
void flushPendingLayerChangesNow();
protected:
- PlatformCALayer* rootLayer() const;
- void addPendingAnimatedLayer(PassRefPtr<PlatformCALayer>);
-
-private:
CACFLayerTreeHost();
- bool createRenderer();
- void destroyRenderer();
- void renderSoon();
- void renderTimerFired(Timer<CACFLayerTreeHost>*);
-
CGRect bounds() const;
+ PlatformCALayer* rootLayer() const;
+ HWND window() const { return m_window; }
+ void notifyAnimationsStarted();
- void initD3DGeometry();
+ virtual bool createRenderer() = 0;
+ virtual void destroyRenderer();
+ virtual void contextDidChange();
- // Call this when the device window has changed size or when IDirect3DDevice9::Present returns
- // D3DERR_DEVICELOST. Returns true if the device was recovered, false if rendering must be
- // aborted and reattempted soon.
- enum ResetReason { ChangedWindowSize, LostDevice };
- bool resetDevice(ResetReason);
+private:
+ void initialize();
+ void addPendingAnimatedLayer(PassRefPtr<PlatformCALayer>);
+ void layerTreeDidChange();
- void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
+ virtual void flushContext() = 0;
+ virtual CFTimeInterval lastCommitTime() const = 0;
+ virtual void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>()) = 0;
+ virtual void initializeContext(void* userData, PlatformCALayer*) = 0;
CACFLayerTreeHostClient* m_client;
- bool m_mightBeAbleToCreateDeviceLater;
- COMPtr<IDirect3DDevice9> m_d3dDevice;
RefPtr<PlatformCALayer> m_rootLayer;
RefPtr<PlatformCALayer> m_rootChildLayer;
- WKCACFContext* m_context;
+ HashSet<RefPtr<PlatformCALayer> > m_pendingAnimatedLayers;
HWND m_window;
- Timer<CACFLayerTreeHost> m_renderTimer;
- bool m_mustResetLostDeviceBeforeRendering;
bool m_shouldFlushPendingGraphicsLayerChanges;
bool m_isFlushingLayerChanges;
- HashSet<RefPtr<PlatformCALayer> > m_pendingAnimatedLayers;
-#ifndef NDEBUG
- bool m_printTree;
+#if !ASSERT_DISABLED
+ enum { WindowNotSet, WindowSet, WindowCleared } m_state;
#endif
};
diff --git a/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHostClient.h b/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHostClient.h
new file mode 100644
index 0000000..845f934
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ca/win/CACFLayerTreeHostClient.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CACFLayerTreeHostClient_h
+#define CACFLayerTreeHostClient_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+namespace WebCore {
+
+class CACFLayerTreeHostClient {
+public:
+ virtual ~CACFLayerTreeHostClient() { }
+ virtual void flushPendingGraphicsLayerChanges() { }
+};
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // CACFLayerTreeHostClient_h
diff --git a/Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.cpp b/Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.cpp
new file mode 100644
index 0000000..772244b
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.cpp
@@ -0,0 +1,401 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LegacyCACFLayerTreeHost.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "PlatformCALayer.h"
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
+
+#ifndef NDEBUG
+#define D3D_DEBUG_INFO
+#endif
+
+#include <d3d9.h>
+#include <d3dx9.h>
+
+#pragma comment(lib, "d3d9")
+#pragma comment(lib, "d3dx9")
+
+using namespace std;
+
+namespace WebCore {
+
+static IDirect3D9* s_d3d = 0;
+static IDirect3D9* d3d()
+{
+ if (s_d3d)
+ return s_d3d;
+
+ if (!LoadLibrary(TEXT("d3d9.dll")))
+ return 0;
+
+ s_d3d = Direct3DCreate9(D3D_SDK_VERSION);
+
+ return s_d3d;
+}
+
+static D3DPRESENT_PARAMETERS initialPresentationParameters()
+{
+ D3DPRESENT_PARAMETERS parameters = {0};
+ parameters.Windowed = TRUE;
+ parameters.SwapEffect = D3DSWAPEFFECT_COPY;
+ parameters.BackBufferCount = 1;
+ parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
+ parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
+
+ return parameters;
+}
+
+// FIXME: <rdar://6507851> Share this code with CoreAnimation.
+static bool hardwareCapabilitiesIndicateCoreAnimationSupport(const D3DCAPS9& caps)
+{
+ // CoreAnimation needs two or more texture units.
+ if (caps.MaxTextureBlendStages < 2)
+ return false;
+
+ // CoreAnimation needs non-power-of-two textures.
+ if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
+ return false;
+
+ // CoreAnimation needs vertex shader 2.0 or greater.
+ if (D3DSHADER_VERSION_MAJOR(caps.VertexShaderVersion) < 2)
+ return false;
+
+ // CoreAnimation needs pixel shader 2.0 or greater.
+ if (D3DSHADER_VERSION_MAJOR(caps.PixelShaderVersion) < 2)
+ return false;
+
+ return true;
+}
+
+PassRefPtr<LegacyCACFLayerTreeHost> LegacyCACFLayerTreeHost::create()
+{
+ return adoptRef(new LegacyCACFLayerTreeHost);
+}
+
+LegacyCACFLayerTreeHost::LegacyCACFLayerTreeHost()
+ : m_renderTimer(this, &LegacyCACFLayerTreeHost::renderTimerFired)
+ , m_context(wkCACFContextCreate())
+ , m_mightBeAbleToCreateDeviceLater(true)
+ , m_mustResetLostDeviceBeforeRendering(false)
+{
+#ifndef NDEBUG
+ char* printTreeFlag = getenv("CA_PRINT_TREE");
+ m_printTree = printTreeFlag && atoi(printTreeFlag);
+#endif
+}
+
+LegacyCACFLayerTreeHost::~LegacyCACFLayerTreeHost()
+{
+ wkCACFContextDestroy(m_context);
+}
+
+void LegacyCACFLayerTreeHost::initializeContext(void* userData, PlatformCALayer* layer)
+{
+ wkCACFContextSetUserData(m_context, userData);
+ wkCACFContextSetLayer(m_context, layer->platformLayer());
+}
+
+bool LegacyCACFLayerTreeHost::createRenderer()
+{
+ if (m_d3dDevice || !m_mightBeAbleToCreateDeviceLater)
+ return m_d3dDevice;
+
+ m_mightBeAbleToCreateDeviceLater = false;
+ D3DPRESENT_PARAMETERS parameters = initialPresentationParameters();
+
+ if (!d3d() || !::IsWindow(window()))
+ return false;
+
+ // D3D doesn't like to make back buffers for 0 size windows. We skirt this problem if we make the
+ // passed backbuffer width and height non-zero. The window will necessarily get set to a non-zero
+ // size eventually, and then the backbuffer size will get reset.
+ RECT rect;
+ GetClientRect(window(), &rect);
+
+ if (rect.left-rect.right == 0 || rect.bottom-rect.top == 0) {
+ parameters.BackBufferWidth = 1;
+ parameters.BackBufferHeight = 1;
+ }
+
+ D3DCAPS9 d3dCaps;
+ if (FAILED(d3d()->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps)))
+ return false;
+
+ DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE;
+ if ((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && d3dCaps.VertexProcessingCaps)
+ behaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
+ else
+ behaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+
+ COMPtr<IDirect3DDevice9> device;
+ if (FAILED(d3d()->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window(), behaviorFlags, &parameters, &device))) {
+ // In certain situations (e.g., shortly after waking from sleep), Direct3DCreate9() will
+ // return an IDirect3D9 for which IDirect3D9::CreateDevice will always fail. In case we
+ // have one of these bad IDirect3D9s, get rid of it so we'll fetch a new one the next time
+ // we want to call CreateDevice.
+ s_d3d->Release();
+ s_d3d = 0;
+
+ // Even if we don't have a bad IDirect3D9, in certain situations (e.g., shortly after
+ // waking from sleep), CreateDevice will fail, but will later succeed if called again.
+ m_mightBeAbleToCreateDeviceLater = true;
+
+ return false;
+ }
+
+ // Now that we've created the IDirect3DDevice9 based on the capabilities we
+ // got from the IDirect3D9 global object, we requery the device for its
+ // actual capabilities. The capabilities returned by the device can
+ // sometimes be more complete, for example when using software vertex
+ // processing.
+ D3DCAPS9 deviceCaps;
+ if (FAILED(device->GetDeviceCaps(&deviceCaps)))
+ return false;
+
+ if (!hardwareCapabilitiesIndicateCoreAnimationSupport(deviceCaps))
+ return false;
+
+ m_d3dDevice = device;
+
+ initD3DGeometry();
+
+ wkCACFContextSetD3DDevice(m_context, m_d3dDevice.get());
+
+ if (IsWindow(window())) {
+ rootLayer()->setBounds(bounds());
+ flushContext();
+ }
+
+ return true;
+}
+
+void LegacyCACFLayerTreeHost::destroyRenderer()
+{
+ wkCACFContextSetLayer(m_context, 0);
+
+ wkCACFContextSetD3DDevice(m_context, 0);
+ m_d3dDevice = 0;
+ if (s_d3d)
+ s_d3d->Release();
+
+ s_d3d = 0;
+ m_mightBeAbleToCreateDeviceLater = true;
+
+ CACFLayerTreeHost::destroyRenderer();
+}
+
+void LegacyCACFLayerTreeHost::resize()
+{
+ if (!m_d3dDevice)
+ return;
+
+ // Resetting the device might fail here. But that's OK, because if it does it we will attempt to
+ // reset the device the next time we try to render.
+ resetDevice(ChangedWindowSize);
+
+ if (rootLayer()) {
+ rootLayer()->setBounds(bounds());
+ flushContext();
+ }
+}
+
+void LegacyCACFLayerTreeHost::renderTimerFired(Timer<LegacyCACFLayerTreeHost>*)
+{
+ paint();
+}
+
+void LegacyCACFLayerTreeHost::paint()
+{
+ createRenderer();
+ if (!m_d3dDevice) {
+ if (m_mightBeAbleToCreateDeviceLater)
+ renderSoon();
+ return;
+ }
+
+ CACFLayerTreeHost::paint();
+}
+
+void LegacyCACFLayerTreeHost::render(const Vector<CGRect>& windowDirtyRects)
+{
+ ASSERT(m_d3dDevice);
+
+ if (m_mustResetLostDeviceBeforeRendering && !resetDevice(LostDevice)) {
+ // We can't reset the device right now. Try again soon.
+ renderSoon();
+ return;
+ }
+
+ CGRect bounds = this->bounds();
+
+ // Give the renderer some space to use. This needs to be valid until the
+ // wkCACFContextFinishUpdate() call below.
+ char space[4096];
+ if (!wkCACFContextBeginUpdate(m_context, space, sizeof(space), CACurrentMediaTime(), bounds, windowDirtyRects.data(), windowDirtyRects.size()))
+ return;
+
+ HRESULT err = S_OK;
+ CFTimeInterval timeToNextRender = numeric_limits<CFTimeInterval>::infinity();
+
+ do {
+ // FIXME: don't need to clear dirty region if layer tree is opaque.
+
+ WKCACFUpdateRectEnumerator* e = wkCACFContextCopyUpdateRectEnumerator(m_context);
+ if (!e)
+ break;
+
+ Vector<D3DRECT, 64> rects;
+ for (const CGRect* r = wkCACFUpdateRectEnumeratorNextRect(e); r; r = wkCACFUpdateRectEnumeratorNextRect(e)) {
+ D3DRECT rect;
+ rect.x1 = r->origin.x;
+ rect.x2 = rect.x1 + r->size.width;
+ rect.y1 = bounds.origin.y + bounds.size.height - (r->origin.y + r->size.height);
+ rect.y2 = rect.y1 + r->size.height;
+
+ rects.append(rect);
+ }
+ wkCACFUpdateRectEnumeratorRelease(e);
+
+ timeToNextRender = wkCACFContextGetNextUpdateTime(m_context);
+
+ if (rects.isEmpty())
+ break;
+
+ m_d3dDevice->Clear(rects.size(), rects.data(), D3DCLEAR_TARGET, 0, 1.0f, 0);
+
+ m_d3dDevice->BeginScene();
+ wkCACFContextRenderUpdate(m_context);
+ m_d3dDevice->EndScene();
+
+ err = m_d3dDevice->Present(0, 0, 0, 0);
+
+ if (err == D3DERR_DEVICELOST) {
+ wkCACFContextAddUpdateRect(m_context, bounds);
+ if (!resetDevice(LostDevice)) {
+ // We can't reset the device right now. Try again soon.
+ renderSoon();
+ return;
+ }
+ }
+ } while (err == D3DERR_DEVICELOST);
+
+ wkCACFContextFinishUpdate(m_context);
+
+#ifndef NDEBUG
+ if (m_printTree)
+ rootLayer()->printTree();
+#endif
+
+ // If timeToNextRender is not infinity, it means animations are running, so queue up to render again
+ if (timeToNextRender != numeric_limits<CFTimeInterval>::infinity())
+ renderSoon();
+}
+
+void LegacyCACFLayerTreeHost::renderSoon()
+{
+ if (!m_renderTimer.isActive())
+ m_renderTimer.startOneShot(0);
+}
+
+void LegacyCACFLayerTreeHost::flushContext()
+{
+ wkCACFContextFlush(m_context);
+ contextDidChange();
+}
+
+void LegacyCACFLayerTreeHost::contextDidChange()
+{
+ renderSoon();
+ CACFLayerTreeHost::contextDidChange();
+}
+
+CFTimeInterval LegacyCACFLayerTreeHost::lastCommitTime() const
+{
+ return wkCACFContextGetLastCommitTime(m_context);
+}
+
+void LegacyCACFLayerTreeHost::initD3DGeometry()
+{
+ ASSERT(m_d3dDevice);
+
+ CGRect bounds = this->bounds();
+
+ float x0 = bounds.origin.x;
+ float y0 = bounds.origin.y;
+ float x1 = x0 + bounds.size.width;
+ float y1 = y0 + bounds.size.height;
+
+ D3DXMATRIXA16 projection;
+ D3DXMatrixOrthoOffCenterRH(&projection, x0, x1, y0, y1, -1.0f, 1.0f);
+
+ m_d3dDevice->SetTransform(D3DTS_PROJECTION, &projection);
+}
+
+bool LegacyCACFLayerTreeHost::resetDevice(ResetReason reason)
+{
+ ASSERT(m_d3dDevice);
+ ASSERT(m_context);
+
+ HRESULT hr = m_d3dDevice->TestCooperativeLevel();
+
+ if (hr == D3DERR_DEVICELOST || hr == D3DERR_DRIVERINTERNALERROR) {
+ // The device cannot be reset at this time. Try again soon.
+ m_mustResetLostDeviceBeforeRendering = true;
+ return false;
+ }
+
+ m_mustResetLostDeviceBeforeRendering = false;
+
+ if (reason == LostDevice && hr == D3D_OK) {
+ // The device wasn't lost after all.
+ return true;
+ }
+
+ // We can reset the device.
+
+ // We have to release the context's D3D resrouces whenever we reset the IDirect3DDevice9 in order to
+ // destroy any D3DPOOL_DEFAULT resources that Core Animation has allocated (e.g., textures used
+ // for mask layers). See <http://msdn.microsoft.com/en-us/library/bb174425(v=VS.85).aspx>.
+ wkCACFContextReleaseD3DResources(m_context);
+
+ D3DPRESENT_PARAMETERS parameters = initialPresentationParameters();
+ hr = m_d3dDevice->Reset(&parameters);
+
+ // TestCooperativeLevel told us the device may be reset now, so we should
+ // not be told here that the device is lost.
+ ASSERT(hr != D3DERR_DEVICELOST);
+
+ initD3DGeometry();
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.h b/Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.h
new file mode 100644
index 0000000..bfa530b
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ca/win/LegacyCACFLayerTreeHost.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LegacyCACFLayerTreeHost_h
+#define LegacyCACFLayerTreeHost_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "CACFLayerTreeHost.h"
+
+namespace WebCore {
+
+// FIXME: Currently there is a LegacyCACFLayerTreeHost for each WebView and each
+// has its own WKCACFContext and Direct3DDevice9, which is inefficient.
+// (https://bugs.webkit.org/show_bug.cgi?id=31855)
+class LegacyCACFLayerTreeHost : public CACFLayerTreeHost {
+public:
+ static PassRefPtr<LegacyCACFLayerTreeHost> create();
+ virtual ~LegacyCACFLayerTreeHost();
+
+private:
+ LegacyCACFLayerTreeHost();
+
+ void initD3DGeometry();
+
+ // Call this when the device window has changed size or when IDirect3DDevice9::Present returns
+ // D3DERR_DEVICELOST. Returns true if the device was recovered, false if rendering must be
+ // aborted and reattempted soon.
+ enum ResetReason { ChangedWindowSize, LostDevice };
+ bool resetDevice(ResetReason);
+
+ void renderSoon();
+ void renderTimerFired(Timer<LegacyCACFLayerTreeHost>*);
+
+ virtual void initializeContext(void* userData, PlatformCALayer*);
+ virtual void resize();
+ virtual bool createRenderer();
+ virtual void destroyRenderer();
+ virtual CFTimeInterval lastCommitTime() const;
+ virtual void flushContext();
+ virtual void contextDidChange();
+ virtual void paint();
+ virtual void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
+
+ Timer<LegacyCACFLayerTreeHost> m_renderTimer;
+ COMPtr<IDirect3DDevice9> m_d3dDevice;
+ WKCACFContext* m_context;
+ bool m_mightBeAbleToCreateDeviceLater;
+ bool m_mustResetLostDeviceBeforeRendering;
+
+#ifndef NDEBUG
+ bool m_printTree;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // LegacyCACFLayerTreeHost_h
diff --git a/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp b/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp
index 228bb01..6e3011b 100644
--- a/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp
+++ b/Source/WebCore/platform/graphics/ca/win/PlatformCAAnimationWin.cpp
@@ -145,11 +145,6 @@ PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::create(PlatformAnimationRef
return adoptRef(new PlatformCAAnimation(animation));
}
-PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::create(const PlatformCAAnimation* animation)
-{
- return adoptRef(new PlatformCAAnimation(animation));
-}
-
PlatformCAAnimation::PlatformCAAnimation(AnimationType type, const String& keyPath)
: m_type(type)
{
@@ -176,33 +171,33 @@ PlatformCAAnimation::PlatformCAAnimation(PlatformAnimationRef animation)
m_animation = animation;
}
-PlatformCAAnimation::PlatformCAAnimation(const PlatformCAAnimation* animation)
+PassRefPtr<PlatformCAAnimation> PlatformCAAnimation::copy() const
{
- m_animation.adoptCF(CACFAnimationCreate((animation->animationType() == Basic) ? kCACFBasicAnimation : kCACFKeyframeAnimation));
- RetainPtr<CFStringRef> keyPath(AdoptCF, animation->keyPath().createCFString());
- CACFAnimationSetKeyPath(m_animation.get(), keyPath.get());
-
- setBeginTime(animation->beginTime());
- setDuration(animation->duration());
- setSpeed(animation->speed());
- setTimeOffset(animation->timeOffset());
- setRepeatCount(animation->repeatCount());
- setAutoreverses(animation->autoreverses());
- setFillMode(animation->fillMode());
- setRemovedOnCompletion(animation->isRemovedOnCompletion());
- setAdditive(animation->isAdditive());
- copyTimingFunctionFrom(animation);
- setValueFunction(animation->valueFunction());
-
+ RefPtr<PlatformCAAnimation> animation = create(animationType(), keyPath());
+
+ animation->setBeginTime(beginTime());
+ animation->setDuration(duration());
+ animation->setSpeed(speed());
+ animation->setTimeOffset(timeOffset());
+ animation->setRepeatCount(repeatCount());
+ animation->setAutoreverses(autoreverses());
+ animation->setFillMode(fillMode());
+ animation->setRemovedOnCompletion(isRemovedOnCompletion());
+ animation->setAdditive(isAdditive());
+ animation->copyTimingFunctionFrom(this);
+ animation->setValueFunction(valueFunction());
+
// Copy the specific Basic or Keyframe values
- if (animation->animationType() == Keyframe) {
- copyValuesFrom(animation);
- copyKeyTimesFrom(animation);
- copyTimingFunctionsFrom(animation);
+ if (animationType() == Keyframe) {
+ animation->copyValuesFrom(this);
+ animation->copyKeyTimesFrom(this);
+ animation->copyTimingFunctionsFrom(this);
} else {
- copyFromValueFrom(animation);
- copyToValueFrom(animation);
+ animation->copyFromValueFrom(this);
+ animation->copyToValueFrom(this);
}
+
+ return animation;
}
PlatformCAAnimation::~PlatformCAAnimation()
diff --git a/Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.cpp b/Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.cpp
new file mode 100644
index 0000000..e672c2d
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.cpp
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WKCACFViewLayerTreeHost.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "PlatformCALayer.h"
+#include "SoftLinking.h"
+#include <wtf/CurrentTime.h>
+
+typedef struct _CACFLayer* CACFLayerRef;
+
+namespace WebCore {
+
+#ifdef DEBUG_ALL
+SOFT_LINK_DEBUG_LIBRARY(WebKitQuartzCoreAdditions)
+#else
+SOFT_LINK_LIBRARY(WebKitQuartzCoreAdditions)
+#endif
+
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewCreate, WKCACFViewRef, __cdecl, (), ())
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewSetLayer, void, __cdecl, (WKCACFViewRef view, CACFLayerRef layer), (view, layer))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewUpdate, void, __cdecl, (WKCACFViewRef view, HWND window, const CGRect* bounds), (view, window, bounds))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewCanDraw, bool, __cdecl, (WKCACFViewRef view), (view))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewDraw, void, __cdecl, (WKCACFViewRef view), (view))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewFlushContext, void, __cdecl, (WKCACFViewRef view), (view))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewInvalidateRects, void, __cdecl, (WKCACFViewRef view, const CGRect rects[], size_t count), (view, rects, count))
+typedef void (*WKCACFViewContextDidChangeCallback)(WKCACFViewRef view, void* info);
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewSetContextDidChangeCallback, void, __cdecl, (WKCACFViewRef view, WKCACFViewContextDidChangeCallback callback, void* info), (view, callback, info))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewGetLastCommitTime, CFTimeInterval, __cdecl, (WKCACFViewRef view), (view))
+SOFT_LINK(WebKitQuartzCoreAdditions, WKCACFViewSetContextUserData, void, __cdecl, (WKCACFViewRef view, void* userData), (view, userData))
+
+PassRefPtr<WKCACFViewLayerTreeHost> WKCACFViewLayerTreeHost::create()
+{
+ if (!WebKitQuartzCoreAdditionsLibrary())
+ return 0;
+
+ return adoptRef(new WKCACFViewLayerTreeHost);
+}
+
+WKCACFViewLayerTreeHost::WKCACFViewLayerTreeHost()
+ : m_view(AdoptCF, WKCACFViewCreate())
+ , m_viewNeedsUpdate(true)
+{
+}
+
+void WKCACFViewLayerTreeHost::updateViewIfNeeded()
+{
+ if (!m_viewNeedsUpdate)
+ return;
+ m_viewNeedsUpdate = false;
+
+ CGRect layerBounds = rootLayer()->bounds();
+
+ CGRect bounds = this->bounds();
+ WKCACFViewUpdate(m_view.get(), window(), &bounds);
+
+ if (CGRectEqualToRect(layerBounds, rootLayer()->bounds()))
+ return;
+
+ // Flush the context so the layer's rendered bounds will match our bounds.
+ flushContext();
+}
+
+void WKCACFViewLayerTreeHost::contextDidChangeCallback(WKCACFViewRef view, void* info)
+{
+ ASSERT_ARG(view, view);
+ ASSERT_ARG(info, info);
+
+ WKCACFViewLayerTreeHost* host = static_cast<WKCACFViewLayerTreeHost*>(info);
+ ASSERT_ARG(view, view == host->m_view);
+ host->contextDidChange();
+}
+
+void WKCACFViewLayerTreeHost::contextDidChange()
+{
+ // Tell the WKCACFView to start rendering now that we have some contents to render.
+ updateViewIfNeeded();
+
+ CACFLayerTreeHost::contextDidChange();
+}
+
+void WKCACFViewLayerTreeHost::initializeContext(void* userData, PlatformCALayer* layer)
+{
+ WKCACFViewSetContextUserData(m_view.get(), userData);
+ WKCACFViewSetLayer(m_view.get(), layer->platformLayer());
+ WKCACFViewSetContextDidChangeCallback(m_view.get(), contextDidChangeCallback, this);
+}
+
+void WKCACFViewLayerTreeHost::resize()
+{
+ m_viewNeedsUpdate = true;
+}
+
+bool WKCACFViewLayerTreeHost::createRenderer()
+{
+ updateViewIfNeeded();
+ return WKCACFViewCanDraw(m_view.get());
+}
+
+void WKCACFViewLayerTreeHost::destroyRenderer()
+{
+ m_viewNeedsUpdate = true;
+ WKCACFViewUpdate(m_view.get(), 0, 0);
+ WKCACFViewSetContextUserData(m_view.get(), 0);
+ WKCACFViewSetLayer(m_view.get(), 0);
+ WKCACFViewSetContextDidChangeCallback(m_view.get(), 0, 0);
+
+ CACFLayerTreeHost::destroyRenderer();
+}
+
+CFTimeInterval WKCACFViewLayerTreeHost::lastCommitTime() const
+{
+ return WKCACFViewGetLastCommitTime(m_view.get());
+}
+
+void WKCACFViewLayerTreeHost::flushContext()
+{
+ WKCACFViewFlushContext(m_view.get());
+}
+
+void WKCACFViewLayerTreeHost::paint()
+{
+ updateViewIfNeeded();
+ CACFLayerTreeHost::paint();
+}
+
+void WKCACFViewLayerTreeHost::render(const Vector<CGRect>& dirtyRects)
+{
+ WKCACFViewInvalidateRects(m_view.get(), dirtyRects.data(), dirtyRects.size());
+ WKCACFViewDraw(m_view.get());
+}
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.h b/Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.h
new file mode 100644
index 0000000..af09f76
--- /dev/null
+++ b/Source/WebCore/platform/graphics/ca/win/WKCACFViewLayerTreeHost.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WKCACFViewLayerTreeHost_h
+#define WKCACFViewLayerTreeHost_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "CACFLayerTreeHost.h"
+
+typedef struct _WKCACFView* WKCACFViewRef;
+
+namespace WebCore {
+
+class WKCACFViewLayerTreeHost : public CACFLayerTreeHost {
+public:
+ static PassRefPtr<WKCACFViewLayerTreeHost> create();
+
+private:
+ WKCACFViewLayerTreeHost();
+
+ void updateViewIfNeeded();
+ static void contextDidChangeCallback(WKCACFViewRef, void* info);
+
+ virtual void initializeContext(void* userData, PlatformCALayer*);
+ virtual void resize();
+ virtual bool createRenderer();
+ virtual void destroyRenderer();
+ virtual void flushContext();
+ virtual void contextDidChange();
+ virtual void paint();
+ virtual void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>());
+ virtual CFTimeInterval lastCommitTime() const;
+
+ RetainPtr<WKCACFViewRef> m_view;
+ bool m_viewNeedsUpdate;
+};
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // WKCACFViewLayerTreeHost_h