Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "platform/weborigin/KURL.h" | 37 #include "platform/weborigin/KURL.h" |
| 38 #include "third_party/skia/include/core/SkAnnotation.h" | 38 #include "third_party/skia/include/core/SkAnnotation.h" |
| 39 #include "third_party/skia/include/core/SkColorFilter.h" | 39 #include "third_party/skia/include/core/SkColorFilter.h" |
| 40 #include "third_party/skia/include/core/SkData.h" | 40 #include "third_party/skia/include/core/SkData.h" |
| 41 #include "third_party/skia/include/core/SkPicture.h" | 41 #include "third_party/skia/include/core/SkPicture.h" |
| 42 #include "third_party/skia/include/core/SkRRect.h" | 42 #include "third_party/skia/include/core/SkRRect.h" |
| 43 #include "third_party/skia/include/core/SkRefCnt.h" | 43 #include "third_party/skia/include/core/SkRefCnt.h" |
| 44 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 44 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| 45 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 45 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
| 46 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 46 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| 47 #include "third_party/skia/include/gpu/GrRenderTarget.h" | |
| 48 #include "third_party/skia/include/gpu/GrTexture.h" | |
| 47 #include "wtf/Assertions.h" | 49 #include "wtf/Assertions.h" |
| 48 #include "wtf/MathExtras.h" | 50 #include "wtf/MathExtras.h" |
| 49 | 51 |
| 50 #if OS(MACOSX) | 52 #if OS(MACOSX) |
| 51 #include <ApplicationServices/ApplicationServices.h> | 53 #include <ApplicationServices/ApplicationServices.h> |
| 52 #endif | 54 #endif |
| 53 | 55 |
| 54 using namespace std; | 56 using namespace std; |
| 55 using blink::WebBlendMode; | 57 using blink::WebBlendMode; |
| 56 | 58 |
| 57 namespace WebCore { | 59 namespace WebCore { |
| 58 | 60 |
| 61 namespace { | |
| 62 | |
| 63 class CompatibleImageBufferSurface : public ImageBufferSurface { | |
| 64 WTF_MAKE_NONCOPYABLE(CompatibleImageBufferSurface); WTF_MAKE_FAST_ALLOCATED; | |
| 65 public: | |
| 66 CompatibleImageBufferSurface(SkCanvas* canvas, const IntSize& size, OpacityM ode opacityMode) | |
| 67 : ImageBufferSurface(size, opacityMode, 1.0f) | |
| 68 { | |
| 69 RefPtr<SkBaseDevice> device = adoptRef(canvas->createCompatibleDevice(Sk Bitmap::kARGB_8888_Config, size.width(), size.height(), opacityMode == Opaque)); | |
|
Stephen White
2013/12/04 21:18:40
It's a little confusing to have a canvas that's pa
| |
| 70 if (!device) | |
| 71 return; | |
| 72 m_canvas = adoptPtr(new SkCanvas(device.get())); | |
| 73 } | |
| 74 virtual ~CompatibleImageBufferSurface() { } | |
| 75 | |
| 76 virtual SkCanvas* canvas() const OVERRIDE { return m_canvas.get(); } | |
| 77 virtual bool isValid() const OVERRIDE { return m_canvas; } | |
| 78 virtual bool isAccelerated() const OVERRIDE { return isValid() && m_canvas-> getTopDevice()->accessRenderTarget(); } | |
| 79 virtual Platform3DObject getBackingTexture() const OVERRIDE | |
| 80 { | |
| 81 ASSERT(isAccelerated()); | |
| 82 GrRenderTarget* renderTarget = m_canvas->getTopDevice()->accessRenderTar get(); | |
| 83 if (renderTarget) { | |
| 84 return renderTarget->asTexture()->getTextureHandle(); | |
| 85 } | |
| 86 return 0; | |
| 87 }; | |
| 88 | |
| 89 private: | |
| 90 OwnPtr<SkCanvas> m_canvas; | |
| 91 }; | |
| 92 | |
| 93 } // unnamed namespace | |
| 94 | |
| 59 struct GraphicsContext::DeferredSaveState { | 95 struct GraphicsContext::DeferredSaveState { |
| 60 DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount( count) { } | 96 DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount( count) { } |
| 61 | 97 |
| 62 unsigned m_flags; | 98 unsigned m_flags; |
| 63 int m_restoreCount; | 99 int m_restoreCount; |
| 64 }; | 100 }; |
| 65 | 101 |
| 66 struct GraphicsContext::RecordingState { | 102 struct GraphicsContext::RecordingState { |
| 67 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR efPtr<DisplayList> displayList) | 103 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR efPtr<DisplayList> displayList) |
| 68 : m_savedCanvas(currentCanvas) | 104 : m_savedCanvas(currentCanvas) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 { | 144 { |
| 109 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); | 145 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); |
| 110 return &m_canvas->getDevice()->accessBitmap(false); | 146 return &m_canvas->getDevice()->accessBitmap(false); |
| 111 } | 147 } |
| 112 | 148 |
| 113 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const | 149 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const |
| 114 { | 150 { |
| 115 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); | 151 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); |
| 116 } | 152 } |
| 117 | 153 |
| 118 SkBaseDevice* GraphicsContext::createCompatibleDevice(const IntSize& size, bool hasAlpha) const | |
| 119 { | |
| 120 if (paintingDisabled()) | |
| 121 return 0; | |
| 122 | |
| 123 return m_canvas->createCompatibleDevice(SkBitmap::kARGB_8888_Config, size.wi dth(), size.height(), !hasAlpha); | |
| 124 } | |
| 125 | |
| 126 void GraphicsContext::save() | 154 void GraphicsContext::save() |
| 127 { | 155 { |
| 128 if (paintingDisabled()) | 156 if (paintingDisabled()) |
| 129 return; | 157 return; |
| 130 | 158 |
| 131 m_stateStack.append(m_state->clone()); | 159 m_stateStack.append(m_state->clone()); |
| 132 m_state = m_stateStack.last().get(); | 160 m_state = m_stateStack.last().get(); |
| 133 | 161 |
| 134 m_saveStateStack.append(DeferredSaveState(m_deferredSaveFlags, m_canvas->get SaveCount())); | 162 m_saveStateStack.append(DeferredSaveState(m_deferredSaveFlags, m_canvas->get SaveCount())); |
| 135 m_deferredSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; | 163 m_deferredSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1693 p1.setX(p1.x() + 0.5f); | 1721 p1.setX(p1.x() + 0.5f); |
| 1694 p2.setX(p2.x() + 0.5f); | 1722 p2.setX(p2.x() + 0.5f); |
| 1695 } else { | 1723 } else { |
| 1696 // We're a horizontal line. Adjust our y. | 1724 // We're a horizontal line. Adjust our y. |
| 1697 p1.setY(p1.y() + 0.5f); | 1725 p1.setY(p1.y() + 0.5f); |
| 1698 p2.setY(p2.y() + 0.5f); | 1726 p2.setY(p2.y() + 0.5f); |
| 1699 } | 1727 } |
| 1700 } | 1728 } |
| 1701 } | 1729 } |
| 1702 | 1730 |
| 1703 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s ize, bool hasAlpha) const | 1731 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s ize, OpacityMode opacityMode) const |
| 1704 { | 1732 { |
| 1705 // Make the buffer larger if the context's transform is scaling it so we nee d a higher | 1733 // Make the buffer larger if the context's transform is scaling it so we nee d a higher |
| 1706 // resolution than one pixel per unit. Also set up a corresponding scale fac tor on the | 1734 // resolution than one pixel per unit. Also set up a corresponding scale fac tor on the |
| 1707 // graphics context. | 1735 // graphics context. |
| 1708 | 1736 |
| 1709 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); | 1737 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); |
| 1710 IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())) , static_cast<int>(ceil(size.height() * transform.yScale()))); | 1738 IntSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())) , static_cast<int>(ceil(size.height() * transform.yScale()))); |
| 1711 | 1739 |
| 1712 OwnPtr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(scaledSize, 1, this, hasAlpha); | 1740 OwnPtr<ImageBufferSurface> surface = adoptPtr(new CompatibleImageBufferSurfa ce(m_canvas, scaledSize, opacityMode)); |
| 1713 if (!buffer) | 1741 if (!surface->isValid()) |
| 1714 return nullptr; | 1742 return nullptr; |
| 1743 OwnPtr<ImageBuffer> buffer = adoptPtr(new ImageBuffer(surface.release())); | |
| 1715 | 1744 |
| 1716 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) / size.width(), | 1745 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) / size.width(), |
| 1717 static_cast<float>(scaledSize.height()) / size.height())); | 1746 static_cast<float>(scaledSize.height()) / size.height())); |
| 1718 | 1747 |
| 1719 return buffer.release(); | 1748 return buffer.release(); |
| 1720 } | 1749 } |
| 1721 | 1750 |
| 1722 void GraphicsContext::addCornerArc(SkPath* path, const SkRect& rect, const IntSi ze& size, int startAngle) | 1751 void GraphicsContext::addCornerArc(SkPath* path, const SkRect& rect, const IntSi ze& size, int startAngle) |
| 1723 { | 1752 { |
| 1724 SkIRect ir; | 1753 SkIRect ir; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1965 | 1994 |
| 1966 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 1995 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
| 1967 { | 1996 { |
| 1968 if (m_trackTextRegion) { | 1997 if (m_trackTextRegion) { |
| 1969 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1998 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
| 1970 m_textRegion.join(textRect); | 1999 m_textRegion.join(textRect); |
| 1971 } | 2000 } |
| 1972 } | 2001 } |
| 1973 | 2002 |
| 1974 } | 2003 } |
| OLD | NEW |