Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: Source/platform/graphics/GraphicsContext.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: mac+win build fix Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "platform/graphics/GraphicsContext.h" 28 #include "platform/graphics/GraphicsContext.h"
29 29
30 #include "platform/geometry/IntRect.h" 30 #include "platform/geometry/IntRect.h"
31 #include "platform/geometry/RoundedRect.h" 31 #include "platform/geometry/RoundedRect.h"
32 #include "platform/graphics/BitmapImage.h" 32 #include "platform/graphics/BitmapImage.h"
33 #include "platform/graphics/DisplayList.h" 33 #include "platform/graphics/DisplayList.h"
34 #include "platform/graphics/Gradient.h" 34 #include "platform/graphics/Gradient.h"
35 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/TextRunIterator.h" 36 #include "platform/graphics/TextRunIterator.h"
36 #include "platform/text/BidiResolver.h" 37 #include "platform/text/BidiResolver.h"
37 #include "platform/weborigin/KURL.h" 38 #include "platform/weborigin/KURL.h"
38 #include "third_party/skia/include/core/SkAnnotation.h" 39 #include "third_party/skia/include/core/SkAnnotation.h"
39 #include "third_party/skia/include/core/SkColorFilter.h" 40 #include "third_party/skia/include/core/SkColorFilter.h"
40 #include "third_party/skia/include/core/SkData.h" 41 #include "third_party/skia/include/core/SkData.h"
41 #include "third_party/skia/include/core/SkPicture.h" 42 #include "third_party/skia/include/core/SkPicture.h"
42 #include "third_party/skia/include/core/SkRRect.h" 43 #include "third_party/skia/include/core/SkRRect.h"
43 #include "third_party/skia/include/core/SkRefCnt.h" 44 #include "third_party/skia/include/core/SkRefCnt.h"
44 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 45 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
45 #include "third_party/skia/include/effects/SkCornerPathEffect.h" 46 #include "third_party/skia/include/effects/SkCornerPathEffect.h"
46 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 47 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
48 #include "third_party/skia/include/gpu/GrRenderTarget.h"
49 #include "third_party/skia/include/gpu/GrTexture.h"
47 #include "wtf/Assertions.h" 50 #include "wtf/Assertions.h"
48 #include "wtf/MathExtras.h" 51 #include "wtf/MathExtras.h"
49 52
50 #if OS(MACOSX) 53 #if OS(MACOSX)
51 #include <ApplicationServices/ApplicationServices.h> 54 #include <ApplicationServices/ApplicationServices.h>
52 #endif 55 #endif
53 56
54 using namespace std; 57 using namespace std;
55 using blink::WebBlendMode; 58 using blink::WebBlendMode;
56 59
57 namespace WebCore { 60 namespace WebCore {
58 61
62 namespace {
63
64 class CompatibleImageBufferSurface : public ImageBufferSurface {
65 WTF_MAKE_NONCOPYABLE(CompatibleImageBufferSurface); WTF_MAKE_FAST_ALLOCATED;
66 public:
67 CompatibleImageBufferSurface(PassRefPtr<SkBaseDevice> device, const IntSize& size, OpacityMode opacityMode)
68 : ImageBufferSurface(size, opacityMode)
69 {
70 m_canvas = adoptPtr(new SkCanvas(device.get())); // Takes a ref on devic e
71 }
72 virtual ~CompatibleImageBufferSurface() { }
73
74 virtual SkCanvas* canvas() const OVERRIDE { return m_canvas.get(); }
75 virtual bool isValid() const OVERRIDE { return m_canvas; }
76 virtual bool isAccelerated() const OVERRIDE { return isValid() && m_canvas-> getTopDevice()->accessRenderTarget(); }
77 virtual Platform3DObject getBackingTexture() const OVERRIDE
78 {
79 ASSERT(isAccelerated());
80 GrRenderTarget* renderTarget = m_canvas->getTopDevice()->accessRenderTar get();
81 if (renderTarget) {
82 return renderTarget->asTexture()->getTextureHandle();
83 }
84 return 0;
85 };
86
87 private:
88 OwnPtr<SkCanvas> m_canvas;
89 };
90
91 } // unnamed namespace
92
59 struct GraphicsContext::DeferredSaveState { 93 struct GraphicsContext::DeferredSaveState {
60 DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount( count) { } 94 DeferredSaveState(unsigned mask, int count) : m_flags(mask), m_restoreCount( count) { }
61 95
62 unsigned m_flags; 96 unsigned m_flags;
63 int m_restoreCount; 97 int m_restoreCount;
64 }; 98 };
65 99
66 struct GraphicsContext::RecordingState { 100 struct GraphicsContext::RecordingState {
67 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR efPtr<DisplayList> displayList) 101 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR efPtr<DisplayList> displayList)
68 : m_savedCanvas(currentCanvas) 102 : m_savedCanvas(currentCanvas)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 { 142 {
109 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); 143 TRACE_EVENT0("skia", "GraphicsContext::bitmap");
110 return &m_canvas->getDevice()->accessBitmap(false); 144 return &m_canvas->getDevice()->accessBitmap(false);
111 } 145 }
112 146
113 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const 147 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const
114 { 148 {
115 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); 149 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite);
116 } 150 }
117 151
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() 152 void GraphicsContext::save()
127 { 153 {
128 if (paintingDisabled()) 154 if (paintingDisabled())
129 return; 155 return;
130 156
131 m_stateStack.append(m_state->clone()); 157 m_stateStack.append(m_state->clone());
132 m_state = m_stateStack.last().get(); 158 m_state = m_stateStack.last().get();
133 159
134 m_saveStateStack.append(DeferredSaveState(m_deferredSaveFlags, m_canvas->get SaveCount())); 160 m_saveStateStack.append(DeferredSaveState(m_deferredSaveFlags, m_canvas->get SaveCount()));
135 m_deferredSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; 161 m_deferredSaveFlags |= SkCanvas::kMatrixClip_SaveFlag;
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 setImageInterpolationQuality(previousInterpolationQuality); 1146 setImageInterpolationQuality(previousInterpolationQuality);
1121 } else { 1147 } else {
1122 image->drawTiled(this, dest, srcRect, tileScaleFactor, hRule, vRule, op) ; 1148 image->drawTiled(this, dest, srcRect, tileScaleFactor, hRule, vRule, op) ;
1123 } 1149 }
1124 } 1150 }
1125 1151
1126 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& p, Com positeOperator op, WebBlendMode blendMode) 1152 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& p, Com positeOperator op, WebBlendMode blendMode)
1127 { 1153 {
1128 if (!image) 1154 if (!image)
1129 return; 1155 return;
1130 drawImageBuffer(image, FloatRect(IntRect(p, image->logicalSize())), FloatRec t(FloatPoint(), FloatSize(image->logicalSize())), op, blendMode); 1156 drawImageBuffer(image, FloatRect(IntRect(p, image->size())), FloatRect(Float Point(), FloatSize(image->size())), op, blendMode);
1131 } 1157 }
1132 1158
1133 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& r, Comp ositeOperator op, WebBlendMode blendMode, bool useLowQualityScale) 1159 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& r, Comp ositeOperator op, WebBlendMode blendMode, bool useLowQualityScale)
1134 { 1160 {
1135 if (!image) 1161 if (!image)
1136 return; 1162 return;
1137 drawImageBuffer(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image ->logicalSize())), op, blendMode, useLowQualityScale); 1163 drawImageBuffer(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image ->size())), op, blendMode, useLowQualityScale);
1138 } 1164 }
1139 1165
1140 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode) 1166 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntPoint& dest, const IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode)
1141 { 1167 {
1142 drawImageBuffer(image, FloatRect(IntRect(dest, srcRect.size())), FloatRect(s rcRect), op, blendMode); 1168 drawImageBuffer(image, FloatRect(IntRect(dest, srcRect.size())), FloatRect(s rcRect), op, blendMode);
1143 } 1169 }
1144 1170
1145 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& dest, c onst IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode, bool useLow QualityScale) 1171 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const IntRect& dest, c onst IntRect& srcRect, CompositeOperator op, WebBlendMode blendMode, bool useLow QualityScale)
1146 { 1172 {
1147 drawImageBuffer(image, FloatRect(dest), FloatRect(srcRect), op, blendMode, u seLowQualityScale); 1173 drawImageBuffer(image, FloatRect(dest), FloatRect(srcRect), op, blendMode, u seLowQualityScale);
1148 } 1174 }
1149 1175
1150 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest) 1176 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest)
1151 { 1177 {
1152 if (!image) 1178 if (!image)
1153 return; 1179 return;
1154 drawImageBuffer(image, dest, FloatRect(IntRect(IntPoint(), image->logicalSiz e()))); 1180 drawImageBuffer(image, dest, FloatRect(IntRect(IntPoint(), image->size())));
1155 } 1181 }
1156 1182
1157 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op, WebBlendMode blendMode, bool useLow QualityScale) 1183 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op, WebBlendMode blendMode, bool useLow QualityScale)
1158 { 1184 {
1159 if (paintingDisabled() || !image) 1185 if (paintingDisabled() || !image)
1160 return; 1186 return;
1161 1187
1162 if (useLowQualityScale) { 1188 if (useLowQualityScale) {
1163 InterpolationQuality previousInterpolationQuality = imageInterpolationQu ality(); 1189 InterpolationQuality previousInterpolationQuality = imageInterpolationQu ality();
1164 setImageInterpolationQuality(InterpolationLow); 1190 setImageInterpolationQuality(InterpolationLow);
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 p1.setX(p1.x() + 0.5f); 1721 p1.setX(p1.x() + 0.5f);
1696 p2.setX(p2.x() + 0.5f); 1722 p2.setX(p2.x() + 0.5f);
1697 } else { 1723 } else {
1698 // We're a horizontal line. Adjust our y. 1724 // We're a horizontal line. Adjust our y.
1699 p1.setY(p1.y() + 0.5f); 1725 p1.setY(p1.y() + 0.5f);
1700 p2.setY(p2.y() + 0.5f); 1726 p2.setY(p2.y() + 0.5f);
1701 } 1727 }
1702 } 1728 }
1703 } 1729 }
1704 1730
1705 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s ize, bool hasAlpha) const 1731 PassOwnPtr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const IntSize& s ize, OpacityMode opacityMode) const
1706 { 1732 {
1707 // 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
1708 // 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
1709 // graphics context. 1735 // graphics context.
1710 1736
1711 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale); 1737 AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale);
1712 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())));
1713 1739
1714 OwnPtr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(scaledSize, 1, this, hasAlpha); 1740 RefPtr<SkBaseDevice> device = adoptRef(m_canvas->getTopDevice()->createCompa tibleDevice(SkBitmap::kARGB_8888_Config, size.width(), size.height(), opacityMod e == Opaque));
1715 if (!buffer) 1741 if (!device)
1716 return nullptr; 1742 return nullptr;
1743 OwnPtr<ImageBufferSurface> surface = adoptPtr(new CompatibleImageBufferSurfa ce(device.release(), scaledSize, opacityMode));
1744 ASSERT(surface->isValid());
1745 OwnPtr<ImageBuffer> buffer = adoptPtr(new ImageBuffer(surface.release()));
1717 1746
1718 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) / size.width(), 1747 buffer->context()->scale(FloatSize(static_cast<float>(scaledSize.width()) / size.width(),
1719 static_cast<float>(scaledSize.height()) / size.height())); 1748 static_cast<float>(scaledSize.height()) / size.height()));
1720 1749
1721 return buffer.release(); 1750 return buffer.release();
1722 } 1751 }
1723 1752
1724 void GraphicsContext::addCornerArc(SkPath* path, const SkRect& rect, const IntSi ze& size, int startAngle) 1753 void GraphicsContext::addCornerArc(SkPath* path, const SkRect& rect, const IntSi ze& size, int startAngle)
1725 { 1754 {
1726 SkIRect ir; 1755 SkIRect ir;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 1995
1967 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) 1996 void GraphicsContext::didDrawTextInRect(const SkRect& textRect)
1968 { 1997 {
1969 if (m_trackTextRegion) { 1998 if (m_trackTextRegion) {
1970 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); 1999 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion");
1971 m_textRegion.join(textRect); 2000 m_textRegion.join(textRect);
1972 } 2001 }
1973 } 2002 }
1974 2003
1975 } 2004 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698