| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 gfx::Rect pictureRect = update.content_rect; | 122 gfx::Rect pictureRect = update.content_rect; |
| 124 gfx::Rect sourceRect = update.source_rect; | 123 gfx::Rect sourceRect = update.source_rect; |
| 125 gfx::Vector2d destOffset = update.dest_offset; | 124 gfx::Vector2d destOffset = update.dest_offset; |
| 126 | 125 |
| 127 texture->acquireBackingTexture(m_resourceProvider); | 126 texture->acquireBackingTexture(m_resourceProvider); |
| 128 DCHECK(texture->haveBackingTexture()); | 127 DCHECK(texture->haveBackingTexture()); |
| 129 | 128 |
| 130 DCHECK(m_resourceProvider->resourceType(texture->resourceId()) == | 129 DCHECK(m_resourceProvider->resourceType(texture->resourceId()) == |
| 131 ResourceProvider::GLTexture); | 130 ResourceProvider::GLTexture); |
| 132 | 131 |
| 133 WebGraphicsContext3D* paintContext = m_hasImplThread ? | 132 if (!m_resourceProvider->ganeshResourceProvider()->has_contexts()) |
| 134 WebSharedGraphicsContext3D::compositorThreadContext() : | 133 return; |
| 135 WebSharedGraphicsContext3D::mainThreadContext(); | 134 |
| 136 GrContext* paintGrContext = m_hasImplThread ? | 135 ResourceProvider::ScopedWriteLockGL lock( |
| 137 WebSharedGraphicsContext3D::compositorThreadGrContext() : | 136 m_resourceProvider, texture->resourceId()); |
| 138 WebSharedGraphicsContext3D::mainThreadGrContext(); | |
| 139 | 137 |
| 140 // Flush the context in which the backing texture is created so that it | 138 // 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 | 139 // 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 | 140 // because the backing texture is created in one context while it is |
| 143 // being written to in another. | 141 // being written to in another. |
| 144 ResourceProvider::ScopedWriteLockGL lock( | 142 GaneshResourceProvider::ScopedContextsFlushed offscreenContexts( |
| 145 m_resourceProvider, texture->resourceId()); | 143 m_resourceProvider, m_resourceProvider->ganeshResourceProvider()); |
| 146 m_resourceProvider->flush(); | |
| 147 | 144 |
| 148 // Make sure ganesh uses the correct GL context. | 145 // Make sure ganesh uses the correct GL context. |
| 149 paintContext->makeContextCurrent(); | 146 offscreenContexts.context3d()->makeContextCurrent(); |
| 150 | 147 |
| 151 // Create an accelerated canvas to draw on. | 148 // Create an accelerated canvas to draw on. |
| 152 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( | 149 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( |
| 153 paintGrContext, texture->size(), lock.textureId()); | 150 offscreenContexts.gr_context(), texture->size(), lock.textureId()); |
| 154 | 151 |
| 155 // The compositor expects the textures to be upside-down so it can flip | 152 // 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 | 153 // the final composited image. Ganesh renders the image upright so we |
| 157 // need to do a y-flip. | 154 // need to do a y-flip. |
| 158 canvas->translate(0.0, texture->size().height()); | 155 canvas->translate(0.0, texture->size().height()); |
| 159 canvas->scale(1.0, -1.0); | 156 canvas->scale(1.0, -1.0); |
| 160 // Clip to the destination on the texture that must be updated. | 157 // Clip to the destination on the texture that must be updated. |
| 161 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), | 158 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), |
| 162 destOffset.y(), | 159 destOffset.y(), |
| 163 sourceRect.width(), | 160 sourceRect.width(), |
| 164 sourceRect.height())); | 161 sourceRect.height())); |
| 165 // Translate the origin of pictureRect to destOffset. | 162 // Translate the origin of pictureRect to destOffset. |
| 166 // Note that destOffset is defined relative to sourceRect. | 163 // Note that destOffset is defined relative to sourceRect. |
| 167 canvas->translate( | 164 canvas->translate( |
| 168 pictureRect.x() - sourceRect.x() + destOffset.x(), | 165 pictureRect.x() - sourceRect.x() + destOffset.x(), |
| 169 pictureRect.y() - sourceRect.y() + destOffset.y()); | 166 pictureRect.y() - sourceRect.y() + destOffset.y()); |
| 170 canvas->drawPicture(*update.picture); | 167 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 } | 168 } |
| 180 | 169 |
| 181 if (update.bitmap) { | 170 if (update.bitmap) { |
| 182 update.bitmap->lockPixels(); | 171 update.bitmap->lockPixels(); |
| 183 update.texture->setPixels( | 172 update.texture->setPixels( |
| 184 m_resourceProvider, | 173 m_resourceProvider, |
| 185 static_cast<const uint8_t*>(update.bitmap->getPixels()), | 174 static_cast<const uint8_t*>(update.bitmap->getPixels()), |
| 186 update.content_rect, | 175 update.content_rect, |
| 187 update.source_rect, | 176 update.source_rect, |
| 188 update.dest_offset); | 177 update.dest_offset); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (!uploads) | 272 if (!uploads) |
| 284 return; | 273 return; |
| 285 | 274 |
| 286 while (m_queue->fullUploadSize() && uploads--) | 275 while (m_queue->fullUploadSize() && uploads--) |
| 287 updateTexture(m_queue->takeFirstFullUpload()); | 276 updateTexture(m_queue->takeFirstFullUpload()); |
| 288 | 277 |
| 289 m_resourceProvider->flushUploads(); | 278 m_resourceProvider->flushUploads(); |
| 290 } | 279 } |
| 291 | 280 |
| 292 } // namespace cc | 281 } // namespace cc |
| OLD | NEW |