Changeset 82960 in webkit
- Timestamp:
- Apr 5, 2011 11:01:52 AM (13 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r82959 r82960 1 2011-04-05 Adam Roben <aroben@apple.com> 2 3 Make accelerated compositing work in WebKit2 on Windows 4 5 LayerTreeHostCAWin uses WKCACFView to render each frame to an image, then has 6 DrawingAreaImpl send that image over to the UI process (just like it does for 7 non-accelerated rendering). It's unfortunate that this requires reading every frame back 8 from the GPU into system memory. More efficient solutions can be explored in the future. 9 10 Fixes <http://webkit.org/b/45567>. 11 12 Reviewed by Anders Carlsson. 13 14 * DerivedSources.make: Added $(WebKit2) to the VPATH so that DerivedSources.make can be 15 found when used as a target dependency. Added rules to generate a HeaderDetection.h file on 16 Windows. If we can find WebKitQuartzCoreAdditions headers, we define HAVE_WKQCA in 17 HeaderDetection.h. 18 19 * WebProcess/WebPage/DrawingAreaImpl.cpp: 20 (WebKit::DrawingAreaImpl::setLayerHostNeedsDisplay): 21 * WebProcess/WebPage/DrawingAreaImpl.h: 22 Added setLayerHostNeedsDisplay. Lets the layer host tell the DrawingAreaImpl that it has a 23 new frame to render. This should only be called by layer hosts that participate in 24 DrawingAreaImpl's display mechanism. 25 26 * WebProcess/WebPage/LayerTreeHost.cpp: 27 (WebKit::LayerTreeHost::create): Only try to instantiate LayerTreeHostCAWin if we have 28 WebKitQuartzCoreAdditions, since it depends on that library. 29 30 * WebProcess/WebPage/WebPage.cpp: 31 (WebKit::WebPage::updatePreferences): Removed code that forced accelerated compositing to be 32 disabled on Windows. 33 34 * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp: 35 (WebKit::registerDummyWindowClass): Registers the window class we use for the dummy window. 36 (WebKit::createDummyWindow): Creates the dummy window we pass to WKCACFView so that D3D can 37 determine the display mode, etc. (The window is never shown on screen.) 38 (WebKit::LayerTreeHostCAWin::LayerTreeHostCAWin): Initialize new members. 39 (WebKit::LayerTreeHostCAWin::platformInitialize): Create our dummy window and view and 40 associate the two. We set ourselves as the view's context's user data so that 41 PlatformCALayer can get our AbstractCACFLayerTreeHost pointer as needed. 42 (WebKit::LayerTreeHostCAWin::invalidate): Cancel any pending flushes, tear down our view, 43 and destroy the dummy window if no other layer host is using it. 44 (WebKit::LayerTreeHostCAWin::scheduleLayerFlush): Ask LayerChangesFlusher to call us back 45 soon to perform the flush. 46 (WebKit::LayerTreeHostCAWin::participatesInDisplay): Added. Returns true, since we render 47 each frame to an image. 48 (WebKit::LayerTreeHostCAWin::needsDisplay): Added. Returns true if it's now time to 49 displayReturns true if it's now time to display. 50 (WebKit::LayerTreeHostCAWin::timeUntilNextDisplay): Added. Returns how many seconds remain 51 before we need to display again. 52 (WebKit::size): Added. Helper function to get the size of a WKCACFImage. 53 (WebKit::toShareableBitmap): Added. Helper function to convert a WKCACFImage to a 54 ShareableBitmap. 55 (WebKit::LayerTreeHostCAWin::display): Added. Renders the next frame to an image and stuffs 56 the image into the UpdateInfo struct. 57 (WebKit::LayerTreeHostCAWin::sizeDidChange): Added. Tells the view about the new size. 58 (WebKit::LayerTreeHostCAWin::forceRepaint): Added. Flushes any pending changes to the view. 59 (WebKit::LayerTreeHostCAWin::contextDidChangeCallback): Added. WKCACFView calls this 60 whenever any changes made to the view or its layer tree have been flushed. Just calls 61 through to contextDidChange. 62 (WebKit::LayerTreeHostCAWin::contextDidChange): Added. Tells layers that they've started 63 animating, and tells the DrawingAreaImpl that we need to display again. 64 (WebKit::LayerTreeHostCAWin::rootLayer): Added. Gets the root layer's PlatformCALayer. 65 (WebKit::LayerTreeHostCAWin::addPendingAnimatedLayer): Added. Stores the layer so that we 66 can tell it animations have started the next time we get a contextDidChange callback. 67 (WebKit::LayerTreeHostCAWin::layerTreeDidChange): Added. Schedules a flush, unless we're 68 already in the process of flushing. This code came from WebCore::WKCACFViewLayerTreeHost. 69 (WebKit::LayerTreeHostCAWin::flushPendingLayerChangesNow): Added. Performs the flush. This 70 code was adapted from WebCore::WKCACFViewLayerTreeHost. 71 72 * WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h: Wrapped this whole header in HAVE(WKQCA), 73 since this class only works when WebKitQuartzCoreAdditions is available. Added a bunch of 74 new members. 75 1 76 2011-04-04 Adam Roben <aroben@apple.com> 2 77 -
trunk/Source/WebKit2/DerivedSources.make
r81788 r82960 22 22 23 23 VPATH = \ 24 $(WebKit2) \ 24 25 $(WebKit2)/PluginProcess \ 25 26 $(WebKit2)/Shared/Plugins \ … … 101 102 @echo Generating message receiver for $*... 102 103 @python $(WebKit2)/Scripts/generate-messages-header.py $< > $@ 104 105 # ------------------------ 106 107 # Windows-specific rules 108 109 ifeq ($(OS),Windows_NT) 110 111 all : HeaderDetection.h 112 113 HeaderDetection.h : DerivedSources.make 114 if [ -f "$(WEBKITLIBRARIESDIR)/include/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsBase.h" ]; then echo "#define HAVE_WKQCA 1" > $@; else echo > $@; fi 115 116 endif # Windows_NT -
trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp
r82959 r82960 193 193 } 194 194 195 void DrawingAreaImpl::setLayerHostNeedsDisplay() 196 { 197 ASSERT(m_layerTreeHost); 198 ASSERT(m_layerTreeHost->participatesInDisplay()); 199 scheduleDisplay(); 200 } 201 195 202 void DrawingAreaImpl::layerHostDidFlushLayers() 196 203 { -
trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h
r80917 r82960 41 41 virtual ~DrawingAreaImpl(); 42 42 43 void setLayerHostNeedsDisplay(); 43 44 void layerHostDidFlushLayers(); 44 45 -
trunk/Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp
r82677 r82960 45 45 PassRefPtr<LayerTreeHost> LayerTreeHost::create(WebPage* webPage) 46 46 { 47 #if PLATFORM(CA)48 47 #if PLATFORM(MAC) 49 48 return LayerTreeHostCAMac::create(webPage); 50 #elif PLATFORM(WIN) 49 #elif PLATFORM(WIN) && HAVE(WKQCA) 51 50 return LayerTreeHostCAWin::create(webPage); 52 #endif53 51 #else 54 52 return 0; -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r82929 r82960 1412 1412 settings->setDefaultFixedFontSize(store.getUInt32ValueForKey(WebPreferencesKey::defaultFixedFontSizeKey())); 1413 1413 1414 #if PLATFORM(WIN)1415 // Temporarily turn off accelerated compositing until we have a good solution for rendering it.1416 settings->setAcceleratedCompositingEnabled(false);1417 settings->setAcceleratedDrawingEnabled(false);1418 settings->setCanvasUsesAcceleratedDrawing(false);1419 #else1420 1414 settings->setAcceleratedCompositingEnabled(store.getBoolValueForKey(WebPreferencesKey::acceleratedCompositingEnabledKey())); 1421 1415 settings->setAcceleratedDrawingEnabled(store.getBoolValueForKey(WebPreferencesKey::acceleratedDrawingEnabledKey())); 1422 1416 settings->setCanvasUsesAcceleratedDrawing(store.getBoolValueForKey(WebPreferencesKey::canvasUsesAcceleratedDrawingKey())); 1423 #endif1424 1417 settings->setShowDebugBorders(store.getBoolValueForKey(WebPreferencesKey::compositingBordersVisibleKey())); 1425 1418 settings->setShowRepaintCounter(store.getBoolValueForKey(WebPreferencesKey::compositingRepaintCountersVisibleKey())); -
trunk/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp
r82675 r82960 27 27 #include "LayerTreeHostCAWin.h" 28 28 29 #include <WebCore/NotImplemented.h> 30 #include <wtf/RefPtr.h> 29 #if HAVE(WKQCA) 30 31 #include "DrawingAreaImpl.h" 32 #include "ShareableBitmap.h" 33 #include "UpdateInfo.h" 34 #include "WebPage.h" 35 #include <WebCore/GraphicsLayerCA.h> 36 #include <WebCore/LayerChangesFlusher.h> 37 #include <WebCore/PlatformCALayer.h> 38 #include <WebCore/WebCoreInstanceHandle.h> 39 #include <WebKitQuartzCoreAdditions/WKCACFImage.h> 40 #include <WebKitQuartzCoreAdditions/WKCACFView.h> 41 #include <wtf/CurrentTime.h> 42 43 #ifdef DEBUG_ALL 44 #pragma comment(lib, "WebKitQuartzCoreAdditions_debug") 45 #else 46 #pragma comment(lib, "WebKitQuartzCoreAdditions") 47 #endif 48 49 using namespace WebCore; 31 50 32 51 namespace WebKit { 52 53 static HWND dummyWindow; 54 static LPCWSTR dummyWindowClass = L"LayerTreeHostCAWindowClass"; 55 static size_t validLayerTreeHostCount; 56 57 static void registerDummyWindowClass() 58 { 59 static bool didRegister; 60 if (didRegister) 61 return; 62 didRegister = true; 63 64 WNDCLASSW wndClass = {0}; 65 wndClass.lpszClassName = dummyWindowClass; 66 wndClass.lpfnWndProc = ::DefWindowProcW; 67 wndClass.hInstance = instanceHandle(); 68 69 ::RegisterClassW(&wndClass); 70 } 71 72 // This window is never shown. It is only needed so that D3D can determine the display mode, etc. 73 static HWND createDummyWindow() 74 { 75 registerDummyWindowClass(); 76 return ::CreateWindowW(dummyWindowClass, 0, WS_POPUP, 0, 0, 10, 10, 0, 0, instanceHandle(), 0); 77 } 33 78 34 79 PassRefPtr<LayerTreeHostCAWin> LayerTreeHostCAWin::create(WebPage* webPage) … … 41 86 LayerTreeHostCAWin::LayerTreeHostCAWin(WebPage* webPage) 42 87 : LayerTreeHostCA(webPage) 88 , m_isFlushingLayerChanges(false) 89 , m_nextDisplayTime(0) 43 90 { 44 91 } … … 50 97 void LayerTreeHostCAWin::platformInitialize(LayerTreeContext&) 51 98 { 52 // FIXME: <http://webkit.org/b/45567> Implement this! 53 notImplemented(); 99 ++validLayerTreeHostCount; 100 if (!dummyWindow) 101 dummyWindow = createDummyWindow(); 102 103 m_view.adoptCF(WKCACFViewCreate(kWKCACFViewDrawingDestinationImage)); 104 WKCACFViewSetContextUserData(m_view.get(), static_cast<AbstractCACFLayerTreeHost*>(this)); 105 WKCACFViewSetLayer(m_view.get(), rootLayer()->platformLayer()); 106 WKCACFViewSetContextDidChangeCallback(m_view.get(), contextDidChangeCallback, this); 107 108 CGRect bounds = m_webPage->bounds(); 109 WKCACFViewUpdate(m_view.get(), dummyWindow, &bounds); 110 } 111 112 void LayerTreeHostCAWin::invalidate() 113 { 114 LayerChangesFlusher::shared().cancelPendingFlush(this); 115 116 WKCACFViewUpdate(m_view.get(), 0, 0); 117 WKCACFViewSetContextUserData(m_view.get(), 0); 118 WKCACFViewSetLayer(m_view.get(), 0); 119 WKCACFViewSetContextDidChangeCallback(m_view.get(), 0, 0); 120 121 LayerTreeHostCA::invalidate(); 122 123 if (--validLayerTreeHostCount) 124 return; 125 ::DestroyWindow(dummyWindow); 126 dummyWindow = 0; 54 127 } 55 128 56 129 void LayerTreeHostCAWin::scheduleLayerFlush() 57 130 { 58 // FIXME: <http://webkit.org/b/45567> Implement this! 59 notImplemented(); 131 LayerChangesFlusher::shared().flushPendingLayerChangesSoon(this); 132 } 133 134 bool LayerTreeHostCAWin::participatesInDisplay() 135 { 136 return true; 137 } 138 139 bool LayerTreeHostCAWin::needsDisplay() 140 { 141 return timeUntilNextDisplay() <= 0; 142 } 143 144 double LayerTreeHostCAWin::timeUntilNextDisplay() 145 { 146 return m_nextDisplayTime - currentTime(); 147 } 148 149 static IntSize size(WKCACFImageRef image) 150 { 151 return IntSize(WKCACFImageGetWidth(image), WKCACFImageGetHeight(image)); 152 } 153 154 static PassRefPtr<ShareableBitmap> toShareableBitmap(WKCACFImageRef image) 155 { 156 size_t fileMappingSize; 157 HANDLE mapping = WKCACFImageCopyFileMapping(image, &fileMappingSize); 158 if (!mapping) 159 return 0; 160 161 RefPtr<SharedMemory> sharedMemory = SharedMemory::adopt(mapping, fileMappingSize, SharedMemory::ReadWrite); 162 if (!sharedMemory) { 163 ::CloseHandle(mapping); 164 return 0; 165 } 166 167 // WKCACFImage never has an alpha channel. 168 return ShareableBitmap::create(size(image), 0, sharedMemory.release()); 169 } 170 171 void LayerTreeHostCAWin::display(UpdateInfo& updateInfo) 172 { 173 CGPoint imageOrigin; 174 CFTimeInterval nextDrawTime; 175 RetainPtr<WKCACFImageRef> image(AdoptCF, WKCACFViewCopyDrawnImage(m_view.get(), &imageOrigin, &nextDrawTime)); 176 m_nextDisplayTime = nextDrawTime - CACurrentMediaTime() + currentTime(); 177 if (!image) 178 return; 179 RefPtr<ShareableBitmap> bitmap = toShareableBitmap(image.get()); 180 if (!bitmap) 181 return; 182 if (!bitmap->createHandle(updateInfo.bitmapHandle)) 183 return; 184 updateInfo.updateRectBounds = IntRect(IntPoint(imageOrigin.x, m_webPage->size().height() - imageOrigin.y - bitmap->size().height()), bitmap->size()); 185 updateInfo.updateRects.append(updateInfo.updateRectBounds); 186 } 187 188 void LayerTreeHostCAWin::sizeDidChange(const IntSize& newSize) 189 { 190 LayerTreeHostCA::sizeDidChange(newSize); 191 CGRect bounds = CGRectMake(0, 0, newSize.width(), newSize.height()); 192 WKCACFViewUpdate(m_view.get(), dummyWindow, &bounds); 193 WKCACFViewFlushContext(m_view.get()); 194 } 195 196 void LayerTreeHostCAWin::forceRepaint() 197 { 198 LayerTreeHostCA::forceRepaint(); 199 WKCACFViewFlushContext(m_view.get()); 200 } 201 202 void LayerTreeHostCAWin::contextDidChangeCallback(WKCACFViewRef view, void* info) 203 { 204 LayerTreeHostCAWin* host = static_cast<LayerTreeHostCAWin*>(info); 205 ASSERT_ARG(view, view == host->m_view); 206 host->contextDidChange(); 207 } 208 209 void LayerTreeHostCAWin::contextDidChange() 210 { 211 // Send currentTime to the pending animations. This function is called by CACF in a callback 212 // which occurs after the drawInContext calls. So currentTime is very close to the time 213 // the animations actually start 214 double currentTime = WTF::currentTime(); 215 216 HashSet<RefPtr<PlatformCALayer> >::iterator end = m_pendingAnimatedLayers.end(); 217 for (HashSet<RefPtr<PlatformCALayer> >::iterator it = m_pendingAnimatedLayers.begin(); it != end; ++it) 218 (*it)->animationStarted(currentTime); 219 220 m_pendingAnimatedLayers.clear(); 221 222 m_nextDisplayTime = 0; 223 static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->setLayerHostNeedsDisplay(); 224 } 225 226 PlatformCALayer* LayerTreeHostCAWin::rootLayer() const 227 { 228 return static_cast<GraphicsLayerCA*>(LayerTreeHostCA::rootLayer())->platformCALayer(); 229 } 230 231 void LayerTreeHostCAWin::addPendingAnimatedLayer(PassRefPtr<PlatformCALayer> layer) 232 { 233 m_pendingAnimatedLayers.add(layer); 234 } 235 236 void LayerTreeHostCAWin::layerTreeDidChange() 237 { 238 if (m_isFlushingLayerChanges) { 239 // The layer tree is changing as a result of flushing GraphicsLayer changes to their 240 // underlying PlatformCALayers. We'll flush those changes to the context as part of that 241 // process, so there's no need to schedule another flush here. 242 return; 243 } 244 245 // The layer tree is changing as a result of someone modifying a PlatformCALayer that doesn't 246 // have a corresponding GraphicsLayer. Schedule a flush since we won't schedule one through the 247 // normal GraphicsLayer mechanisms. 248 LayerChangesFlusher::shared().flushPendingLayerChangesSoon(this); 249 } 250 251 void LayerTreeHostCAWin::flushPendingLayerChangesNow() 252 { 253 RefPtr<LayerTreeHostCA> protector(this); 254 255 m_isFlushingLayerChanges = true; 256 257 // Flush changes stored up in GraphicsLayers to their underlying PlatformCALayers, if 258 // requested. 259 performScheduledLayerFlush(); 260 261 // Flush changes stored up in PlatformCALayers to the context so they will be rendered. 262 WKCACFViewFlushContext(m_view.get()); 263 264 m_isFlushingLayerChanges = false; 60 265 } 61 266 62 267 } // namespace WebKit 268 269 #endif // HAVE(WKQCA) -
trunk/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.h
r82675 r82960 27 27 #define LayerTreeHostCAWin_h 28 28 29 #include "HeaderDetection.h" 30 31 #if HAVE(WKQCA) 32 29 33 #include "LayerTreeHostCA.h" 34 #include <WebCore/AbstractCACFLayerTreeHost.h> 35 #include <wtf/HashSet.h> 36 #include <wtf/RetainPtr.h> 37 38 typedef struct _WKCACFView* WKCACFViewRef; 30 39 31 40 namespace WebKit { 32 41 33 class LayerTreeHostCAWin : public LayerTreeHostCA {42 class LayerTreeHostCAWin : public LayerTreeHostCA, private WebCore::AbstractCACFLayerTreeHost { 34 43 public: 35 44 static PassRefPtr<LayerTreeHostCAWin> create(WebPage*); … … 39 48 explicit LayerTreeHostCAWin(WebPage*); 40 49 50 static void contextDidChangeCallback(WKCACFViewRef, void* info); 51 void contextDidChange(); 52 41 53 // LayerTreeHost 54 virtual void invalidate(); 55 virtual void forceRepaint(); 56 virtual void sizeDidChange(const WebCore::IntSize& newSize); 42 57 virtual void scheduleLayerFlush(); 58 virtual bool participatesInDisplay(); 59 virtual bool needsDisplay(); 60 virtual double timeUntilNextDisplay(); 61 virtual void display(UpdateInfo&); 43 62 44 63 // LayerTreeHostCA 45 64 virtual void platformInitialize(LayerTreeContext&); 65 66 // AbstractCACFLayerTreeHost 67 virtual WebCore::PlatformCALayer* rootLayer() const; 68 virtual void addPendingAnimatedLayer(PassRefPtr<WebCore::PlatformCALayer>); 69 virtual void layerTreeDidChange(); 70 virtual void flushPendingLayerChangesNow(); 71 72 RetainPtr<WKCACFViewRef> m_view; 73 HashSet<RefPtr<WebCore::PlatformCALayer> > m_pendingAnimatedLayers; 74 bool m_isFlushingLayerChanges; 75 double m_nextDisplayTime; 46 76 }; 47 77 48 78 } // namespace WebKit 49 79 80 #endif // HAVE(WKQCA) 81 50 82 #endif // LayerTreeHostCAWin_h
Note: See TracChangeset
for help on using the changeset viewer.