Commit bc449085 authored by wangxianzhu's avatar wangxianzhu Committed by Commit bot

Remove WebGraphicsContext/WebGraphicsContextImpl

We used it to pass GraphicsContext from PageOverlay to
PageOverlay::Delegete implementors. Pass GraphicsContext directly.

Skip cache in InspectorOverlay because view painted for the overlay
may conflict with the view's real painting.

BUG=536999
R=chrishtr@chromium.org
TBR=dpranke@chromium.org (remove an extra include from src/components/test_runner.cc)

Review URL: https://codereview.chromium.org/1412593003

Cr-Commit-Position: refs/heads/master@{#357148}
parent 899b90ef
......@@ -36,7 +36,6 @@
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebGraphicsContext.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
......
......@@ -51,10 +51,10 @@
#include "platform/ScriptForbiddenScope.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/paint/CullRect.h"
#include "platform/graphics/paint/DisplayItemCacheSkipper.h"
#include "public/platform/Platform.h"
#include "public/platform/WebData.h"
#include "web/PageOverlay.h"
#include "web/WebGraphicsContextImpl.h"
#include "web/WebInputEventConversion.h"
#include "web/WebLocalFrameImpl.h"
#include "web/WebViewImpl.h"
......@@ -109,12 +109,13 @@ public:
PageOverlay::Delegate::trace(visitor);
}
void paintPageOverlay(WebGraphicsContext* context, const WebSize& webViewSize) const override
void paintPageOverlay(const PageOverlay&, GraphicsContext& graphicsContext, const WebSize& webViewSize) const override
{
if (m_overlay->isEmpty())
return;
GraphicsContext& graphicsContext = toWebGraphicsContextImpl(context)->graphicsContext();
// Skip cache because the following paint may conflict with the view's real painting.
DisplayItemCacheSkipper cacheSkipper(graphicsContext);
FrameView* view = m_overlay->overlayMainFrame()->view();
ASSERT(!view->needsLayout());
view->paint(&graphicsContext, CullRect(IntRect(0, 0, view->width(), view->height())));
......
......@@ -38,7 +38,6 @@
#include "public/platform/WebLayer.h"
#include "public/web/WebViewClient.h"
#include "web/WebDevToolsAgentImpl.h"
#include "web/WebGraphicsContextImpl.h"
#include "web/WebViewImpl.h"
namespace blink {
......@@ -100,8 +99,7 @@ void PageOverlay::update()
void PageOverlay::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& gc, GraphicsLayerPaintingPhase phase, const IntRect* inClip) const
{
ASSERT(m_layer);
WebGraphicsContextImpl contextWrapper(gc, *this, DisplayItem::PageOverlay);
m_delegate->paintPageOverlay(&contextWrapper, expandedIntSize(m_layer->size()));
m_delegate->paintPageOverlay(*this, gc, expandedIntSize(m_layer->size()));
}
String PageOverlay::debugName(const GraphicsLayer*)
......
......@@ -41,7 +41,6 @@ namespace blink {
class GraphicsContext;
class WebPageOverlay;
class WebViewImpl;
class WebGraphicsContext;
// Manages a layer that is overlaid on a WebView's content.
// Clients can paint by implementing WebPageOverlay.
......@@ -55,7 +54,7 @@ public:
DEFINE_INLINE_VIRTUAL_TRACE() { }
// Paints page overlay contents.
virtual void paintPageOverlay(WebGraphicsContext*, const WebSize& webViewSize) const = 0;
virtual void paintPageOverlay(const PageOverlay&, GraphicsContext&, const WebSize& webViewSize) const = 0;
virtual ~Delegate() { }
};
......
......@@ -19,7 +19,6 @@
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "web/WebGraphicsContextImpl.h"
#include "web/WebLocalFrameImpl.h"
#include "web/WebViewImpl.h"
#include "web/tests/FrameTestHelpers.h"
......@@ -71,45 +70,20 @@ private:
FrameTestHelpers::WebViewHelper m_helper;
};
// PageOverlay that uses a WebCanvas to draw a solid color.
class SimpleCanvasOverlay : public PageOverlay::Delegate {
// PageOverlay that paints a solid color.
class SolidColorOverlay : public PageOverlay::Delegate {
public:
SimpleCanvasOverlay(SkColor color) : m_color(color) { }
SolidColorOverlay(Color color) : m_color(color) { }
void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) const override
void paintPageOverlay(const PageOverlay& pageOverlay, GraphicsContext& graphicsContext, const WebSize& size) const override
{
WebFloatRect rect(0, 0, size.width, size.height);
WebCanvas* canvas = context->beginDrawing(rect);
SkPaint paint;
paint.setColor(m_color);
paint.setStyle(SkPaint::kFill_Style);
canvas->drawRectCoords(0, 0, size.width, size.height, paint);
context->endDrawing();
}
private:
SkColor m_color;
};
// PageOverlay that uses the underlying blink::GraphicsContext to paint a
// solid color.
class PrivateGraphicsContextOverlay : public PageOverlay::Delegate {
public:
PrivateGraphicsContextOverlay(Color color) : m_color(color) { }
void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) const override
{
GraphicsContext& graphicsContext = toWebGraphicsContextImpl(context)->graphicsContext();
if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, *this, DisplayItem::PageOverlay))
if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, pageOverlay, DisplayItem::PageOverlay))
return;
FloatRect rect(0, 0, size.width, size.height);
DrawingRecorder drawingRecorder(graphicsContext, *this, DisplayItem::PageOverlay, rect);
DrawingRecorder drawingRecorder(graphicsContext, pageOverlay, DisplayItem::PageOverlay, rect);
graphicsContext.fillRect(rect, m_color);
}
DisplayItemClient displayItemClient() const { return toDisplayItemClient(this); }
String debugName() const { return "PrivateGraphicsContextOverlay"; }
private:
Color m_color;
};
......@@ -129,13 +103,12 @@ public:
MOCK_METHOD2(onDrawRect, void(const SkRect&, const SkPaint&));
};
template <typename OverlayType>
void PageOverlayTest::runPageOverlayTestWithAcceleratedCompositing()
TEST_F(PageOverlayTest, PageOverlay_AcceleratedCompositing)
{
initialize(AcceleratedCompositing);
webViewImpl()->layerTreeView()->setViewportSize(WebSize(viewportWidth, viewportHeight));
OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(webViewImpl(), new OverlayType(SK_ColorYELLOW));
OwnPtr<PageOverlay> pageOverlay = PageOverlay::create(webViewImpl(), new SolidColorOverlay(SK_ColorYELLOW));
pageOverlay->update();
webViewImpl()->layout();
......@@ -164,15 +137,5 @@ void PageOverlayTest::runPageOverlayTestWithAcceleratedCompositing()
graphicsContext.endRecording()->playback(&canvas);
}
TEST_F(PageOverlayTest, SimpleCanvasOverlay_AcceleratedCompositing)
{
runPageOverlayTestWithAcceleratedCompositing<SimpleCanvasOverlay>();
}
TEST_F(PageOverlayTest, PrivateGraphicsContextOverlay_AcceleratedCompositing)
{
runPageOverlayTestWithAcceleratedCompositing<PrivateGraphicsContextOverlay>();
}
} // namespace
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "web/WebGraphicsContextImpl.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/paint/DrawingRecorder.h"
namespace blink {
WebGraphicsContextImpl::WebGraphicsContextImpl(GraphicsContext& graphicsContext, const DisplayItemClientWrapper& client, DisplayItem::Type type)
: m_graphicsContext(graphicsContext)
, m_client(client)
, m_type(type)
#ifndef NDEBUG
, m_hasBegunDrawing(false)
#endif
{
}
WebGraphicsContextImpl::~WebGraphicsContextImpl()
{
}
WebCanvas* WebGraphicsContextImpl::beginDrawing(const WebFloatRect& bounds)
{
#ifndef NDEBUG
ASSERT(!m_hasBegunDrawing);
m_hasBegunDrawing = true;
#endif
ASSERT(!DrawingRecorder::useCachedDrawingIfPossible(m_graphicsContext, m_client, m_type));
m_drawingRecorder = adoptPtr(new DrawingRecorder(m_graphicsContext, m_client, m_type, bounds));
WebCanvas* canvas = m_graphicsContext.canvas();
ASSERT(canvas);
return canvas;
}
void WebGraphicsContextImpl::endDrawing()
{
ASSERT(m_drawingRecorder);
m_drawingRecorder.clear();
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebGraphicsContextImpl_h
#define WebGraphicsContextImpl_h
#include "platform/graphics/paint/DisplayItem.h"
#include "platform/graphics/paint/DisplayItemClient.h"
#include "public/web/WebGraphicsContext.h"
#include "wtf/OwnPtr.h"
namespace blink {
class DrawingRecorder;
class GraphicsContext;
// Wraps a blink::GraphicsContext.
// Internal consumers can extract the underlying context (via WebGraphicsContextImpl).
// External consumers can make a single drawing using a WebCanvas.
class WebGraphicsContextImpl : public WebGraphicsContext {
public:
WebGraphicsContextImpl(GraphicsContext&, const DisplayItemClientWrapper&, DisplayItem::Type);
~WebGraphicsContextImpl();
GraphicsContext& graphicsContext() { return m_graphicsContext; }
// blink::WebGraphicsContext
WebCanvas* beginDrawing(const WebFloatRect& bounds) override;
void endDrawing() override;
private:
GraphicsContext& m_graphicsContext;
DisplayItemClientWrapper m_client;
DisplayItem::Type m_type;
OwnPtr<DrawingRecorder> m_drawingRecorder;
#ifndef NDEBUG
bool m_hasBegunDrawing;
#endif
};
// Source/web/ assumes that WebGraphicsContextImpl is the only implementation.
DEFINE_TYPE_CASTS(WebGraphicsContextImpl, WebGraphicsContext, webGraphicsContext, true, true);
} // namespace blink
#endif
......@@ -113,9 +113,11 @@
#include "platform/fonts/FontCache.h"
#include "platform/graphics/Color.h"
#include "platform/graphics/FirstPaintInvalidationTracking.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/Image.h"
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/gpu/DrawingBuffer.h"
#include "platform/graphics/paint/DrawingRecorder.h"
#include "platform/scroll/ScrollbarTheme.h"
#include "platform/weborigin/SchemeRegistry.h"
#include "public/platform/Platform.h"
......@@ -134,7 +136,6 @@
#include "public/web/WebElement.h"
#include "public/web/WebFrame.h"
#include "public/web/WebFrameClient.h"
#include "public/web/WebGraphicsContext.h"
#include "public/web/WebHitTestResult.h"
#include "public/web/WebInputElement.h"
#include "public/web/WebMeaningfulLayout.h"
......@@ -309,15 +310,13 @@ public:
}
private:
void paintPageOverlay(WebGraphicsContext* context, const WebSize& size) const override
void paintPageOverlay(const PageOverlay& pageOverlay, GraphicsContext& graphicsContext, const WebSize& size) const override
{
WebFloatRect rect(0, 0, size.width, size.height);
WebCanvas* canvas = context->beginDrawing(rect);
SkPaint paint;
paint.setColor(m_color);
paint.setStyle(SkPaint::kFill_Style);
canvas->drawRectCoords(0, 0, size.width, size.height, paint);
context->endDrawing();
if (DrawingRecorder::useCachedDrawingIfPossible(graphicsContext, pageOverlay, DisplayItem::PageOverlay))
return;
FloatRect rect(0, 0, size.width, size.height);
DrawingRecorder drawingRecorder(graphicsContext, pageOverlay, DisplayItem::PageOverlay, rect);
graphicsContext.fillRect(rect, m_color);
}
WebColor m_color;
......
......@@ -156,8 +156,6 @@
'WebGeolocationPermissionRequestManager.cpp',
'WebGeolocationPosition.cpp',
'WebGlyphCache.cpp',
'WebGraphicsContextImpl.cpp',
'WebGraphicsContextImpl.h',
'WebHeap.cpp',
'WebHelperPluginImpl.cpp',
'WebHelperPluginImpl.h',
......
......@@ -408,7 +408,6 @@
"web/WebGeolocationPermissionRequestManager.h",
"web/WebGeolocationPosition.h",
"web/WebGlyphCache.h",
"web/WebGraphicsContext.h",
"web/WebHeap.h",
"web/WebHelperPlugin.h",
"web/WebHistoryCommitType.h",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebGraphicsContext_h
#define WebGraphicsContext_h
#include "public/platform/WebCanvas.h"
#include "public/platform/WebFloatRect.h"
namespace blink {
// Wraps a blink::GraphicsContext.
// Internal consumers can extract the underlying context (via WebGraphicsContextImpl).
// External consumers can make a single drawing using a WebCanvas.
class WebGraphicsContext {
public:
virtual WebCanvas* beginDrawing(const WebFloatRect& bounds) = 0;
virtual void endDrawing() = 0;
protected:
~WebGraphicsContext() { }
};
} // namespace blink
#endif
Markdown is supported
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