OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 DCHECK_EQ(static_cast<size_t>(sk_canvas->getSaveCount()), | 160 DCHECK_EQ(static_cast<size_t>(sk_canvas->getSaveCount()), |
161 state_stack_.size() + 1); | 161 state_stack_.size() + 1); |
162 } | 162 } |
163 } | 163 } |
164 #endif | 164 #endif |
165 CHECK(state_stack_.front() | 165 CHECK(state_stack_.front() |
166 .Get()); // Temporary for investigating crbug.com/648510 | 166 .Get()); // Temporary for investigating crbug.com/648510 |
167 } | 167 } |
168 | 168 |
169 bool CanvasRenderingContext2D::IsAccelerated() const { | 169 bool CanvasRenderingContext2D::IsAccelerated() const { |
170 if (!canvas()->HasImageBuffer()) | 170 if (!host()->HasImageBuffer()) |
171 return false; | 171 return false; |
172 return canvas()->Buffer()->IsAccelerated(); | 172 return host()->GetImageBuffer()->IsAccelerated(); |
173 } | 173 } |
174 | 174 |
175 bool CanvasRenderingContext2D::IsComposited() const { | 175 bool CanvasRenderingContext2D::IsComposited() const { |
176 return IsAccelerated(); | 176 return IsAccelerated(); |
177 } | 177 } |
178 | 178 |
179 void CanvasRenderingContext2D::Stop() { | 179 void CanvasRenderingContext2D::Stop() { |
180 if (!isContextLost()) { | 180 if (!isContextLost()) { |
181 // Never attempt to restore the context because the page is being torn down. | 181 // Never attempt to restore the context because the page is being torn down. |
182 LoseContext(kSyntheticLostContext); | 182 LoseContext(kSyntheticLostContext); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 bool CanvasRenderingContext2D::isContextLost() const { | 186 bool CanvasRenderingContext2D::isContextLost() const { |
187 return context_lost_mode_ != kNotLostContext; | 187 return context_lost_mode_ != kNotLostContext; |
188 } | 188 } |
189 | 189 |
190 void CanvasRenderingContext2D::LoseContext(LostContextMode lost_mode) { | 190 void CanvasRenderingContext2D::LoseContext(LostContextMode lost_mode) { |
191 if (context_lost_mode_ != kNotLostContext) | 191 if (context_lost_mode_ != kNotLostContext) |
192 return; | 192 return; |
193 context_lost_mode_ = lost_mode; | 193 context_lost_mode_ = lost_mode; |
194 if (context_lost_mode_ == kSyntheticLostContext && canvas()) { | 194 if (context_lost_mode_ == kSyntheticLostContext && canvas()) { |
195 canvas()->DiscardImageBuffer(); | 195 host()->DiscardImageBuffer(); |
196 } | 196 } |
197 dispatch_context_lost_event_timer_.StartOneShot(0, BLINK_FROM_HERE); | 197 dispatch_context_lost_event_timer_.StartOneShot(0, BLINK_FROM_HERE); |
198 } | 198 } |
199 | 199 |
200 void CanvasRenderingContext2D::DidSetSurfaceSize() { | 200 void CanvasRenderingContext2D::DidSetSurfaceSize() { |
201 if (!context_restorable_) | 201 if (!context_restorable_) |
202 return; | 202 return; |
203 // This code path is for restoring from an eviction | 203 // This code path is for restoring from an eviction |
204 // Restoring from surface failure is handled internally | 204 // Restoring from surface failure is handled internally |
205 DCHECK(context_lost_mode_ != kNotLostContext && !canvas()->HasImageBuffer()); | 205 DCHECK(context_lost_mode_ != kNotLostContext && !host()->HasImageBuffer()); |
206 | 206 |
207 if (canvas()->Buffer()) { | 207 if (host()->GetImageBuffer()) { |
208 if (ContextLostRestoredEventsEnabled()) { | 208 if (ContextLostRestoredEventsEnabled()) { |
209 dispatch_context_restored_event_timer_.StartOneShot(0, BLINK_FROM_HERE); | 209 dispatch_context_restored_event_timer_.StartOneShot(0, BLINK_FROM_HERE); |
210 } else { | 210 } else { |
211 // legacy synchronous context restoration. | 211 // legacy synchronous context restoration. |
212 Reset(); | 212 Reset(); |
213 context_lost_mode_ = kNotLostContext; | 213 context_lost_mode_ = kNotLostContext; |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
(...skipping 25 matching lines...) Expand all Loading... |
243 | 243 |
244 void CanvasRenderingContext2D::TryRestoreContextEvent(TimerBase* timer) { | 244 void CanvasRenderingContext2D::TryRestoreContextEvent(TimerBase* timer) { |
245 if (context_lost_mode_ == kNotLostContext) { | 245 if (context_lost_mode_ == kNotLostContext) { |
246 // Canvas was already restored (possibly thanks to a resize), so stop | 246 // Canvas was already restored (possibly thanks to a resize), so stop |
247 // trying. | 247 // trying. |
248 try_restore_context_event_timer_.Stop(); | 248 try_restore_context_event_timer_.Stop(); |
249 return; | 249 return; |
250 } | 250 } |
251 | 251 |
252 DCHECK(context_lost_mode_ == kRealLostContext); | 252 DCHECK(context_lost_mode_ == kRealLostContext); |
253 if (canvas()->HasImageBuffer() && canvas()->Buffer()->RestoreSurface()) { | 253 if (host()->HasImageBuffer() && host()->GetImageBuffer()->RestoreSurface()) { |
254 try_restore_context_event_timer_.Stop(); | 254 try_restore_context_event_timer_.Stop(); |
255 DispatchContextRestoredEvent(nullptr); | 255 DispatchContextRestoredEvent(nullptr); |
256 } | 256 } |
257 | 257 |
258 if (++try_restore_context_attempt_count_ > kMaxTryRestoreContextAttempts) { | 258 if (++try_restore_context_attempt_count_ > kMaxTryRestoreContextAttempts) { |
259 // final attempt: allocate a brand new image buffer instead of restoring | 259 // final attempt: allocate a brand new image buffer instead of restoring |
260 canvas()->DiscardImageBuffer(); | 260 host()->DiscardImageBuffer(); |
261 try_restore_context_event_timer_.Stop(); | 261 try_restore_context_event_timer_.Stop(); |
262 if (canvas()->Buffer()) | 262 if (host()->GetImageBuffer()) |
263 DispatchContextRestoredEvent(nullptr); | 263 DispatchContextRestoredEvent(nullptr); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 void CanvasRenderingContext2D::DispatchContextRestoredEvent(TimerBase*) { | 267 void CanvasRenderingContext2D::DispatchContextRestoredEvent(TimerBase*) { |
268 if (context_lost_mode_ == kNotLostContext) | 268 if (context_lost_mode_ == kNotLostContext) |
269 return; | 269 return; |
270 Reset(); | 270 Reset(); |
271 context_lost_mode_ = kNotLostContext; | 271 context_lost_mode_ = kNotLostContext; |
272 if (ContextLostRestoredEventsEnabled()) { | 272 if (ContextLostRestoredEventsEnabled()) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 hit_region_manager_->RemoveHitRegionsInRect(rect, GetState().Transform()); | 361 hit_region_manager_->RemoveHitRegionsInRect(rect, GetState().Transform()); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 void CanvasRenderingContext2D::DidDraw(const SkIRect& dirty_rect) { | 365 void CanvasRenderingContext2D::DidDraw(const SkIRect& dirty_rect) { |
366 if (dirty_rect.isEmpty()) | 366 if (dirty_rect.isEmpty()) |
367 return; | 367 return; |
368 | 368 |
369 if (ExpensiveCanvasHeuristicParameters::kBlurredShadowsAreExpensive && | 369 if (ExpensiveCanvasHeuristicParameters::kBlurredShadowsAreExpensive && |
370 GetState().ShouldDrawShadows() && GetState().ShadowBlur() > 0) { | 370 GetState().ShouldDrawShadows() && GetState().ShadowBlur() > 0) { |
371 ImageBuffer* buffer = canvas()->Buffer(); | 371 ImageBuffer* buffer = host()->GetImageBuffer(); |
372 if (buffer) | 372 if (buffer) |
373 buffer->SetHasExpensiveOp(); | 373 buffer->SetHasExpensiveOp(); |
374 } | 374 } |
375 | 375 |
376 CanvasRenderingContext::DidDraw(dirty_rect); | 376 CanvasRenderingContext::DidDraw(dirty_rect); |
377 } | 377 } |
378 | 378 |
379 bool CanvasRenderingContext2D::StateHasFilter() { | 379 bool CanvasRenderingContext2D::StateHasFilter() { |
380 return GetState().HasFilter(canvas(), canvas()->Size(), this); | 380 return GetState().HasFilter(canvas(), canvas()->Size(), this); |
381 } | 381 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 595 |
596 int CanvasRenderingContext2D::Width() const { | 596 int CanvasRenderingContext2D::Width() const { |
597 return canvas()->width(); | 597 return canvas()->width(); |
598 } | 598 } |
599 | 599 |
600 int CanvasRenderingContext2D::Height() const { | 600 int CanvasRenderingContext2D::Height() const { |
601 return canvas()->height(); | 601 return canvas()->height(); |
602 } | 602 } |
603 | 603 |
604 bool CanvasRenderingContext2D::HasImageBuffer() const { | 604 bool CanvasRenderingContext2D::HasImageBuffer() const { |
605 return canvas()->HasImageBuffer(); | 605 return host()->HasImageBuffer(); |
606 } | 606 } |
607 | 607 |
608 ImageBuffer* CanvasRenderingContext2D::GetImageBuffer() const { | 608 ImageBuffer* CanvasRenderingContext2D::GetImageBuffer() const { |
609 return canvas()->Buffer(); | 609 return host()->GetImageBuffer(); |
610 } | 610 } |
611 | 611 |
612 PassRefPtr<Image> blink::CanvasRenderingContext2D::GetImage( | 612 PassRefPtr<Image> blink::CanvasRenderingContext2D::GetImage( |
613 AccelerationHint hint, | 613 AccelerationHint hint, |
614 SnapshotReason reason) const { | 614 SnapshotReason reason) const { |
615 if (!HasImageBuffer()) | 615 if (!HasImageBuffer()) |
616 return nullptr; | 616 return nullptr; |
617 return canvas()->Buffer()->NewImageSnapshot(hint, reason); | 617 return host()->GetImageBuffer()->NewImageSnapshot(hint, reason); |
618 } | 618 } |
619 | 619 |
620 bool CanvasRenderingContext2D::ParseColorOrCurrentColor( | 620 bool CanvasRenderingContext2D::ParseColorOrCurrentColor( |
621 Color& color, | 621 Color& color, |
622 const String& color_string) const { | 622 const String& color_string) const { |
623 return ::blink::ParseColorOrCurrentColor(color, color_string, canvas()); | 623 return ::blink::ParseColorOrCurrentColor(color, color_string, canvas()); |
624 } | 624 } |
625 | 625 |
626 HitTestCanvasResult* CanvasRenderingContext2D::GetControlAndIdIfHitRegionExists( | 626 HitTestCanvasResult* CanvasRenderingContext2D::GetControlAndIdIfHitRegionExists( |
627 const LayoutPoint& location) { | 627 const LayoutPoint& location) { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 : -font_metrics.Descent() + font_metrics.Height() / 2; | 972 : -font_metrics.Descent() + font_metrics.Height() / 2; |
973 case kAlphabeticTextBaseline: | 973 case kAlphabeticTextBaseline: |
974 default: | 974 default: |
975 // Do nothing. | 975 // Do nothing. |
976 break; | 976 break; |
977 } | 977 } |
978 return 0; | 978 return 0; |
979 } | 979 } |
980 | 980 |
981 void CanvasRenderingContext2D::SetIsHidden(bool hidden) { | 981 void CanvasRenderingContext2D::SetIsHidden(bool hidden) { |
982 if (canvas()->HasImageBuffer()) | 982 if (host()->HasImageBuffer()) |
983 canvas()->Buffer()->SetIsHidden(hidden); | 983 host()->GetImageBuffer()->SetIsHidden(hidden); |
984 if (hidden) { | 984 if (hidden) { |
985 PruneLocalFontCache(0); | 985 PruneLocalFontCache(0); |
986 } | 986 } |
987 } | 987 } |
988 | 988 |
989 bool CanvasRenderingContext2D::IsTransformInvertible() const { | 989 bool CanvasRenderingContext2D::IsTransformInvertible() const { |
990 return GetState().IsTransformInvertible(); | 990 return GetState().IsTransformInvertible(); |
991 } | 991 } |
992 | 992 |
993 WebLayer* CanvasRenderingContext2D::PlatformLayer() const { | 993 WebLayer* CanvasRenderingContext2D::PlatformLayer() const { |
994 return canvas()->Buffer() ? canvas()->Buffer()->PlatformLayer() : 0; | 994 return host()->GetImageBuffer() ? host()->GetImageBuffer()->PlatformLayer() |
| 995 : 0; |
995 } | 996 } |
996 | 997 |
997 void CanvasRenderingContext2D::getContextAttributes( | 998 void CanvasRenderingContext2D::getContextAttributes( |
998 CanvasRenderingContext2DSettings& settings) const { | 999 CanvasRenderingContext2DSettings& settings) const { |
999 settings.setAlpha(CreationAttributes().alpha()); | 1000 settings.setAlpha(CreationAttributes().alpha()); |
1000 settings.setColorSpace(ColorSpaceAsString()); | 1001 settings.setColorSpace(ColorSpaceAsString()); |
1001 settings.setPixelFormat(PixelFormatAsString()); | 1002 settings.setPixelFormat(PixelFormatAsString()); |
1002 settings.setLinearPixelMath(color_params().LinearPixelMath()); | 1003 settings.setLinearPixelMath(color_params().LinearPixelMath()); |
1003 } | 1004 } |
1004 | 1005 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 } | 1190 } |
1190 return true; | 1191 return true; |
1191 } | 1192 } |
1192 | 1193 |
1193 void CanvasRenderingContext2D::ResetUsageTracking() { | 1194 void CanvasRenderingContext2D::ResetUsageTracking() { |
1194 UsageCounters new_counters; | 1195 UsageCounters new_counters; |
1195 usage_counters_ = new_counters; | 1196 usage_counters_ = new_counters; |
1196 } | 1197 } |
1197 | 1198 |
1198 } // namespace blink | 1199 } // namespace blink |
OLD | NEW |