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

Side by Side Diff: third_party/WebKit/WebCore/platform/graphics/skia/PlatformContextSkia.cpp

Issue 18339: Attempt at getting GDI text to render when drawn using canvas. I added... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 months 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
« no previous file with comments | « third_party/WebKit/WebCore/platform/graphics/skia/PlatformContextSkia.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "GraphicsContext.h" 33 #include "GraphicsContext.h"
34 #include "ImageBuffer.h"
34 #include "NativeImageSkia.h" 35 #include "NativeImageSkia.h"
35 #include "PlatformContextSkia.h" 36 #include "PlatformContextSkia.h"
36 #include "SkiaUtils.h" 37 #include "SkiaUtils.h"
37 38
38 #include "skia/ext/image_operations.h" 39 #include "skia/ext/image_operations.h"
39 #include "skia/ext/platform_canvas.h" 40 #include "skia/ext/platform_canvas.h"
40 41
41 #include "SkBitmap.h" 42 #include "SkBitmap.h"
42 #include "SkColorPriv.h" 43 #include "SkColorPriv.h"
43 #include "SkShader.h" 44 #include "SkShader.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 SkPaint::Join m_lineJoin; 80 SkPaint::Join m_lineJoin;
80 SkDashPathEffect* m_dash; 81 SkDashPathEffect* m_dash;
81 82
82 // Text. (See cTextFill & friends in GraphicsContext.h.) 83 // Text. (See cTextFill & friends in GraphicsContext.h.)
83 int m_textDrawingMode; 84 int m_textDrawingMode;
84 85
85 // Helper function for applying the state's alpha value to the given input 86 // Helper function for applying the state's alpha value to the given input
86 // color to produce a new output color. 87 // color to produce a new output color.
87 SkColor applyAlpha(SkColor) const; 88 SkColor applyAlpha(SkColor) const;
88 89
90 #if defined(__linux__) || PLATFORM(WIN_OS)
91 // If non-empty, the current State is clipped to this image.
92 SkBitmap m_imageBufferClip;
93 // If m_imageBufferClip is non-empty, this is the region the image is clippe d to.
94 WebCore::FloatRect m_clip;
95 #endif
96
89 private: 97 private:
90 // Not supported. 98 // Not supported.
91 void operator=(const State&); 99 void operator=(const State&);
92 }; 100 };
93 101
94 // Note: Keep theses default values in sync with GraphicsContextState. 102 // Note: Keep theses default values in sync with GraphicsContextState.
95 PlatformContextSkia::State::State() 103 PlatformContextSkia::State::State()
96 : m_alpha(1) 104 : m_alpha(1)
97 , m_porterDuffMode(SkPorterDuff::kSrcOver_Mode) 105 , m_porterDuffMode(SkPorterDuff::kSrcOver_Mode)
98 , m_gradient(0) 106 , m_gradient(0)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 int a = SkAlphaMul(SkColorGetA(c), s); 149 int a = SkAlphaMul(SkColorGetA(c), s);
142 return (c & 0x00FFFFFF) | (a << 24); 150 return (c & 0x00FFFFFF) | (a << 24);
143 } 151 }
144 152
145 // PlatformContextSkia --------------------------------------------------------- 153 // PlatformContextSkia ---------------------------------------------------------
146 154
147 // Danger: canvas can be NULL. 155 // Danger: canvas can be NULL.
148 PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas) 156 PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas)
149 : m_canvas(canvas) 157 : m_canvas(canvas)
150 , m_stateStack(sizeof(State)) 158 , m_stateStack(sizeof(State))
159 #if PLATFORM(WIN_OS)
160 , m_drawingToImageBuffer(false)
161 #endif
151 { 162 {
152 m_stateStack.append(State()); 163 m_stateStack.append(State());
153 m_state = &m_stateStack.last(); 164 m_state = &m_stateStack.last();
154 #if defined(OS_LINUX) 165 #if defined(OS_LINUX)
155 m_gdkskia = m_canvas ? gdk_skia_new(m_canvas) : 0; 166 m_gdkskia = m_canvas ? gdk_skia_new(m_canvas) : 0;
156 #endif 167 #endif
157 } 168 }
158 169
159 PlatformContextSkia::~PlatformContextSkia() 170 PlatformContextSkia::~PlatformContextSkia()
160 { 171 {
161 #if defined(OS_LINUX) 172 #if defined(OS_LINUX)
162 if (m_gdkskia) { 173 if (m_gdkskia) {
163 g_object_unref(m_gdkskia); 174 g_object_unref(m_gdkskia);
164 m_gdkskia = 0; 175 m_gdkskia = 0;
165 } 176 }
166 #endif 177 #endif
167 } 178 }
168 179
169 void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas) 180 void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas)
170 { 181 {
171 m_canvas = canvas; 182 m_canvas = canvas;
172 } 183 }
173 184
185 #if PLATFORM(WIN_OS)
186 void PlatformContextSkia::setDrawingToImageBuffer(bool value)
187 {
188 m_drawingToImageBuffer = value;
189 }
190
191 bool PlatformContextSkia::isDrawingToImageBuffer() const
192 {
193 return m_drawingToImageBuffer;
194 }
195 #endif
196
174 void PlatformContextSkia::save() 197 void PlatformContextSkia::save()
175 { 198 {
176 m_stateStack.append(*m_state); 199 m_stateStack.append(*m_state);
177 m_state = &m_stateStack.last(); 200 m_state = &m_stateStack.last();
178 201
179 // Save our native canvas. 202 // Save our native canvas.
180 canvas()->save(); 203 canvas()->save();
181 } 204 }
182 205
206 #if defined(__linux__) || PLATFORM(WIN_OS)
207 void PlatformContextSkia::beginLayerClippedToImage(const WebCore::FloatRect& rec t,
208 const WebCore::ImageBuffer* i mageBuffer)
209 {
210 // Skia doesn't support clipping to an image, so we create a layer. The next
211 // time restore is invoked the layer and |imageBuffer| are combined to
212 // create the resulting image.
213 m_state->m_clip = rect;
214 SkRect bounds = { SkFloatToScalar(rect.x()), SkFloatToScalar(rect.y()),
215 SkFloatToScalar(rect.right()), SkFloatToScalar(rect.bottom ()) };
216
217 canvas()->saveLayerAlpha(&bounds, 255,
218 static_cast<SkCanvas::SaveFlags>(SkCanvas::kHasAlph aLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag));
219 // Copy off the image as |imageBuffer| may be deleted before restore is invo ked.
220 m_state->m_imageBufferClip = *(imageBuffer->context()->platformContext()->bi tmap());
221 }
222 #endif
183 void PlatformContextSkia::restore() 223 void PlatformContextSkia::restore()
184 { 224 {
225 #if defined(__linux__) || PLATFORM(WIN_OS)
226 if (!m_state->m_imageBufferClip.empty()) {
227 applyClipFromImage(m_state->m_clip, m_state->m_imageBufferClip);
228 canvas()->restore();
229 }
230 #endif
231
185 m_stateStack.removeLast(); 232 m_stateStack.removeLast();
186 m_state = &m_stateStack.last(); 233 m_state = &m_stateStack.last();
187 234
188 // Restore our native canvas. 235 // Restore our native canvas.
189 canvas()->restore(); 236 canvas()->restore();
190 } 237 }
191 238
192 void PlatformContextSkia::drawRect(SkRect rect) 239 void PlatformContextSkia::drawRect(SkRect rect)
193 { 240 {
194 SkPaint paint; 241 SkPaint paint;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 474
428 const SkBitmap* PlatformContextSkia::bitmap() const 475 const SkBitmap* PlatformContextSkia::bitmap() const
429 { 476 {
430 return &m_canvas->getDevice()->accessBitmap(false); 477 return &m_canvas->getDevice()->accessBitmap(false);
431 } 478 }
432 479
433 bool PlatformContextSkia::isPrinting() 480 bool PlatformContextSkia::isPrinting()
434 { 481 {
435 return m_canvas->getTopPlatformDevice().IsVectorial(); 482 return m_canvas->getTopPlatformDevice().IsVectorial();
436 } 483 }
484
485 #if defined(__linux__) || PLATFORM(WIN_OS)
486 void PlatformContextSkia::applyClipFromImage(const WebCore::FloatRect& rect, con st SkBitmap& imageBuffer)
487 {
488 // NOTE: this assumes the image mask contains opaque black for the portions that are to be shown, as such we
489 // only look at the alpha when compositing. I'm not 100% sure this is what W ebKit expects for image clipping.
490 SkPaint paint;
491 paint.setPorterDuffXfermode(SkPorterDuff::kDstIn_Mode);
492 m_canvas->drawBitmap(imageBuffer, SkFloatToScalar(rect.x()), SkFloatToScalar (rect.y()), &paint);
493 }
494 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/WebCore/platform/graphics/skia/PlatformContextSkia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698