| 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" | |
| 11 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 12 | 9 |
| 13 namespace blink { | 10 namespace blink { |
| 14 | 11 |
| 15 void BeginTransparencyDisplayItem::replay(GraphicsContext* context) | 12 void BeginTransparencyDisplayItem::replay(GraphicsContext* context) |
| 16 { | 13 { |
| 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 |
| 25 } | 28 } |
| 26 | 29 |
| 27 #ifndef NDEBUG | 30 #ifndef NDEBUG |
| 28 WTF::String BeginTransparencyDisplayItem::asDebugString() const | 31 WTF::String BeginTransparencyDisplayItem::asDebugString() const |
| 29 { | 32 { |
| 30 return String::format("{%s, type: \"%s\", hasBlendMode: %d, blendMode: %d, o
pacity: %f}", | 33 return String::format("{%s, type: \"%s\", clip bounds: [%f,%f,%f,%f], hasBle
ndMode: %d, blendMode: %d, opacity: %f}", |
| 31 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type())
.utf8().data(), | 34 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(), |
| 32 hasBlendMode(), m_blendMode, m_opacity); | 36 hasBlendMode(), m_blendMode, m_opacity); |
| 33 } | 37 } |
| 34 #endif | 38 #endif |
| 35 | 39 |
| 36 void EndTransparencyDisplayItem::replay(GraphicsContext* context) | 40 void EndTransparencyDisplayItem::replay(GraphicsContext* context) |
| 37 { | 41 { |
| 38 context->endLayer(); | 42 context->endLayer(); |
| 43 context->restore(); |
| 39 } | 44 } |
| 40 | 45 |
| 41 #ifndef NDEBUG | 46 #ifndef NDEBUG |
| 42 WTF::String EndTransparencyDisplayItem::asDebugString() const | 47 WTF::String EndTransparencyDisplayItem::asDebugString() const |
| 43 { | 48 { |
| 44 return String::format("{%s, type: \"%s\"}", | 49 return String::format("{%s, type: \"%s\"}", |
| 45 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type())
.utf8().data()); | 50 rendererDebugString(renderer()).utf8().data(), typeAsDebugString(type())
.utf8().data()); |
| 46 } | 51 } |
| 47 #endif | 52 #endif |
| 48 | 53 |
| 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 | |
| 70 } // namespace blink | 54 } // namespace blink |
| OLD | NEW |