Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp

Issue 2425113002: Fix the linear-rgb canvas color space so that it renders (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // The id of the texture bound to the CHROMIUM image. 78 // The id of the texture bound to the CHROMIUM image.
79 const GLuint m_textureId; 79 const GLuint m_textureId;
80 }; 80 };
81 #endif // USE_IOSURFACE_FOR_2D_CANVAS 81 #endif // USE_IOSURFACE_FOR_2D_CANVAS
82 82
83 static sk_sp<SkSurface> createSkSurface(GrContext* gr, 83 static sk_sp<SkSurface> createSkSurface(GrContext* gr,
84 const IntSize& size, 84 const IntSize& size,
85 int msaaSampleCount, 85 int msaaSampleCount,
86 OpacityMode opacityMode, 86 OpacityMode opacityMode,
87 sk_sp<SkColorSpace> colorSpace, 87 sk_sp<SkColorSpace> colorSpace,
88 SkColorType colorType,
88 bool* surfaceIsAccelerated) { 89 bool* surfaceIsAccelerated) {
89 if (gr) 90 if (gr)
90 gr->resetContext(); 91 gr->resetContext();
91 92
92 SkAlphaType alphaType = 93 SkAlphaType alphaType =
93 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType; 94 (Opaque == opacityMode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
94 SkImageInfo info = 95 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), colorType,
95 SkImageInfo::MakeN32(size.width(), size.height(), alphaType, colorSpace); 96 alphaType, colorSpace);
96 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); 97 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry);
97 sk_sp<SkSurface> surface; 98 sk_sp<SkSurface> surface;
98 99
99 if (gr) { 100 if (gr) {
100 *surfaceIsAccelerated = true; 101 *surfaceIsAccelerated = true;
101 surface = SkSurface::MakeRenderTarget( 102 surface = SkSurface::MakeRenderTarget(
102 gr, SkBudgeted::kNo, info, msaaSampleCount, 103 gr, SkBudgeted::kNo, info, msaaSampleCount,
103 Opaque == opacityMode ? 0 : &disableLCDProps); 104 Opaque == opacityMode ? 0 : &disableLCDProps);
104 } 105 }
105 106
(...skipping 12 matching lines...) Expand all
118 } 119 }
119 return surface; 120 return surface;
120 } 121 }
121 122
122 Canvas2DLayerBridge::Canvas2DLayerBridge( 123 Canvas2DLayerBridge::Canvas2DLayerBridge(
123 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, 124 std::unique_ptr<WebGraphicsContext3DProvider> contextProvider,
124 const IntSize& size, 125 const IntSize& size,
125 int msaaSampleCount, 126 int msaaSampleCount,
126 OpacityMode opacityMode, 127 OpacityMode opacityMode,
127 AccelerationMode accelerationMode, 128 AccelerationMode accelerationMode,
128 sk_sp<SkColorSpace> colorSpace) 129 sk_sp<SkColorSpace> colorSpace,
130 SkColorType colorType)
129 : m_contextProvider(std::move(contextProvider)), 131 : m_contextProvider(std::move(contextProvider)),
130 m_logger(wrapUnique(new Logger)), 132 m_logger(wrapUnique(new Logger)),
131 m_weakPtrFactory(this), 133 m_weakPtrFactory(this),
132 m_imageBuffer(0), 134 m_imageBuffer(0),
133 m_msaaSampleCount(msaaSampleCount), 135 m_msaaSampleCount(msaaSampleCount),
134 m_bytesAllocated(0), 136 m_bytesAllocated(0),
135 m_haveRecordedDrawCommands(false), 137 m_haveRecordedDrawCommands(false),
136 m_destructionInProgress(false), 138 m_destructionInProgress(false),
137 m_filterQuality(kLow_SkFilterQuality), 139 m_filterQuality(kLow_SkFilterQuality),
138 m_isHidden(false), 140 m_isHidden(false),
139 m_isDeferralEnabled(true), 141 m_isDeferralEnabled(true),
140 m_isRegisteredTaskObserver(false), 142 m_isRegisteredTaskObserver(false),
141 m_renderingTaskCompletedForCurrentFrame(false), 143 m_renderingTaskCompletedForCurrentFrame(false),
142 m_softwareRenderingWhileHidden(false), 144 m_softwareRenderingWhileHidden(false),
143 m_lastImageId(0), 145 m_lastImageId(0),
144 m_lastFilter(GL_LINEAR), 146 m_lastFilter(GL_LINEAR),
145 m_accelerationMode(accelerationMode), 147 m_accelerationMode(accelerationMode),
146 m_opacityMode(opacityMode), 148 m_opacityMode(opacityMode),
147 m_size(size), 149 m_size(size),
148 m_colorSpace(colorSpace) { 150 m_colorSpace(colorSpace),
151 m_colorType(colorType) {
149 DCHECK(m_contextProvider); 152 DCHECK(m_contextProvider);
150 DCHECK(!m_contextProvider->isSoftwareRendering()); 153 DCHECK(!m_contextProvider->isSoftwareRendering());
151 // Used by browser tests to detect the use of a Canvas2DLayerBridge. 154 // Used by browser tests to detect the use of a Canvas2DLayerBridge.
152 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation", 155 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation",
153 TRACE_EVENT_SCOPE_GLOBAL); 156 TRACE_EVENT_SCOPE_GLOBAL);
154 startRecording(); 157 startRecording();
155 } 158 }
156 159
157 Canvas2DLayerBridge::~Canvas2DLayerBridge() { 160 Canvas2DLayerBridge::~Canvas2DLayerBridge() {
158 DCHECK(m_destructionInProgress); 161 DCHECK(m_destructionInProgress);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 bool wantAcceleration = shouldAccelerate(hint); 547 bool wantAcceleration = shouldAccelerate(hint);
545 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() && 548 if (CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU && isHidden() &&
546 wantAcceleration) { 549 wantAcceleration) {
547 wantAcceleration = false; 550 wantAcceleration = false;
548 m_softwareRenderingWhileHidden = true; 551 m_softwareRenderingWhileHidden = true;
549 } 552 }
550 553
551 bool surfaceIsAccelerated; 554 bool surfaceIsAccelerated;
552 m_surface = createSkSurface( 555 m_surface = createSkSurface(
553 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size, 556 wantAcceleration ? m_contextProvider->grContext() : nullptr, m_size,
554 m_msaaSampleCount, m_opacityMode, m_colorSpace, &surfaceIsAccelerated); 557 m_msaaSampleCount, m_opacityMode, m_colorSpace, m_colorType,
558 &surfaceIsAccelerated);
555 559
556 if (m_surface) { 560 if (m_surface) {
557 // Always save an initial frame, to support resetting the top level matrix 561 // Always save an initial frame, to support resetting the top level matrix
558 // and clip. 562 // and clip.
559 m_surface->getCanvas()->save(); 563 m_surface->getCanvas()->save();
560 } else { 564 } else {
561 reportSurfaceCreationFailure(); 565 reportSurfaceCreationFailure();
562 } 566 }
563 567
564 if (m_surface && surfaceIsAccelerated && !m_layer) { 568 if (m_surface && surfaceIsAccelerated && !m_layer) {
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 gpu::gles2::GLES2Interface* sharedGL = nullptr; 847 gpu::gles2::GLES2Interface* sharedGL = nullptr;
844 m_layer->clearTexture(); 848 m_layer->clearTexture();
845 m_contextProvider = wrapUnique( 849 m_contextProvider = wrapUnique(
846 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); 850 Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
847 if (m_contextProvider) 851 if (m_contextProvider)
848 sharedGL = m_contextProvider->contextGL(); 852 sharedGL = m_contextProvider->contextGL();
849 853
850 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) { 854 if (sharedGL && sharedGL->GetGraphicsResetStatusKHR() == GL_NO_ERROR) {
851 GrContext* grCtx = m_contextProvider->grContext(); 855 GrContext* grCtx = m_contextProvider->grContext();
852 bool surfaceIsAccelerated; 856 bool surfaceIsAccelerated;
853 sk_sp<SkSurface> surface(createSkSurface(grCtx, m_size, m_msaaSampleCount, 857 sk_sp<SkSurface> surface(
854 m_opacityMode, m_colorSpace, 858 createSkSurface(grCtx, m_size, m_msaaSampleCount, m_opacityMode,
855 &surfaceIsAccelerated)); 859 m_colorSpace, m_colorType, &surfaceIsAccelerated));
856 860
857 if (!m_surface) 861 if (!m_surface)
858 reportSurfaceCreationFailure(); 862 reportSurfaceCreationFailure();
859 863
860 // The current paradigm does not support switching from accelerated to 864 // The current paradigm does not support switching from accelerated to
861 // non-accelerated, which would be tricky due to changes to the layer tree, 865 // non-accelerated, which would be tricky due to changes to the layer tree,
862 // which can only happen at specific times during the document lifecycle. 866 // which can only happen at specific times during the document lifecycle.
863 // Therefore, we can only accept the restored surface if it is accelerated. 867 // Therefore, we can only accept the restored surface if it is accelerated.
864 if (surface && surfaceIsAccelerated) { 868 if (surface && surfaceIsAccelerated) {
865 m_surface = std::move(surface); 869 m_surface = std::move(surface);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 default; 1136 default;
1133 1137
1134 void Canvas2DLayerBridge::Logger::reportHibernationEvent( 1138 void Canvas2DLayerBridge::Logger::reportHibernationEvent(
1135 HibernationEvent event) { 1139 HibernationEvent event) {
1136 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram, 1140 DEFINE_STATIC_LOCAL(EnumerationHistogram, hibernationHistogram,
1137 ("Canvas.HibernationEvents", HibernationEventCount)); 1141 ("Canvas.HibernationEvents", HibernationEventCount));
1138 hibernationHistogram.count(event); 1142 hibernationHistogram.count(event);
1139 } 1143 }
1140 1144
1141 } // namespace blink 1145 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698