| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #include "platform/mac/LocalCurrentGraphicsContext.h" | 20 #include "platform/mac/LocalCurrentGraphicsContext.h" |
| 21 | 21 |
| 22 #include <AppKit/NSGraphicsContext.h> | 22 #include <AppKit/NSGraphicsContext.h> |
| 23 #include "platform/graphics/GraphicsContext.h" | 23 #include "platform/graphics/GraphicsContext.h" |
| 24 #include "platform/mac/ThemeMac.h" | 24 #include "platform/mac/ThemeMac.h" |
| 25 #include "platform_canvas.h" | 25 #include "platform_canvas.h" |
| 26 | 26 |
| 27 namespace blink { | 27 namespace blink { |
| 28 | 28 |
| 29 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext& graphi
csContext, const IntRect& dirtyRect) | 29 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext& graphi
csContext, const IntRect& dirtyRect) |
| 30 : LocalCurrentGraphicsContext(graphicsContext.canvas(), graphicsContext.devi
ceScaleFactor(), nullptr, dirtyRect) | 30 : LocalCurrentGraphicsContext(graphicsContext.canvas(), graphicsContext.devi
ceScaleFactor(), dirtyRect) |
| 31 { | 31 { |
| 32 } | 32 } |
| 33 | 33 |
| 34 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext& graphi
csContext, const IntRect* interestRect, | 34 static IntRect clampRect(int size, const IntRect& rect) |
| 35 const IntRect& dirtyRec
t) | |
| 36 : LocalCurrentGraphicsContext(graphicsContext.canvas(), graphicsContext.devi
ceScaleFactor(), interestRect, dirtyRect) | |
| 37 { | 35 { |
| 36 IntRect clampedRect(rect); |
| 37 clampedRect.setSize(IntSize( |
| 38 std::min(size, clampedRect.width()), |
| 39 std::min(size, clampedRect.height()))); |
| 40 return clampedRect; |
| 38 } | 41 } |
| 39 | 42 |
| 40 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(SkCanvas* canvas, float
deviceScaleFactor, const IntRect* interestRect, | 43 static const int kMaxDirtyRectPixelSize = 10000; |
| 41 const IntRect& dirtyRec
t) | 44 |
| 45 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(SkCanvas* canvas, float
deviceScaleFactor, const IntRect& dirtyRect) |
| 42 : m_didSetGraphicsContext(false) | 46 : m_didSetGraphicsContext(false) |
| 43 , m_inflatedDirtyRect(ThemeMac::inflateRectForAA(dirtyRect)) | 47 , m_inflatedDirtyRect(ThemeMac::inflateRectForAA(dirtyRect)) |
| 44 , m_skiaBitLocker(canvas, | 48 , m_skiaBitLocker(canvas, |
| 45 m_inflatedDirtyRect, | 49 m_inflatedDirtyRect, |
| 46 deviceScaleFactor) | 50 deviceScaleFactor) |
| 47 { | 51 { |
| 48 m_savedCanvas = canvas; | 52 m_savedCanvas = canvas; |
| 49 canvas->save(); | 53 canvas->save(); |
| 50 | 54 |
| 51 bool clipToInterest = interestRect && !interestRect->contains(m_inflatedDirt
yRect); | 55 // Constrain the maximum size of what we paint to something reasonable. This
accordingly |
| 52 if (clipToInterest) { | 56 // means we will not paint the entirety of truly huge native form elements,
which is |
| 53 IntRect clippedBounds(m_inflatedDirtyRect); | 57 // deemed an acceptable tradeoff for this simple approach to manage such an
edge case. |
| 54 clippedBounds.intersect(*interestRect); | 58 if (dirtyRect.width() > kMaxDirtyRectPixelSize || dirtyRect.height() > kMaxD
irtyRectPixelSize) |
| 55 canvas->clipRect(clippedBounds, SkRegion::kIntersect_Op); | 59 canvas->clipRect(clampRect(kMaxDirtyRectPixelSize, dirtyRect), SkRegion:
:kIntersect_Op); |
| 56 } | |
| 57 | 60 |
| 58 CGContextRef cgContext = this->cgContext(); | 61 CGContextRef cgContext = this->cgContext(); |
| 59 if (cgContext == [[NSGraphicsContext currentContext] graphicsPort]) { | 62 if (cgContext == [[NSGraphicsContext currentContext] graphicsPort]) { |
| 60 m_savedNSGraphicsContext = 0; | 63 m_savedNSGraphicsContext = 0; |
| 61 return; | 64 return; |
| 62 } | 65 } |
| 63 | 66 |
| 64 m_savedNSGraphicsContext = [[NSGraphicsContext currentContext] retain]; | 67 m_savedNSGraphicsContext = [[NSGraphicsContext currentContext] retain]; |
| 65 NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphi
csPort:cgContext flipped:YES]; | 68 NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphi
csPort:cgContext flipped:YES]; |
| 66 [NSGraphicsContext setCurrentContext:newContext]; | 69 [NSGraphicsContext setCurrentContext:newContext]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 CGContextRef LocalCurrentGraphicsContext::cgContext() | 83 CGContextRef LocalCurrentGraphicsContext::cgContext() |
| 81 { | 84 { |
| 82 // This synchronizes the CGContext to reflect the current SkCanvas state. | 85 // This synchronizes the CGContext to reflect the current SkCanvas state. |
| 83 // The implementation may not return the same CGContext each time. | 86 // The implementation may not return the same CGContext each time. |
| 84 CGContextRef cgContext = m_skiaBitLocker.cgContext(); | 87 CGContextRef cgContext = m_skiaBitLocker.cgContext(); |
| 85 | 88 |
| 86 return cgContext; | 89 return cgContext; |
| 87 } | 90 } |
| 88 | 91 |
| 89 } | 92 } |
| OLD | NEW |