OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, Google Inc. All rights reserved. | 2 * Copyright (c) 2012, 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 16 matching lines...) Expand all Loading... |
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 "OpaqueRegionSkia.h" | 33 #include "OpaqueRegionSkia.h" |
34 | 34 |
35 #include "PlatformContextSkia.h" | 35 #include "PlatformContextSkia.h" |
36 | 36 |
| 37 #include "SkCanvas.h" |
37 #include "SkShader.h" | 38 #include "SkShader.h" |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
41 OpaqueRegionSkia::OpaqueRegionSkia() | 42 OpaqueRegionSkia::OpaqueRegionSkia() |
42 : m_opaqueRect(SkRect::MakeEmpty()) | 43 : m_opaqueRect(SkRect::MakeEmpty()) |
43 { | 44 { |
44 } | 45 } |
45 | 46 |
46 OpaqueRegionSkia::~OpaqueRegionSkia() | 47 OpaqueRegionSkia::~OpaqueRegionSkia() |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 230 } |
230 | 231 |
231 void OpaqueRegionSkia::didDrawUnbounded(const SkPaint& paint, bool drawsOpaque) | 232 void OpaqueRegionSkia::didDrawUnbounded(const SkPaint& paint, bool drawsOpaque) |
232 { | 233 { |
233 if (!xfermodePreservesOpaque(paint, drawsOpaque)) { | 234 if (!xfermodePreservesOpaque(paint, drawsOpaque)) { |
234 // We don't know what was drawn on so just destroy the known opaque area
. | 235 // We don't know what was drawn on so just destroy the known opaque area
. |
235 m_opaqueRect = SkRect::MakeEmpty(); | 236 m_opaqueRect = SkRect::MakeEmpty(); |
236 } | 237 } |
237 } | 238 } |
238 | 239 |
239 void OpaqueRegionSkia::markRectAsOpaque(const PlatformContextSkia* context, cons
t SkRect& rect) | 240 void OpaqueRegionSkia::markRectAsOpaque(const PlatformContextSkia* context, cons
t SkRect& paintRect) |
240 { | 241 { |
241 // We want to keep track of an opaque region but bound its complexity at a c
onstant size. | 242 // We want to keep track of an opaque region but bound its complexity at a c
onstant size. |
242 // We keep track of the largest rectangle seen by area. If we can add the ne
w rect to this | 243 // We keep track of the largest rectangle seen by area. If we can add the ne
w rect to this |
243 // rectangle then we do that, as that is the cheapest way to increase the ar
ea returned | 244 // rectangle then we do that, as that is the cheapest way to increase the ar
ea returned |
244 // without increasing the complexity. | 245 // without increasing the complexity. |
245 | 246 |
246 if (rect.isEmpty()) | 247 if (paintRect.isEmpty()) |
247 return; | 248 return; |
248 if (!context->clippedToImage().isOpaque()) | 249 if (!context->clippedToImage().isOpaque()) |
249 return; | 250 return; |
250 if (m_opaqueRect.contains(rect)) | 251 if (context->canvas()->getClipType() != SkCanvas::kRect_ClipType) |
251 return; | 252 return; |
| 253 if (m_opaqueRect.contains(paintRect)) |
| 254 return; |
| 255 |
| 256 // Apply the current clip. |
| 257 SkIRect deviceClip; |
| 258 context->canvas()->getClipDeviceBounds(&deviceClip); |
| 259 SkRect rect = paintRect; |
| 260 if (!rect.intersect(SkIntToScalar(deviceClip.fLeft), SkIntToScalar(deviceCli
p.fTop), SkIntToScalar(deviceClip.fRight), SkIntToScalar(deviceClip.fBottom))) |
| 261 return; |
| 262 |
252 if (rect.contains(m_opaqueRect)) { | 263 if (rect.contains(m_opaqueRect)) { |
253 m_opaqueRect = rect; | 264 m_opaqueRect = rect; |
254 return; | 265 return; |
255 } | 266 } |
256 | 267 |
257 if (rect.fTop <= m_opaqueRect.fTop && rect.fBottom >= m_opaqueRect.fBottom)
{ | 268 if (rect.fTop <= m_opaqueRect.fTop && rect.fBottom >= m_opaqueRect.fBottom)
{ |
258 if (rect.fLeft < m_opaqueRect.fLeft && rect.fRight >= m_opaqueRect.fLeft
) | 269 if (rect.fLeft < m_opaqueRect.fLeft && rect.fRight >= m_opaqueRect.fLeft
) |
259 m_opaqueRect.fLeft = rect.fLeft; | 270 m_opaqueRect.fLeft = rect.fLeft; |
260 if (rect.fRight > m_opaqueRect.fRight && rect.fLeft <= m_opaqueRect.fRig
ht) | 271 if (rect.fRight > m_opaqueRect.fRight && rect.fLeft <= m_opaqueRect.fRig
ht) |
261 m_opaqueRect.fRight = rect.fRight; | 272 m_opaqueRect.fRight = rect.fRight; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 else | 311 else |
301 vertical.fLeft = rect.fRight; | 312 vertical.fLeft = rect.fRight; |
302 | 313 |
303 if ((long)horizontal.width() * (long)horizontal.height() > (long)vertical.wi
dth() * (long)vertical.height()) | 314 if ((long)horizontal.width() * (long)horizontal.height() > (long)vertical.wi
dth() * (long)vertical.height()) |
304 m_opaqueRect = horizontal; | 315 m_opaqueRect = horizontal; |
305 else | 316 else |
306 m_opaqueRect = vertical; | 317 m_opaqueRect = vertical; |
307 } | 318 } |
308 | 319 |
309 } // namespace WebCore | 320 } // namespace WebCore |
OLD | NEW |