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(); | |
15 context->clip(m_clipRect); | |
16 | |
17 bool hasBlendMode = this->hasBlendMode(); | 17 bool hasBlendMode = this->hasBlendMode(); |
18 if (hasBlendMode) | 18 if (hasBlendMode) |
19 context->setCompositeOperation(context->compositeOperation(), m_blendMod
e); | 19 context->setCompositeOperation(context->compositeOperation(), m_blendMod
e); |
20 | 20 |
21 context->beginTransparencyLayer(m_opacity); | 21 context->beginTransparencyLayer(m_opacity); |
22 | 22 |
23 if (hasBlendMode) | 23 if (hasBlendMode) |
24 context->setCompositeOperation(context->compositeOperation(), WebBlendMo
deNormal); | 24 context->setCompositeOperation(context->compositeOperation(), WebBlendMo
deNormal); |
25 #ifdef REVEAL_TRANSPARENCY_LAYERS | |
26 context->fillRect(clipRect, Color(0.0f, 0.0f, 0.5f, 0.2f)); | |
27 #endif | |
28 } | 25 } |
29 | 26 |
30 #ifndef NDEBUG | 27 #ifndef NDEBUG |
31 WTF::String BeginTransparencyDisplayItem::asDebugString() const | 28 WTF::String BeginTransparencyDisplayItem::asDebugString() const |
32 { | 29 { |
33 return String::format("{%s, type: \"%s\", clip bounds: [%f,%f,%f,%f], hasBle
ndMode: %d, blendMode: %d, opacity: %f}", | 30 return String::format("{%s, type: \"%s\", hasBlendMode: %d, blendMode: %d, o
pacity: %f}", |
34 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type())
.utf8().data(), | 31 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(), | |
36 hasBlendMode(), m_blendMode, m_opacity); | 32 hasBlendMode(), m_blendMode, m_opacity); |
37 } | 33 } |
38 #endif | 34 #endif |
39 | 35 |
40 void EndTransparencyDisplayItem::replay(GraphicsContext* context) | 36 void EndTransparencyDisplayItem::replay(GraphicsContext* context) |
41 { | 37 { |
42 context->endLayer(); | 38 context->endLayer(); |
43 context->restore(); | |
44 } | 39 } |
45 | 40 |
46 #ifndef NDEBUG | 41 #ifndef NDEBUG |
47 WTF::String EndTransparencyDisplayItem::asDebugString() const | 42 WTF::String EndTransparencyDisplayItem::asDebugString() const |
48 { | 43 { |
49 return String::format("{%s, type: \"%s\"}", | 44 return String::format("{%s, type: \"%s\"}", |
50 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type())
.utf8().data()); | 45 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type())
.utf8().data()); |
51 } | 46 } |
52 #endif | 47 #endif |
53 | 48 |
| 49 TransparencyRecorder::TransparencyRecorder(GraphicsContext* graphicsContext, con
st RenderObject* renderer, DisplayItem::Type type, const WebBlendMode& blendMode
, const float opacity) |
| 50 : m_renderer(renderer) |
| 51 , m_type(type) |
| 52 , m_graphicsContext(graphicsContext) |
| 53 { |
| 54 OwnPtr<BeginTransparencyDisplayItem> beginTransparencyDisplayItem = adoptPtr
(new BeginTransparencyDisplayItem(renderer, type, blendMode, opacity)); |
| 55 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 56 renderer->view()->viewDisplayList().add(beginTransparencyDisplayItem.rel
ease()); |
| 57 else |
| 58 beginTransparencyDisplayItem->replay(graphicsContext); |
| 59 } |
| 60 |
| 61 TransparencyRecorder::~TransparencyRecorder() |
| 62 { |
| 63 OwnPtr<EndTransparencyDisplayItem> endTransparencyDisplayItem = adoptPtr(new
EndTransparencyDisplayItem(m_renderer, m_type)); |
| 64 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 65 m_renderer->view()->viewDisplayList().add(endTransparencyDisplayItem.rel
ease()); |
| 66 else |
| 67 endTransparencyDisplayItem->replay(m_graphicsContext); |
| 68 } |
| 69 |
54 } // namespace blink | 70 } // namespace blink |
OLD | NEW |