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/ganesh_resource_provider.h" |
10 #include "cc/prioritized_resource.h" | 11 #include "cc/prioritized_resource.h" |
11 #include "cc/resource_provider.h" | 12 #include "cc/resource_provider.h" |
12 #include "cc/texture_copier.h" | 13 #include "cc/texture_copier.h" |
13 #include "cc/thread.h" | 14 #include "cc/thread.h" |
14 #include "skia/ext/refptr.h" | 15 #include "skia/ext/refptr.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 16 #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" | 17 #include "third_party/khronos/GLES2/gl2.h" |
18 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 18 #include "third_party/skia/include/gpu/SkGpuDevice.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 if (!m_resourceProvider->ganeshResourceProvider()->has_contexts()) |
134 WebSharedGraphicsContext3D::compositorThreadContext() : | 132 return; |
135 WebSharedGraphicsContext3D::mainThreadContext(); | 133 |
136 GrContext* paintGrContext = m_hasImplThread ? | 134 ResourceProvider::ScopedWriteLockGL lock( |
137 WebSharedGraphicsContext3D::compositorThreadGrContext() : | 135 m_resourceProvider, texture->resourceId()); |
138 WebSharedGraphicsContext3D::mainThreadGrContext(); | |
139 | 136 |
140 // Flush the context in which the backing texture is created so that it | 137 // 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 | 138 // 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 | 139 // because the backing texture is created in one context while it is |
143 // being written to in another. | 140 // being written to in another. |
144 ResourceProvider::ScopedWriteLockGL lock( | 141 GaneshResourceProvider::ScopedContextsFlushed offscreenContexts( |
145 m_resourceProvider, texture->resourceId()); | 142 m_resourceProvider, m_resourceProvider->ganeshResourceProvider()); |
146 m_resourceProvider->flush(); | |
147 | 143 |
148 // Make sure ganesh uses the correct GL context. | 144 // Make sure ganesh uses the correct GL context. |
149 paintContext->makeContextCurrent(); | 145 offscreenContexts.context3d()->makeContextCurrent(); |
150 | 146 |
151 // Create an accelerated canvas to draw on. | 147 // Create an accelerated canvas to draw on. |
152 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( | 148 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( |
153 paintGrContext, texture->size(), lock.textureId()); | 149 offscreenContexts.gr_context(), texture->size(), lock.textureId()); |
154 | 150 |
155 // The compositor expects the textures to be upside-down so it can flip | 151 // 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 | 152 // the final composited image. Ganesh renders the image upright so we |
157 // need to do a y-flip. | 153 // need to do a y-flip. |
158 canvas->translate(0.0, texture->size().height()); | 154 canvas->translate(0.0, texture->size().height()); |
159 canvas->scale(1.0, -1.0); | 155 canvas->scale(1.0, -1.0); |
160 // Clip to the destination on the texture that must be updated. | 156 // Clip to the destination on the texture that must be updated. |
161 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), | 157 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), |
162 destOffset.y(), | 158 destOffset.y(), |
163 sourceRect.width(), | 159 sourceRect.width(), |
164 sourceRect.height())); | 160 sourceRect.height())); |
165 // Translate the origin of pictureRect to destOffset. | 161 // Translate the origin of pictureRect to destOffset. |
166 // Note that destOffset is defined relative to sourceRect. | 162 // Note that destOffset is defined relative to sourceRect. |
167 canvas->translate( | 163 canvas->translate( |
168 pictureRect.x() - sourceRect.x() + destOffset.x(), | 164 pictureRect.x() - sourceRect.x() + destOffset.x(), |
169 pictureRect.y() - sourceRect.y() + destOffset.y()); | 165 pictureRect.y() - sourceRect.y() + destOffset.y()); |
170 canvas->drawPicture(*update.picture); | 166 canvas->drawPicture(*update.picture); |
171 | |
172 // Flush ganesh context so that all the rendered stuff appears on the | |
173 // texture. | |
174 paintGrContext->flush(); | |
175 | |
176 // Flush the GL context so rendering results from this context are | |
177 // visible in the compositor's context. | |
178 paintContext->flush(); | |
179 } | 167 } |
180 | 168 |
181 if (update.bitmap) { | 169 if (update.bitmap) { |
182 update.bitmap->lockPixels(); | 170 update.bitmap->lockPixels(); |
183 update.texture->setPixels( | 171 update.texture->setPixels( |
184 m_resourceProvider, | 172 m_resourceProvider, |
185 static_cast<const uint8_t*>(update.bitmap->getPixels()), | 173 static_cast<const uint8_t*>(update.bitmap->getPixels()), |
186 update.content_rect, | 174 update.content_rect, |
187 update.source_rect, | 175 update.source_rect, |
188 update.dest_offset); | 176 update.dest_offset); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 if (!uploads) | 271 if (!uploads) |
284 return; | 272 return; |
285 | 273 |
286 while (m_queue->fullUploadSize() && uploads--) | 274 while (m_queue->fullUploadSize() && uploads--) |
287 updateTexture(m_queue->takeFirstFullUpload()); | 275 updateTexture(m_queue->takeFirstFullUpload()); |
288 | 276 |
289 m_resourceProvider->flushUploads(); | 277 m_resourceProvider->flushUploads(); |
290 } | 278 } |
291 | 279 |
292 } // namespace cc | 280 } // namespace cc |
OLD | NEW |