OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/paint/TransparencyDisplayItem.h" | 6 #include "core/paint/TransparencyDisplayItem.h" |
7 | 7 |
8 #include "core/rendering/RenderObject.h" | |
9 #include "core/rendering/RenderView.h" | |
10 #include "platform/RuntimeEnabledFeatures.h" | |
8 #include "platform/graphics/GraphicsContext.h" | 11 #include "platform/graphics/GraphicsContext.h" |
9 | 12 |
10 namespace blink { | 13 namespace blink { |
11 | 14 |
12 void BeginTransparencyDisplayItem::replay(GraphicsContext* context) | 15 void BeginTransparencyDisplayItem::replay(GraphicsContext* context) |
13 { | 16 { |
14 context->save(); | 17 if (m_clipBehavior == ClipToRect) { |
chrishtr
2014/11/21 20:09:02
Should we just create an extra ClipDisplayItem rat
| |
15 context->clip(m_clipRect); | 18 context->save(); |
19 context->clip(m_clipRect); | |
20 } | |
16 | 21 |
17 bool hasBlendMode = this->hasBlendMode(); | 22 bool hasBlendMode = this->hasBlendMode(); |
18 if (hasBlendMode) | 23 if (hasBlendMode) |
19 context->setCompositeOperation(context->compositeOperation(), m_blendMod e); | 24 context->setCompositeOperation(context->compositeOperation(), m_blendMod e); |
20 | 25 |
21 context->beginTransparencyLayer(m_opacity); | 26 context->beginTransparencyLayer(m_opacity); |
22 | 27 |
23 if (hasBlendMode) | 28 if (hasBlendMode) |
24 context->setCompositeOperation(context->compositeOperation(), WebBlendMo deNormal); | 29 context->setCompositeOperation(context->compositeOperation(), WebBlendMo deNormal); |
25 #ifdef REVEAL_TRANSPARENCY_LAYERS | 30 #ifdef REVEAL_TRANSPARENCY_LAYERS |
26 context->fillRect(clipRect, Color(0.0f, 0.0f, 0.5f, 0.2f)); | 31 context->fillRect(clipRect, Color(0.0f, 0.0f, 0.5f, 0.2f)); |
27 #endif | 32 #endif |
28 } | 33 } |
29 | 34 |
30 #ifndef NDEBUG | 35 #ifndef NDEBUG |
31 WTF::String BeginTransparencyDisplayItem::asDebugString() const | 36 WTF::String BeginTransparencyDisplayItem::asDebugString() const |
32 { | 37 { |
33 return String::format("{%s, type: \"%s\", clip bounds: [%f,%f,%f,%f], hasBle ndMode: %d, blendMode: %d, opacity: %f}", | 38 return String::format("{%s, type: \"%s\", clip bounds: [%f,%f,%f,%f], hasBle ndMode: %d, blendMode: %d, opacity: %f}", |
34 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type()) .utf8().data(), | 39 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type()) .utf8().data(), |
35 m_clipRect.x().toFloat(), m_clipRect.y().toFloat(), m_clipRect.width().t oFloat(), m_clipRect.height().toFloat(), | 40 m_clipRect.x().toFloat(), m_clipRect.y().toFloat(), m_clipRect.width().t oFloat(), m_clipRect.height().toFloat(), |
36 hasBlendMode(), m_blendMode, m_opacity); | 41 hasBlendMode(), m_blendMode, m_opacity); |
37 } | 42 } |
38 #endif | 43 #endif |
39 | 44 |
40 void EndTransparencyDisplayItem::replay(GraphicsContext* context) | 45 void EndTransparencyDisplayItem::replay(GraphicsContext* context) |
41 { | 46 { |
42 context->endLayer(); | 47 context->endLayer(); |
43 context->restore(); | 48 if (m_clipBehavior == ClipToRect) |
49 context->restore(); | |
44 } | 50 } |
45 | 51 |
46 #ifndef NDEBUG | 52 #ifndef NDEBUG |
47 WTF::String EndTransparencyDisplayItem::asDebugString() const | 53 WTF::String EndTransparencyDisplayItem::asDebugString() const |
48 { | 54 { |
49 return String::format("{%s, type: \"%s\"}", | 55 return String::format("{%s, type: \"%s\"}", |
50 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type()) .utf8().data()); | 56 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type()) .utf8().data()); |
51 } | 57 } |
52 #endif | 58 #endif |
53 | 59 |
60 TransparencyRecorder::TransparencyRecorder(GraphicsContext* graphicsContext, con st RenderObject* renderer, DisplayItem::Type type, const LayoutRect& clipRect, c onst WebBlendMode& blendMode, const float opacity, TransparencyClipBehavior clip Behavior) | |
61 : m_renderer(renderer) | |
62 , m_type(type) | |
63 , m_graphicsContext(graphicsContext) | |
64 , m_clipBehavior(clipBehavior) | |
65 { | |
66 OwnPtr<BeginTransparencyDisplayItem> beginTransparencyDisplayItem = adoptPtr (new BeginTransparencyDisplayItem(renderer, type, clipRect, blendMode, opacity, clipBehavior)); | |
67 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | |
68 renderer->view()->viewDisplayList().add(beginTransparencyDisplayItem.rel ease()); | |
69 else | |
70 beginTransparencyDisplayItem->replay(graphicsContext); | |
71 } | |
72 | |
73 TransparencyRecorder::~TransparencyRecorder() | |
74 { | |
75 OwnPtr<EndTransparencyDisplayItem> endTransparencyDisplayItem = adoptPtr(new EndTransparencyDisplayItem(m_renderer, m_type, m_clipBehavior)); | |
76 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | |
77 m_renderer->view()->viewDisplayList().add(endTransparencyDisplayItem.rel ease()); | |
78 else | |
79 endTransparencyDisplayItem->replay(m_graphicsContext); | |
80 } | |
81 | |
54 } // namespace blink | 82 } // namespace blink |
OLD | NEW |