| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "platform/mac/LocalCurrentGraphicsContext.h" | 22 #include "platform/mac/LocalCurrentGraphicsContext.h" |
| 23 #include "platform/mac/ThemeMac.h" | 23 #include "platform/mac/ThemeMac.h" |
| 24 | 24 |
| 25 #include <AppKit/NSGraphicsContext.h> | 25 #include <AppKit/NSGraphicsContext.h> |
| 26 #include "platform/graphics/GraphicsContext.h" | 26 #include "platform/graphics/GraphicsContext.h" |
| 27 #include "platform_canvas.h" | 27 #include "platform_canvas.h" |
| 28 | 28 |
| 29 namespace blink { | 29 namespace blink { |
| 30 | 30 |
| 31 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext* graphi
csContext, const IntRect& dirtyRect) | 31 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext* graphi
csContext, const IntRect& dirtyRect) |
| 32 : LocalCurrentGraphicsContext(graphicsContext, nullptr, dirtyRect) | 32 : LocalCurrentGraphicsContext(graphicsContext->canvas(), graphicsContext->de
viceScaleFactor(), nullptr, dirtyRect) |
| 33 { | 33 { |
| 34 } | 34 } |
| 35 | 35 |
| 36 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext* graphi
csContext, const IntRect* interestRect, | 36 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(GraphicsContext* graphi
csContext, const IntRect* interestRect, |
| 37 const IntRect& dirtyRec
t) | 37 const IntRect& dirtyRec
t) |
| 38 : LocalCurrentGraphicsContext(graphicsContext->canvas(), graphicsContext->de
viceScaleFactor(), interestRect, dirtyRect) |
| 39 { |
| 40 } |
| 41 |
| 42 LocalCurrentGraphicsContext::LocalCurrentGraphicsContext(SkCanvas* canvas, float
deviceScaleFactor, const IntRect* interestRect, |
| 43 const IntRect& dirtyRec
t) |
| 38 : m_didSetGraphicsContext(false) | 44 : m_didSetGraphicsContext(false) |
| 39 , m_inflatedDirtyRect(ThemeMac::inflateRectForAA(dirtyRect)) | 45 , m_inflatedDirtyRect(ThemeMac::inflateRectForAA(dirtyRect)) |
| 40 , m_skiaBitLocker(graphicsContext->canvas(), | 46 , m_skiaBitLocker(canvas, |
| 41 m_inflatedDirtyRect, | 47 m_inflatedDirtyRect, |
| 42 graphicsContext->deviceScaleFactor()) | 48 deviceScaleFactor) |
| 43 { | 49 { |
| 44 m_savedGraphicsContext = graphicsContext; | 50 m_savedCanvas = canvas; |
| 45 graphicsContext->save(); | 51 canvas->save(); |
| 46 | 52 |
| 47 bool clipToInterest = interestRect && RuntimeEnabledFeatures::slimmingPaintE
nabled() && !interestRect->contains(m_inflatedDirtyRect); | 53 bool clipToInterest = interestRect && RuntimeEnabledFeatures::slimmingPaintE
nabled() && !interestRect->contains(m_inflatedDirtyRect); |
| 48 if (clipToInterest) { | 54 if (clipToInterest) { |
| 49 IntRect clippedBounds(m_inflatedDirtyRect); | 55 IntRect clippedBounds(m_inflatedDirtyRect); |
| 50 clippedBounds.intersect(*interestRect); | 56 clippedBounds.intersect(*interestRect); |
| 51 graphicsContext->clipRect(clippedBounds, NotAntiAliased, SkRegion::kInters
ect_Op); | 57 canvas->clipRect(clippedBounds, SkRegion::kIntersect_Op); |
| 52 } | 58 } |
| 53 | 59 |
| 54 CGContextRef cgContext = this->cgContext(); | 60 CGContextRef cgContext = this->cgContext(); |
| 55 if (cgContext == [[NSGraphicsContext currentContext] graphicsPort]) { | 61 if (cgContext == [[NSGraphicsContext currentContext] graphicsPort]) { |
| 56 m_savedNSGraphicsContext = 0; | 62 m_savedNSGraphicsContext = 0; |
| 57 return; | 63 return; |
| 58 } | 64 } |
| 59 | 65 |
| 60 m_savedNSGraphicsContext = [[NSGraphicsContext currentContext] retain]; | 66 m_savedNSGraphicsContext = [[NSGraphicsContext currentContext] retain]; |
| 61 NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphi
csPort:cgContext flipped:YES]; | 67 NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithGraphi
csPort:cgContext flipped:YES]; |
| 62 [NSGraphicsContext setCurrentContext:newContext]; | 68 [NSGraphicsContext setCurrentContext:newContext]; |
| 63 m_didSetGraphicsContext = true; | 69 m_didSetGraphicsContext = true; |
| 64 } | 70 } |
| 65 | 71 |
| 66 LocalCurrentGraphicsContext::~LocalCurrentGraphicsContext() | 72 LocalCurrentGraphicsContext::~LocalCurrentGraphicsContext() |
| 67 { | 73 { |
| 68 if (m_didSetGraphicsContext) { | 74 if (m_didSetGraphicsContext) { |
| 69 [NSGraphicsContext setCurrentContext:m_savedNSGraphicsContext]; | 75 [NSGraphicsContext setCurrentContext:m_savedNSGraphicsContext]; |
| 70 [m_savedNSGraphicsContext release]; | 76 [m_savedNSGraphicsContext release]; |
| 71 } | 77 } |
| 72 | 78 |
| 73 m_savedGraphicsContext->restore(); | 79 m_savedCanvas->restore(); |
| 74 } | 80 } |
| 75 | 81 |
| 76 CGContextRef LocalCurrentGraphicsContext::cgContext() | 82 CGContextRef LocalCurrentGraphicsContext::cgContext() |
| 77 { | 83 { |
| 78 // This synchronizes the CGContext to reflect the current SkCanvas state. | 84 // This synchronizes the CGContext to reflect the current SkCanvas state. |
| 79 // The implementation may not return the same CGContext each time. | 85 // The implementation may not return the same CGContext each time. |
| 80 CGContextRef cgContext = m_skiaBitLocker.cgContext(); | 86 CGContextRef cgContext = m_skiaBitLocker.cgContext(); |
| 81 | 87 |
| 82 return cgContext; | 88 return cgContext; |
| 83 } | 89 } |
| 84 | 90 |
| 85 } | 91 } |
| OLD | NEW |