Commit 9c57db95 authored by andersca@apple.com's avatar andersca@apple.com
Browse files

2011-01-18 Anders Carlsson <andersca@apple.com>

        Reviewed by Darin Adler.

        Use a CGLayer for the backing store when possible
        https://bugs.webkit.org/show_bug.cgi?id=52679

        * UIProcess/mac/BackingStoreMac.mm:
        (WebKit::BackingStore::paint):
        If there is a layer, paint it into the given context.

        (WebKit::BackingStore::backingStoreContext):
        If we can get the containing window graphics context, use it to create a 
        CGLayer that we'll use for the backing store.

        (WebKit::BackingStore::scroll):
        Paint the layer into itself.

        * UIProcess/mac/WebPageProxyMac.mm:
        (WebKit::WebPageProxy::containingWindowGraphicsContext):
        Call the page client.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76080 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 584609ca
2011-01-18 Anders Carlsson <andersca@apple.com>
Reviewed by Darin Adler.
Use a CGLayer for the backing store when possible
https://bugs.webkit.org/show_bug.cgi?id=52679
* UIProcess/mac/BackingStoreMac.mm:
(WebKit::BackingStore::paint):
If there is a layer, paint it into the given context.
(WebKit::BackingStore::backingStoreContext):
If we can get the containing window graphics context, use it to create a
CGLayer that we'll use for the backing store.
(WebKit::BackingStore::scroll):
Paint the layer into itself.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::containingWindowGraphicsContext):
Call the page client.
2011-01-18 Anders Carlsson <andersca@apple.com>
 
Reviewed by Dan Bernstein.
......@@ -28,6 +28,7 @@
#include "CGUtilities.h"
#include "ShareableBitmap.h"
#include "UpdateInfo.h"
#include "WebPageProxy.h"
#include <WebCore/GraphicsContext.h>
using namespace WebCore;
......@@ -36,13 +37,46 @@ namespace WebKit {
void BackingStore::paint(PlatformGraphicsContext context, const IntRect& rect)
{
ASSERT(m_bitmapContext);
if (m_cgLayer) {
CGContextSaveGState(context);
CGContextClipToRect(context, rect);
CGContextScaleCTM(context, 1, -1);
CGContextDrawLayerAtPoint(context, CGPointMake(0, -m_size.height()), m_cgLayer.get());
CGContextRestoreGState(context);
return;
}
ASSERT(m_bitmapContext);
paintBitmapContext(context, m_bitmapContext.get(), rect.location(), rect);
}
CGContextRef BackingStore::backingStoreContext()
{
if (m_cgLayer)
return CGLayerGetContext(m_cgLayer.get());
// Try to create a layer.
if (CGContextRef containingWindowContext = m_webPageProxy->containingWindowGraphicsContext()) {
m_cgLayer.adoptCF(CGLayerCreateWithContext(containingWindowContext, NSSizeToCGSize(m_size), 0));
CGContextRef layerContext = CGLayerGetContext(m_cgLayer.get());
CGContextSetBlendMode(layerContext, kCGBlendModeCopy);
// We want the origin to be in the top left corner so flip the backing store context.
CGContextTranslateCTM(layerContext, 0, m_size.height());
CGContextScaleCTM(layerContext, 1, -1);
if (m_bitmapContext) {
// Paint the contents of the bitmap into the layer context.
paintBitmapContext(layerContext, m_bitmapContext.get(), CGPointZero, CGRectMake(0, 0, m_size.width(), m_size.height()));
m_bitmapContext = nullptr;
}
return layerContext;
}
if (!m_bitmapContext) {
RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
......@@ -89,15 +123,25 @@ void BackingStore::scroll(const IntRect& scrollRect, const IntSize& scrollOffset
if (scrollOffset.isZero())
return;
if (m_cgLayer) {
CGContextRef layerContext = CGLayerGetContext(m_cgLayer.get());
// Scroll the layer by painting it into itself with the given offset.
CGContextSaveGState(layerContext);
CGContextClipToRect(layerContext, scrollRect);
CGContextScaleCTM(layerContext, 1, -1);
CGContextDrawLayerAtPoint(layerContext, CGPointMake(scrollOffset.width(), -m_size.height() - scrollOffset.height()), m_cgLayer.get());
CGContextRestoreGState(layerContext);
return;
}
ASSERT(m_bitmapContext);
CGContextSaveGState(m_bitmapContext.get());
CGContextClipToRect(m_bitmapContext.get(), scrollRect);
CGPoint destination = CGPointMake(scrollRect.x() + scrollOffset.width(), scrollRect.y() + scrollOffset.height());
paintBitmapContext(m_bitmapContext.get(), m_bitmapContext.get(), destination, scrollRect);
CGContextRestoreGState(m_bitmapContext.get());
}
......
......@@ -25,6 +25,7 @@
#include "WebPageProxy.h"
#include "PageClient.h"
#include <WebCore/Language.h>
#include <wtf/text/StringConcatenate.h>
......@@ -110,4 +111,9 @@ void WebPageProxy::stopSpeaking()
[NSApp stopSpeaking:nil];
}
CGContextRef WebPageProxy::containingWindowGraphicsContext()
{
return m_pageClient->containingWindowGraphicsContext();
}
} // namespace WebKit
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment