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

Side by Side Diff: cc/resource_update_controller.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the GrContextProvider::ScopedContexts guard classes Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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/grcontext_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
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
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 GrContextProvider* offscreenContexts = m_resourceProvider->offscreenCont extProvider();
134 WebSharedGraphicsContext3D::compositorThreadContext() : 132 if (!offscreenContexts->has_contexts())
135 WebSharedGraphicsContext3D::mainThreadContext(); 133 return;
136 GrContext* paintGrContext = m_hasImplThread ?
137 WebSharedGraphicsContext3D::compositorThreadGrContext() :
138 WebSharedGraphicsContext3D::mainThreadGrContext();
139 134
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( 135 ResourceProvider::ScopedWriteLockGL lock(
145 m_resourceProvider, texture->resourceId()); 136 m_resourceProvider, texture->resourceId());
146 m_resourceProvider->flush();
147 137
148 // Make sure ganesh uses the correct GL context. 138 // Do this after locking/creating the compositor texture.
149 paintContext->makeContextCurrent(); 139 offscreenContexts->BeginUsingContexts();
150 140
151 // Create an accelerated canvas to draw on. 141 // Create an accelerated canvas to draw on.
152 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas( 142 skia::RefPtr<SkCanvas> canvas = createAcceleratedCanvas(
153 paintGrContext, texture->size(), lock.textureId()); 143 offscreenContexts->gr_context(), texture->size(), lock.textureId());
154 144
155 // The compositor expects the textures to be upside-down so it can flip 145 // 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 146 // the final composited image. Ganesh renders the image upright so we
157 // need to do a y-flip. 147 // need to do a y-flip.
158 canvas->translate(0.0, texture->size().height()); 148 canvas->translate(0.0, texture->size().height());
159 canvas->scale(1.0, -1.0); 149 canvas->scale(1.0, -1.0);
160 // Clip to the destination on the texture that must be updated. 150 // Clip to the destination on the texture that must be updated.
161 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), 151 canvas->clipRect(SkRect::MakeXYWH(destOffset.x(),
162 destOffset.y(), 152 destOffset.y(),
163 sourceRect.width(), 153 sourceRect.width(),
164 sourceRect.height())); 154 sourceRect.height()));
165 // Translate the origin of pictureRect to destOffset. 155 // Translate the origin of pictureRect to destOffset.
166 // Note that destOffset is defined relative to sourceRect. 156 // Note that destOffset is defined relative to sourceRect.
167 canvas->translate( 157 canvas->translate(
168 pictureRect.x() - sourceRect.x() + destOffset.x(), 158 pictureRect.x() - sourceRect.x() + destOffset.x(),
169 pictureRect.y() - sourceRect.y() + destOffset.y()); 159 pictureRect.y() - sourceRect.y() + destOffset.y());
170 canvas->drawPicture(*update.picture); 160 canvas->drawPicture(*update.picture);
171 161 offscreenContexts->FinishUsingContexts();
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 } 162 }
180 163
181 if (update.bitmap) { 164 if (update.bitmap) {
182 update.bitmap->lockPixels(); 165 update.bitmap->lockPixels();
183 update.texture->setPixels( 166 update.texture->setPixels(
184 m_resourceProvider, 167 m_resourceProvider,
185 static_cast<const uint8_t*>(update.bitmap->getPixels()), 168 static_cast<const uint8_t*>(update.bitmap->getPixels()),
186 update.content_rect, 169 update.content_rect,
187 update.source_rect, 170 update.source_rect,
188 update.dest_offset); 171 update.dest_offset);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (!uploads) 266 if (!uploads)
284 return; 267 return;
285 268
286 while (m_queue->fullUploadSize() && uploads--) 269 while (m_queue->fullUploadSize() && uploads--)
287 updateTexture(m_queue->takeFirstFullUpload()); 270 updateTexture(m_queue->takeFirstFullUpload());
288 271
289 m_resourceProvider->flushUploads(); 272 m_resourceProvider->flushUploads();
290 } 273 }
291 274
292 } // namespace cc 275 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698