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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 namespace blink { | 67 namespace blink { |
68 | 68 |
69 static PassRefPtr<SkSurface> createSkSurface(GrContext* gr, const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, bool* surfaceIsAccelerated) | 69 static PassRefPtr<SkSurface> createSkSurface(GrContext* gr, const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, bool* surfaceIsAccelerated) |
70 { | 70 { |
71 if (gr) | 71 if (gr) |
72 gr->resetContext(); | 72 gr->resetContext(); |
73 | 73 |
74 SkAlphaType alphaType = (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPre
mul_SkAlphaType; | 74 SkAlphaType alphaType = (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPre
mul_SkAlphaType; |
75 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), alphaTy
pe); | 75 SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), alphaTy
pe); |
76 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); | 76 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); |
77 RefPtr<SkSurface> surface; | 77 sk_sp<SkSurface> surface; |
78 | 78 |
79 if (gr) { | 79 if (gr) { |
80 *surfaceIsAccelerated = true; | 80 *surfaceIsAccelerated = true; |
81 surface = adoptRef(SkSurface::NewRenderTarget(gr, SkBudgeted::kNo, info,
msaaSampleCount, Opaque == opacityMode ? 0 : &disableLCDProps)); | 81 surface = SkSurface::MakeRenderTarget(gr, SkBudgeted::kNo, info, msaaSam
pleCount, Opaque == opacityMode ? 0 : &disableLCDProps); |
82 } | 82 } |
83 | 83 |
84 if (!surface) { | 84 if (!surface) { |
85 *surfaceIsAccelerated = false; | 85 *surfaceIsAccelerated = false; |
86 surface = adoptRef(SkSurface::NewRaster(info, Opaque == opacityMode ? 0
: &disableLCDProps)); | 86 surface = SkSurface::MakeRaster(info, Opaque == opacityMode ? 0 : &disab
leLCDProps); |
87 } | 87 } |
88 | 88 |
89 if (surface) { | 89 if (surface) { |
90 if (opacityMode == Opaque) { | 90 if (opacityMode == Opaque) { |
91 surface->getCanvas()->clear(SK_ColorBLACK); | 91 surface->getCanvas()->clear(SK_ColorBLACK); |
92 } else { | 92 } else { |
93 surface->getCanvas()->clear(SK_ColorTRANSPARENT); | 93 surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
94 } | 94 } |
95 } | 95 } |
96 return surface; | 96 return fromSkSp(surface); |
97 } | 97 } |
98 | 98 |
99 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, AccelerationMode accelerationMode
) | 99 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size,
int msaaSampleCount, OpacityMode opacityMode, AccelerationMode accelerationMode
) |
100 { | 100 { |
101 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", TRACE_EVENT_
SCOPE_GLOBAL); | 101 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", TRACE_EVENT_
SCOPE_GLOBAL); |
102 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu
rrent()->createSharedOffscreenGraphicsContext3DProvider()); | 102 OwnPtr<WebGraphicsContext3DProvider> contextProvider = adoptPtr(Platform::cu
rrent()->createSharedOffscreenGraphicsContext3DProvider()); |
103 if (!contextProvider) | 103 if (!contextProvider) |
104 return nullptr; | 104 return nullptr; |
105 RefPtr<Canvas2DLayerBridge> layerBridge; | 105 RefPtr<Canvas2DLayerBridge> layerBridge; |
106 layerBridge = adoptRef(new Canvas2DLayerBridge(contextProvider.release(), si
ze, msaaSampleCount, opacityMode, accelerationMode)); | 106 layerBridge = adoptRef(new Canvas2DLayerBridge(contextProvider.release(), si
ze, msaaSampleCount, opacityMode, accelerationMode)); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 m_logger->reportHibernationEvent(HibernationAbortedDueGpuContextLoss); | 421 m_logger->reportHibernationEvent(HibernationAbortedDueGpuContextLoss); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
425 if (!isAccelerated()) { | 425 if (!isAccelerated()) { |
426 m_logger->reportHibernationEvent(HibernationAbortedDueToSwitchToUnaccele
ratedRendering); | 426 m_logger->reportHibernationEvent(HibernationAbortedDueToSwitchToUnaccele
ratedRendering); |
427 return; | 427 return; |
428 } | 428 } |
429 | 429 |
430 TRACE_EVENT0("cc", "Canvas2DLayerBridge::hibernate"); | 430 TRACE_EVENT0("cc", "Canvas2DLayerBridge::hibernate"); |
431 RefPtr<SkSurface> tempHibernationSurface = adoptRef(SkSurface::NewRasterN32P
remul(m_size.width(), m_size.height())); | 431 sk_sp<SkSurface> tempHibernationSurface = SkSurface::MakeRasterN32Premul(m_s
ize.width(), m_size.height()); |
432 if (!tempHibernationSurface) { | 432 if (!tempHibernationSurface) { |
433 m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailur
e); | 433 m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailur
e); |
434 return; | 434 return; |
435 } | 435 } |
436 // No HibernationEvent reported on success. This is on purppose to avoid | 436 // No HibernationEvent reported on success. This is on purppose to avoid |
437 // non-complementary stats. Each HibernationScheduled event is paired with | 437 // non-complementary stats. Each HibernationScheduled event is paired with |
438 // exactly one failure or exit event. | 438 // exactly one failure or exit event. |
439 flushRecordingOnly(); | 439 flushRecordingOnly(); |
440 // The following checks that the flush succeeded, which should always be the | 440 // The following checks that the flush succeeded, which should always be the |
441 // case because flushRecordingOnly should only fail it it fails to allocate | 441 // case because flushRecordingOnly should only fail it it fails to allocate |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 #endif // USE_IOSURFACE_FOR_2D_CANVAS | 999 #endif // USE_IOSURFACE_FOR_2D_CANVAS |
1000 } | 1000 } |
1001 | 1001 |
1002 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 1002 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
1003 { | 1003 { |
1004 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); | 1004 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, ("Canvas.Hib
ernationEvents", HibernationEventCount)); |
1005 hibernationHistogram.count(event); | 1005 hibernationHistogram.count(event); |
1006 } | 1006 } |
1007 | 1007 |
1008 } // namespace blink | 1008 } // namespace blink |
OLD | NEW |