Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / graphics / ContentLayerDelegate.cpp
blob85ae04aeee50cd0a57ae8673519fb9aa9416631c
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include "config.h"
27 #include "platform/graphics/ContentLayerDelegate.h"
29 #include "platform/EventTracer.h"
30 #include "platform/RuntimeEnabledFeatures.h"
31 #include "platform/TraceEvent.h"
32 #include "platform/TracedValue.h"
33 #include "platform/geometry/IntRect.h"
34 #include "platform/graphics/GraphicsContext.h"
35 #include "platform/graphics/paint/DisplayItemList.h"
36 #include "platform/transforms/AffineTransform.h"
37 #include "platform/transforms/TransformationMatrix.h"
38 #include "public/platform/WebDisplayItemList.h"
39 #include "public/platform/WebFloatRect.h"
40 #include "public/platform/WebRect.h"
41 #include "third_party/skia/include/core/SkCanvas.h"
42 #include "third_party/skia/include/core/SkPicture.h"
43 #include "third_party/skia/include/core/SkPictureRecorder.h"
45 namespace blink {
47 ContentLayerDelegate::ContentLayerDelegate(GraphicsContextPainter* painter)
48 : m_painter(painter)
52 ContentLayerDelegate::~ContentLayerDelegate()
56 PassRefPtr<TracedValue> toTracedValue(const WebRect& clip)
58 RefPtr<TracedValue> tracedValue = TracedValue::create();
59 tracedValue->beginArray("clip_rect");
60 tracedValue->pushInteger(clip.x);
61 tracedValue->pushInteger(clip.y);
62 tracedValue->pushInteger(clip.width);
63 tracedValue->pushInteger(clip.height);
64 tracedValue->endArray();
65 return tracedValue;
68 void ContentLayerDelegate::paintContents(
69 SkCanvas* canvas, const WebRect& clip,
70 WebContentLayerClient::PaintingControlSetting paintingControl)
72 TRACE_EVENT1("blink,benchmark", "ContentLayerDelegate::paintContents", "clip_rect", toTracedValue(clip));
74 // TODO(pdr): Remove this function.
75 ASSERT_NOT_REACHED();
78 void ContentLayerDelegate::paintContents(
79 WebDisplayItemList* webDisplayItemList, const WebRect& clip,
80 WebContentLayerClient::PaintingControlSetting paintingControl)
82 TRACE_EVENT1("blink,benchmark", "ContentLayerDelegate::paintContents", "clip_rect", toTracedValue(clip));
84 // TODO(pdr): Remove when slimming paint v2 is further along. This is only
85 // here so the browser is usable during development and does not crash due
86 // to committing the new display items twice.
87 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
88 m_painter->displayItemList()->appendToWebDisplayItemList(webDisplayItemList);
89 return;
92 DisplayItemList* displayItemList = m_painter->displayItemList();
93 ASSERT(displayItemList);
94 displayItemList->setDisplayItemConstructionIsDisabled(
95 paintingControl == WebContentLayerClient::DisplayListConstructionDisabled);
97 // We also disable caching when Painting or Construction are disabled. In both cases we would like
98 // to compare assuming the full cost of recording, not the cost of re-using cached content.
99 if (paintingControl != WebContentLayerClient::PaintDefaultBehavior)
100 displayItemList->invalidateAll();
102 GraphicsContext::DisabledMode disabledMode = GraphicsContext::NothingDisabled;
103 if (paintingControl == WebContentLayerClient::DisplayListPaintingDisabled
104 || paintingControl == WebContentLayerClient::DisplayListConstructionDisabled)
105 disabledMode = GraphicsContext::FullyDisabled;
106 GraphicsContext context(displayItemList, disabledMode);
108 m_painter->paint(context, clip);
110 displayItemList->commitNewDisplayItemsAndAppendToWebDisplayItemList(webDisplayItemList);
113 size_t ContentLayerDelegate::approximateUnsharedMemoryUsage() const
115 return m_painter->displayItemList()->approximateUnsharedMemoryUsage();
118 } // namespace blink