Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 115 |
| 116 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOr Painting) | 116 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOr Painting) |
| 117 : m_canvas(canvas) | 117 : m_canvas(canvas) |
| 118 , m_paintStateStack() | 118 , m_paintStateStack() |
| 119 , m_paintStateIndex(0) | 119 , m_paintStateIndex(0) |
| 120 , m_pendingCanvasSave(false) | 120 , m_pendingCanvasSave(false) |
| 121 , m_annotationMode(0) | 121 , m_annotationMode(0) |
| 122 #if !ASSERT_DISABLED | 122 #if !ASSERT_DISABLED |
| 123 , m_annotationCount(0) | 123 , m_annotationCount(0) |
| 124 , m_layerCount(0) | 124 , m_layerCount(0) |
| 125 , m_saveCount(0) | |
| 126 , m_disableDestructionChecks(false) | |
| 125 #endif | 127 #endif |
| 126 , m_disabledState(disableContextOrPainting) | 128 , m_disabledState(disableContextOrPainting) |
| 127 , m_trackOpaqueRegion(false) | 129 , m_trackOpaqueRegion(false) |
| 128 , m_trackTextRegion(false) | 130 , m_trackTextRegion(false) |
| 129 , m_useHighResMarker(false) | 131 , m_useHighResMarker(false) |
| 130 , m_updatingControlTints(false) | 132 , m_updatingControlTints(false) |
| 131 , m_accelerated(false) | 133 , m_accelerated(false) |
| 132 , m_isCertainlyOpaque(true) | 134 , m_isCertainlyOpaque(true) |
| 133 , m_printing(false) | 135 , m_printing(false) |
| 134 , m_antialiasHairlineImages(false) | 136 , m_antialiasHairlineImages(false) |
| 135 { | 137 { |
| 136 if (!canvas) | 138 if (!canvas) |
| 137 m_disabledState |= PaintingDisabled; | 139 m_disabledState |= PaintingDisabled; |
| 138 | 140 |
| 139 // FIXME: Do some tests to determine how many states are typically used, and allocate | 141 // FIXME: Do some tests to determine how many states are typically used, and allocate |
| 140 // several here. | 142 // several here. |
| 141 m_paintStateStack.append(GraphicsContextState::create()); | 143 m_paintStateStack.append(GraphicsContextState::create()); |
| 142 m_paintState = m_paintStateStack.last().get(); | 144 m_paintState = m_paintStateStack.last().get(); |
| 143 } | 145 } |
| 144 | 146 |
| 145 GraphicsContext::~GraphicsContext() | 147 GraphicsContext::~GraphicsContext() |
| 146 { | 148 { |
| 147 #if !ENABLE(OILPAN) | 149 #if !ASSERT_DISABLED |
| 148 // FIXME: Oilpan: These asserts are not true for | 150 if (!m_disableDestructionChecks) { |
| 149 // CanvasRenderingContext2D. Therefore, there is debug mode code | 151 ASSERT(!m_paintStateIndex); |
| 150 // in the CanvasRenderingContext2D that forces this to be true so | 152 ASSERT(!m_paintState->saveCount()); |
| 151 // that the assertions can be here for all the other cases. With | 153 ASSERT(!m_annotationCount); |
| 152 // Oilpan we cannot run that code in the CanvasRenderingContext2D | 154 ASSERT(!m_layerCount); |
| 153 // destructor because it touches other objects that are already | 155 ASSERT(!m_saveCount); |
| 154 // dead. We need to find another way of doing these asserts when | 156 ASSERT(m_recordingStateStack.isEmpty()); |
| 155 // Oilpan is enabled. | 157 } |
| 156 ASSERT(!m_paintStateIndex); | |
| 157 ASSERT(!m_paintState->saveCount()); | |
| 158 ASSERT(!m_annotationCount); | |
| 159 ASSERT(!m_layerCount); | |
| 160 ASSERT(m_recordingStateStack.isEmpty()); | |
| 161 #endif | 158 #endif |
| 162 } | 159 } |
| 163 | 160 |
| 161 void GraphicsContext::unwindStateStack() | |
| 162 { | |
| 163 while (m_paintStateIndex || m_paintState->saveCount()) | |
| 164 restore(); | |
|
f(malita)
2014/05/27 20:28:22
You can probably drive this off m_canvasStateStack
| |
| 165 } | |
| 166 | |
| 164 void GraphicsContext::save() | 167 void GraphicsContext::save() |
| 165 { | 168 { |
| 166 if (contextDisabled()) | 169 if (contextDisabled()) |
| 167 return; | 170 return; |
| 168 | 171 |
| 169 m_paintState->incrementSaveCount(); | 172 m_paintState->incrementSaveCount(); |
| 170 | 173 |
| 171 m_canvasStateStack.append(CanvasSaveState(m_pendingCanvasSave, m_canvas->get SaveCount())); | 174 m_canvasStateStack.append(CanvasSaveState(m_pendingCanvasSave, m_canvas->get SaveCount())); |
| 172 m_pendingCanvasSave = true; | 175 m_pendingCanvasSave = true; |
| 176 | |
| 177 #if !ASSERT_DISABLED | |
| 178 m_saveCount++; | |
| 179 #endif | |
| 173 } | 180 } |
| 174 | 181 |
| 175 void GraphicsContext::restore() | 182 void GraphicsContext::restore() |
| 176 { | 183 { |
| 177 if (contextDisabled()) | 184 if (contextDisabled()) |
| 178 return; | 185 return; |
| 179 | 186 |
| 180 if (!m_paintStateIndex && !m_paintState->saveCount()) { | 187 if (!m_paintStateIndex && !m_paintState->saveCount()) { |
| 181 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); | 188 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); |
| 182 return; | 189 return; |
| 183 } | 190 } |
| 184 | 191 |
| 185 if (m_paintState->saveCount()) { | 192 if (m_paintState->saveCount()) { |
| 186 m_paintState->decrementSaveCount(); | 193 m_paintState->decrementSaveCount(); |
| 187 } else { | 194 } else { |
| 188 m_paintStateIndex--; | 195 m_paintStateIndex--; |
| 189 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 196 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
| 190 } | 197 } |
| 191 | 198 |
| 192 CanvasSaveState savedState = m_canvasStateStack.last(); | 199 CanvasSaveState savedState = m_canvasStateStack.last(); |
| 193 m_canvasStateStack.removeLast(); | 200 m_canvasStateStack.removeLast(); |
| 194 m_pendingCanvasSave = savedState.m_pendingSave; | 201 m_pendingCanvasSave = savedState.m_pendingSave; |
| 195 m_canvas->restoreToCount(savedState.m_restoreCount); | 202 m_canvas->restoreToCount(savedState.m_restoreCount); |
| 203 #if !ASSERT_DISABLED | |
| 204 m_saveCount--; | |
| 205 #endif | |
| 196 } | 206 } |
| 197 | 207 |
| 198 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) | 208 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 199 { | 209 { |
| 200 if (contextDisabled()) | 210 if (contextDisabled()) |
| 201 return; | 211 return; |
| 202 | 212 |
| 203 realizeCanvasSave(); | 213 realizeCanvasSave(); |
| 204 | 214 |
| 205 m_canvas->saveLayer(bounds, paint); | 215 m_canvas->saveLayer(bounds, paint); |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 | 1856 |
| 1847 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 1857 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
| 1848 { | 1858 { |
| 1849 if (m_trackTextRegion) { | 1859 if (m_trackTextRegion) { |
| 1850 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1860 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
| 1851 m_textRegion.join(textRect); | 1861 m_textRegion.join(textRect); |
| 1852 } | 1862 } |
| 1853 } | 1863 } |
| 1854 | 1864 |
| 1855 } | 1865 } |
| OLD | NEW |