OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resource_update_controller.h" | 5 #include "cc/resource_update_controller.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "cc/prioritized_resource.h" | 10 #include "cc/prioritized_resource.h" |
11 #include "cc/resource_provider.h" | 11 #include "cc/resource_provider.h" |
12 #include "cc/texture_copier.h" | 12 #include "cc/texture_copier.h" |
13 #include "cc/thread.h" | 13 #include "cc/thread.h" |
14 #include "skia/ext/refptr.h" | 14 #include "skia/ext/refptr.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo
ntext3D.h" | |
17 #include "third_party/khronos/GLES2/gl2.h" | 16 #include "third_party/khronos/GLES2/gl2.h" |
18 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 17 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 18 #include "ui/gl/context_provider.h" |
19 | 19 |
20 using WebKit::WebGraphicsContext3D; | 20 using WebKit::WebGraphicsContext3D; |
21 using WebKit::WebSharedGraphicsContext3D; | |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 // Number of partial updates we allow. | 24 // Number of partial updates we allow. |
26 const size_t partialTextureUpdatesMax = 12; | 25 const size_t partialTextureUpdatesMax = 12; |
27 | 26 |
28 // Measured in seconds. | 27 // Measured in seconds. |
29 const double textureUpdateTickRate = 0.004; | 28 const double textureUpdateTickRate = 0.004; |
30 | 29 |
31 // Measured in seconds. | 30 // Measured in seconds. |
(...skipping 28 matching lines...) Expand all Loading... |
60 } | 59 } |
61 | 60 |
62 size_t ResourceUpdateController::maxFullUpdatesPerTick( | 61 size_t ResourceUpdateController::maxFullUpdatesPerTick( |
63 ResourceProvider* resourceProvider) | 62 ResourceProvider* resourceProvider) |
64 { | 63 { |
65 double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond(); | 64 double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond(); |
66 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); | 65 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); |
67 return texturesPerTick ? texturesPerTick : 1; | 66 return texturesPerTick ? texturesPerTick : 1; |
68 } | 67 } |
69 | 68 |
70 ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClien
t* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvid
er* resourceProvider, bool hasImplThread) | 69 ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClien
t* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvid
er* resourceProvider) |
71 : m_client(client) | 70 : m_client(client) |
72 , m_hasImplThread(hasImplThread) | |
73 , m_queue(queue.Pass()) | 71 , m_queue(queue.Pass()) |
74 , m_resourceProvider(resourceProvider) | 72 , m_resourceProvider(resourceProvider) |
75 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider)) | 73 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider)) |
76 , m_firstUpdateAttempt(true) | 74 , m_firstUpdateAttempt(true) |
77 , m_thread(thread) | 75 , m_thread(thread) |
78 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) | 76 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
79 , m_taskPosted(false) | 77 , m_taskPosted(false) |
80 { | 78 { |
81 } | 79 } |
82 | 80 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 gfx::Rect pictureRect = update.content_rect; | 121 gfx::Rect pictureRect = update.content_rect; |
124 gfx::Rect sourceRect = update.source_rect; | 122 gfx::Rect sourceRect = update.source_rect; |
125 gfx::Vector2d destOffset = update.dest_offset; | 123 gfx::Vector2d destOffset = update.dest_offset; |
126 | 124 |
127 texture->acquireBackingTexture(m_resourceProvider); | 125 texture->acquireBackingTexture(m_resourceProvider); |
128 DCHECK(texture->haveBackingTexture()); | 126 DCHECK(texture->haveBackingTexture()); |
129 | 127 |
130 DCHECK(m_resourceProvider->resourceType(texture->resourceId()) == | 128 DCHECK(m_resourceProvider->resourceType(texture->resourceId()) == |
131 ResourceProvider::GLTexture); | 129 ResourceProvider::GLTexture); |
132 | 130 |
133 WebGraphicsContext3D* paintContext = m_hasImplThread ? | 131 ui::ContextProvider* offscreenContexts = m_resourceProvider->offscreenCo
ntextProvider(); |
134 WebSharedGraphicsContext3D::compositorThreadContext() : | |
135 WebSharedGraphicsContext3D::mainThreadContext(); | |
136 GrContext* paintGrContext = m_hasImplThread ? | |
137 WebSharedGraphicsContext3D::compositorThreadGrContext() : | |
138 WebSharedGraphicsContext3D::mainThreadGrContext(); | |
139 | 132 |
140 // Flush the context in which the backing texture is created so that it | |
141 // is available in other shared contexts. It is important to do here | |
142 // because the backing texture is created in one context while it is | |
143 // being written to in another. | |
144 ResourceProvider::ScopedWriteLockGL lock( | 133 ResourceProvider::ScopedWriteLockGL lock( |
145 m_resourceProvider, texture->resourceId()); | 134 m_resourceProvider, texture->resourceId()); |
| 135 |
| 136 // Flush the compositor context to ensure that textures there are availa
ble |
| 137 // in the shared context. Do this after locking/creating the compositor |
| 138 // texture. |
146 m_resourceProvider->flush(); | 139 m_resourceProvider->flush(); |
147 | 140 |
148 // Make sure ganesh uses the correct GL context. | 141 // Make sure ganesh uses the correct GL context. |
149 paintContext->makeContextCurrent(); | 142 offscreenContexts->Context3d()->makeContextCurrent(); |
150 | 143 |
151 // Create an accelerated canvas to draw on. | 144 // Create an accelerated canvas to draw on. |
152 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( | 145 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( |
153 paintGrContext, texture->size(), lock.textureId()); | 146 offscreenContexts->GrContext(), texture->size(), lock.textureId()); |
154 | 147 |
155 // The compositor expects the textures to be upside-down so it can flip | 148 // The compositor expects the textures to be upside-down so it can flip |
156 // the final composited image. Ganesh renders the image upright so we | 149 // the final composited image. Ganesh renders the image upright so we |
157 // need to do a y-flip. | 150 // need to do a y-flip. |
158 canvas->translate(0.0, texture->size().height()); | 151 canvas->translate(0.0, texture->size().height()); |
159 canvas->scale(1.0, -1.0); | 152 canvas->scale(1.0, -1.0); |
160 // Clip to the destination on the texture that must be updated. | 153 // Clip to the destination on the texture that must be updated. |
161 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), | 154 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), |
162 destOffset.y(), | 155 destOffset.y(), |
163 sourceRect.width(), | 156 sourceRect.width(), |
164 sourceRect.height())); | 157 sourceRect.height())); |
165 // Translate the origin of pictureRect to destOffset. | 158 // Translate the origin of pictureRect to destOffset. |
166 // Note that destOffset is defined relative to sourceRect. | 159 // Note that destOffset is defined relative to sourceRect. |
167 canvas->translate( | 160 canvas->translate( |
168 pictureRect.x() - sourceRect.x() + destOffset.x(), | 161 pictureRect.x() - sourceRect.x() + destOffset.x(), |
169 pictureRect.y() - sourceRect.y() + destOffset.y()); | 162 pictureRect.y() - sourceRect.y() + destOffset.y()); |
170 canvas->drawPicture(*update.picture); | 163 canvas->drawPicture(*update.picture); |
171 | 164 |
172 // Flush ganesh context so that all the rendered stuff appears on the | 165 // Flush ganesh context so that all the rendered stuff appears on the |
173 // texture. | 166 // texture. |
174 paintGrContext->flush(); | 167 offscreenContexts->GrContext()->flush(); |
175 | 168 |
176 // Flush the GL context so rendering results from this context are | 169 // Flush the GL context so rendering results from this context are |
177 // visible in the compositor's context. | 170 // visible in the compositor's context. |
178 paintContext->flush(); | 171 offscreenContexts->Context3d()->flush(); |
179 } | 172 } |
180 | 173 |
181 if (update.bitmap) { | 174 if (update.bitmap) { |
182 update.bitmap->lockPixels(); | 175 update.bitmap->lockPixels(); |
183 update.texture->setPixels( | 176 update.texture->setPixels( |
184 m_resourceProvider, | 177 m_resourceProvider, |
185 static_cast<const uint8_t*>(update.bitmap->getPixels()), | 178 static_cast<const uint8_t*>(update.bitmap->getPixels()), |
186 update.content_rect, | 179 update.content_rect, |
187 update.source_rect, | 180 update.source_rect, |
188 update.dest_offset); | 181 update.dest_offset); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (!uploads) | 276 if (!uploads) |
284 return; | 277 return; |
285 | 278 |
286 while (m_queue->fullUploadSize() && uploads--) | 279 while (m_queue->fullUploadSize() && uploads--) |
287 updateTexture(m_queue->takeFirstFullUpload()); | 280 updateTexture(m_queue->takeFirstFullUpload()); |
288 | 281 |
289 m_resourceProvider->flushUploads(); | 282 m_resourceProvider->flushUploads(); |
290 } | 283 } |
291 | 284 |
292 } // namespace cc | 285 } // namespace cc |
OLD | NEW |