diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 19:48:47 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 19:48:47 +0000 |
commit | b375853a5b2305fe3cc689e2b3712bf42258ef4d (patch) | |
tree | ed1707a941a96624ba442f4360b736e5416a3158 | |
parent | b2b06c4f160763133874468c5f6715afc8832e06 (diff) | |
download | chromium_src-b375853a5b2305fe3cc689e2b3712bf42258ef4d.zip chromium_src-b375853a5b2305fe3cc689e2b3712bf42258ef4d.tar.gz chromium_src-b375853a5b2305fe3cc689e2b3712bf42258ef4d.tar.bz2 |
Remove static thread pointers from CC
BUG=152904
Review URL: https://codereview.chromium.org/11232051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165476 0039d316-1c4b-4281-b951-d872f2087c98
69 files changed, 774 insertions, 835 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index 963f841..255c699 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -59,6 +59,8 @@ 'test/fake_graphics_context_3d_unittest.cc', 'test/fake_layer_tree_host_client.cc', 'test/fake_layer_tree_host_client.h', + 'test/fake_proxy.cc', + 'test/fake_proxy.h', 'test/fake_web_compositor_output_surface.h', 'test/fake_web_compositor_software_output_device.h', 'test/fake_web_graphics_context_3d.h', diff --git a/cc/damage_tracker_unittest.cc b/cc/damage_tracker_unittest.cc index 22280e4..a2d5a44 100644 --- a/cc/damage_tracker_unittest.cc +++ b/cc/damage_tracker_unittest.cc @@ -165,9 +165,6 @@ scoped_ptr<LayerImpl> createAndSetUpTestTreeWithTwoSurfaces() } class DamageTrackerTest : public testing::Test { -private: - // For testing purposes, fake that we are on the impl thread. - DebugScopedSetImplThread setImplThread; }; TEST_F(DamageTrackerTest, sanityCheckTestTreeWithOneSurface) diff --git a/cc/delegated_renderer_layer_impl_unittest.cc b/cc/delegated_renderer_layer_impl_unittest.cc index 23df876..772f292 100644 --- a/cc/delegated_renderer_layer_impl_unittest.cc +++ b/cc/delegated_renderer_layer_impl_unittest.cc @@ -14,6 +14,7 @@ #include "cc/single_thread_proxy.h" #include "cc/solid_color_draw_quad.h" #include "cc/solid_color_layer_impl.h" +#include "cc/test/fake_proxy.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/geometry_test_utils.h" @@ -34,11 +35,13 @@ namespace { class DelegatedRendererLayerImplTest : public testing::Test, public LayerTreeHostImplClient { public: DelegatedRendererLayerImplTest() + : m_proxy(scoped_ptr<Thread>(NULL)) + , m_alwaysImplThreadAndMainThreadBlocked(&m_proxy) { LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - m_hostImpl = LayerTreeHostImpl::create(settings, this); + m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); m_hostImpl->initializeRenderer(createContext()); m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); } @@ -60,9 +63,8 @@ protected: return FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3D)).PassAs<GraphicsContext>(); } - DebugScopedSetImplThread m_alwaysImplThread; - DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked; - + FakeProxy m_proxy; + DebugScopedSetImplThreadAndMainThreadBlocked m_alwaysImplThreadAndMainThreadBlocked; scoped_ptr<LayerTreeHostImpl> m_hostImpl; }; diff --git a/cc/font_atlas.cc b/cc/font_atlas.cc index 2d15766..2f18e02 100644 --- a/cc/font_atlas.cc +++ b/cc/font_atlas.cc @@ -28,7 +28,7 @@ FontAtlas::~FontAtlas() void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::string& text, const gfx::Point& destPosition, const gfx::Size& clip) const { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); std::vector<std::string> lines; base::SplitString(text, '\n', &lines); @@ -44,7 +44,7 @@ void FontAtlas::drawText(SkCanvas* canvas, const SkPaint& paint, const std::stri void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint, const std::string& textLine, const gfx::Point& destPosition) const { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); gfx::Point position = destPosition; for (unsigned i = 0; i < textLine.length(); ++i) { @@ -59,7 +59,7 @@ void FontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const SkPaint& paint void FontAtlas::drawDebugAtlas(SkCanvas* canvas, const gfx::Point& destPosition) const { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height()); canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height())); diff --git a/cc/font_atlas.h b/cc/font_atlas.h index 0a227a6..f5878a7 100644 --- a/cc/font_atlas.h +++ b/cc/font_atlas.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "base/threading/thread_checker.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/rect.h" @@ -54,6 +55,8 @@ private: int m_fontHeight; + base::ThreadChecker m_threadChecker; + DISALLOW_COPY_AND_ASSIGN(FontAtlas); }; diff --git a/cc/frame_rate_counter.cc b/cc/frame_rate_counter.cc index 46b51f4..877930f 100644 --- a/cc/frame_rate_counter.cc +++ b/cc/frame_rate_counter.cc @@ -24,8 +24,8 @@ static inline int safeMod(int number, int modulus) } // static -scoped_ptr<FrameRateCounter> FrameRateCounter::create() { - return make_scoped_ptr(new FrameRateCounter()); +scoped_ptr<FrameRateCounter> FrameRateCounter::create(bool hasImplThread) { + return make_scoped_ptr(new FrameRateCounter(hasImplThread)); } inline base::TimeDelta FrameRateCounter::frameInterval(int frameNumber) const @@ -39,8 +39,9 @@ inline int FrameRateCounter::frameIndex(int frameNumber) const return safeMod(frameNumber, kTimeStampHistorySize); } -FrameRateCounter::FrameRateCounter() - : m_currentFrameNumber(1) +FrameRateCounter::FrameRateCounter(bool hasImplThread) + : m_hasImplThread(hasImplThread) + , m_currentFrameNumber(1) , m_droppedFrameCount(0) { m_timeStampHistory[0] = base::TimeTicks::Now(); @@ -54,7 +55,7 @@ void FrameRateCounter::markBeginningOfFrame(base::TimeTicks timestamp) m_timeStampHistory[frameIndex(m_currentFrameNumber)] = timestamp; base::TimeDelta frameIntervalSeconds = frameInterval(m_currentFrameNumber); - if (Proxy::hasImplThread() && m_currentFrameNumber > 0) { + if (m_hasImplThread && m_currentFrameNumber > 0) { HISTOGRAM_CUSTOM_COUNTS("Renderer4.CompositorThreadImplDrawDelay", frameIntervalSeconds.InMilliseconds(), 1, 120, 60); } @@ -70,7 +71,7 @@ void FrameRateCounter::markEndOfFrame() bool FrameRateCounter::isBadFrameInterval(base::TimeDelta intervalBetweenConsecutiveFrames) const { - bool schedulerAllowsDoubleFrames = !Proxy::hasImplThread(); + bool schedulerAllowsDoubleFrames = m_hasImplThread; bool intervalTooFast = schedulerAllowsDoubleFrames && intervalBetweenConsecutiveFrames.InSecondsF() < kFrameTooFast; bool intervalTooSlow = intervalBetweenConsecutiveFrames.InSecondsF() > kFrameTooSlow; return intervalTooFast || intervalTooSlow; @@ -132,4 +133,3 @@ base::TimeTicks FrameRateCounter::timeStampOfRecentFrame(int n) } } // namespace cc - diff --git a/cc/frame_rate_counter.h b/cc/frame_rate_counter.h index 008c2f3..bc1765b 100644 --- a/cc/frame_rate_counter.h +++ b/cc/frame_rate_counter.h @@ -15,7 +15,7 @@ namespace cc { // intelligently compute average frames per second (and standard deviation). class FrameRateCounter { public: - static scoped_ptr<FrameRateCounter> create(); + static scoped_ptr<FrameRateCounter> create(bool hasImplThread); void markBeginningOfFrame(base::TimeTicks timestamp); void markEndOfFrame(); @@ -34,7 +34,7 @@ public: int droppedFrameCount() const { return m_droppedFrameCount; } private: - FrameRateCounter(); + explicit FrameRateCounter(bool hasImplThread); base::TimeDelta frameInterval(int frameNumber) const; int frameIndex(int frameNumber) const; @@ -53,6 +53,8 @@ private: static const int kTimeStampHistorySize = 120; + bool m_hasImplThread; + int m_currentFrameNumber; base::TimeTicks m_timeStampHistory[kTimeStampHistorySize]; diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc index 6b78e04..4faa422 100644 --- a/cc/gl_renderer.cc +++ b/cc/gl_renderer.cc @@ -112,7 +112,7 @@ bool GLRenderer::initialize() m_capabilities.usingPartialSwap = Settings::partialSwapEnabled() && extensions.count("GL_CHROMIUM_post_sub_buffer"); // Use the swapBuffers callback only with the threaded proxy. - if (Proxy::hasImplThread()) + if (m_client->hasImplThread()) m_capabilities.usingSwapCompleteCallback = extensions.count("GL_CHROMIUM_swapbuffers_complete_callback"); if (m_capabilities.usingSwapCompleteCallback) m_context->setSwapBuffersCompleteCallbackCHROMIUM(this); @@ -145,7 +145,6 @@ bool GLRenderer::initialize() GLRenderer::~GLRenderer() { - DCHECK(Proxy::isImplThread()); m_context->setSwapBuffersCompleteCallbackCHROMIUM(0); m_context->setMemoryAllocationChangedCallbackCHROMIUM(0); m_context->setContextLostCallback(0); @@ -343,29 +342,29 @@ void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 6 * sizeof(unsigned short))); } -static WebGraphicsContext3D* getFilterContext() +static WebGraphicsContext3D* getFilterContext(bool hasImplThread) { - if (Proxy::hasImplThread()) + if (hasImplThread) return WebSharedGraphicsContext3D::compositorThreadContext(); else return WebSharedGraphicsContext3D::mainThreadContext(); } -static GrContext* getFilterGrContext() +static GrContext* getFilterGrContext(bool hasImplThread) { - if (Proxy::hasImplThread()) + if (hasImplThread) return WebSharedGraphicsContext3D::compositorThreadGrContext(); else return WebSharedGraphicsContext3D::mainThreadGrContext(); } -static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilterOperations& filters, ScopedTexture* sourceTexture) +static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilterOperations& filters, ScopedTexture* sourceTexture, bool hasImplThread) { if (filters.isEmpty()) return SkBitmap(); - WebGraphicsContext3D* filterContext = getFilterContext(); - GrContext* filterGrContext = getFilterGrContext(); + WebGraphicsContext3D* filterContext = getFilterContext(hasImplThread); + GrContext* filterGrContext = getFilterGrContext(hasImplThread); if (!filterContext || !filterGrContext) return SkBitmap(); @@ -377,13 +376,13 @@ static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilte return source; } -static SkBitmap applyImageFilter(GLRenderer* renderer, SkImageFilter* filter, ScopedTexture* sourceTexture) +static SkBitmap applyImageFilter(GLRenderer* renderer, SkImageFilter* filter, ScopedTexture* sourceTexture, bool hasImplThread) { if (!filter) return SkBitmap(); - WebGraphicsContext3D* context3d = getFilterContext(); - GrContext* grContext = getFilterGrContext(); + WebGraphicsContext3D* context3d = getFilterContext(hasImplThread); + GrContext* grContext = getFilterGrContext(hasImplThread); if (!context3d || !grContext) return SkBitmap(); @@ -469,7 +468,7 @@ scoped_ptr<ScopedTexture> GLRenderer::drawBackgroundFilters(DrawingFrame& frame, if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) return scoped_ptr<ScopedTexture>(); - SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgroundTexture.get()); + SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgroundTexture.get(), m_client->hasImplThread()); if (!filteredDeviceBackground.getTexture()) return scoped_ptr<ScopedTexture>(); @@ -524,9 +523,9 @@ void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua // Apply filters to the contents texture. SkBitmap filterBitmap; if (renderPass->filter()) { - filterBitmap = applyImageFilter(this, renderPass->filter(), contentsTexture); + filterBitmap = applyImageFilter(this, renderPass->filter(), contentsTexture, m_client->hasImplThread()); } else { - filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture); + filterBitmap = applyFilters(this, renderPass->filters(), contentsTexture, m_client->hasImplThread()); } scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock; unsigned contentsTextureId = 0; @@ -954,8 +953,6 @@ struct TexTransformTextureProgramBinding : TextureProgramBinding { void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQuad* quad) { - DCHECK(Proxy::isImplThread()); - TexTransformTextureProgramBinding binding; if (quad->flipped()) binding.set(textureProgramFlip()); @@ -998,7 +995,6 @@ void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDrawQuad* quad) { - DCHECK(Proxy::isImplThread()); TexTransformTextureProgramBinding binding; binding.set(textureIOSurfaceProgram()); @@ -1140,35 +1136,6 @@ void GLRenderer::onSwapBuffersComplete() void GLRenderer::onMemoryAllocationChanged(WebGraphicsMemoryAllocation allocation) { - // FIXME: This is called on the main thread in single threaded mode, but we expect it on the impl thread. - if (!Proxy::hasImplThread()) { - DCHECK(Proxy::isMainThread()); - DebugScopedSetImplThread impl; - onMemoryAllocationChangedOnImplThread(allocation); - } else { - DCHECK(Proxy::isImplThread()); - onMemoryAllocationChangedOnImplThread(allocation); - } -} - -int GLRenderer::priorityCutoffValue(WebKit::WebGraphicsMemoryAllocation::PriorityCutoff priorityCutoff) -{ - switch (priorityCutoff) { - case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing: - return PriorityCalculator::allowNothingCutoff(); - case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly: - return PriorityCalculator::allowVisibleOnlyCutoff(); - case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby: - return PriorityCalculator::allowVisibleAndNearbyCutoff(); - case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything: - return PriorityCalculator::allowEverythingCutoff(); - } - NOTREACHED(); - return 0; -} - -void GLRenderer::onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemoryAllocation allocation) -{ // Just ignore the memory manager when it says to set the limit to zero // bytes. This will happen when the memory manager thinks that the renderer // is not visible (which the renderer knows better). @@ -1192,6 +1159,22 @@ void GLRenderer::onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemory m_discardFramebufferWhenNotVisible = oldDiscardFramebufferWhenNotVisible; } +int GLRenderer::priorityCutoffValue(WebKit::WebGraphicsMemoryAllocation::PriorityCutoff priorityCutoff) +{ + switch (priorityCutoff) { + case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowNothing: + return PriorityCalculator::allowNothingCutoff(); + case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleOnly: + return PriorityCalculator::allowVisibleOnlyCutoff(); + case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby: + return PriorityCalculator::allowVisibleAndNearbyCutoff(); + case WebKit::WebGraphicsMemoryAllocation::PriorityCutoffAllowEverything: + return PriorityCalculator::allowEverythingCutoff(); + } + NOTREACHED(); + return 0; +} + void GLRenderer::enforceMemoryPolicy() { if (!m_visible) { diff --git a/cc/gl_renderer.h b/cc/gl_renderer.h index cb03c06..4fff3a1 100644 --- a/cc/gl_renderer.h +++ b/cc/gl_renderer.h @@ -116,7 +116,6 @@ private: // WebKit::WebGraphicsContext3D::WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation. virtual void onMemoryAllocationChanged(WebKit::WebGraphicsMemoryAllocation) OVERRIDE; - void onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemoryAllocation); void discardFramebuffer(); void ensureFramebuffer(); void enforceMemoryPolicy(); diff --git a/cc/gl_renderer_unittest.cc b/cc/gl_renderer_unittest.cc index 5979a38..b2f8fa5 100644 --- a/cc/gl_renderer_unittest.cc +++ b/cc/gl_renderer_unittest.cc @@ -9,7 +9,6 @@ #include "cc/prioritized_texture_manager.h" #include "cc/resource_provider.h" #include "cc/settings.h" -#include "cc/single_thread_proxy.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/test_common.h" @@ -42,9 +41,6 @@ public: int frameCount() { return m_frame; } void setMemoryAllocation(WebGraphicsMemoryAllocation allocation) { - DCHECK(Proxy::isImplThread()); - // In single threaded mode we expect this callback on main thread. - DebugScopedSetMainThread main; m_memoryAllocationChangedCallback->onMemoryAllocationChanged(allocation); } @@ -76,6 +72,7 @@ public: virtual void setFullRootLayerDamage() OVERRIDE { m_setFullRootLayerDamageCount++; } virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { m_memoryAllocationLimitBytes = policy.bytesLimitWhenVisible; } virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { if (m_lastCallWasSetVisibility) *m_lastCallWasSetVisibility = false; } + virtual bool hasImplThread() const OVERRIDE { return false; } // Methods added for test. int setFullRootLayerDamageCount() const { return m_setFullRootLayerDamageCount; } @@ -90,7 +87,6 @@ public: private: int m_setFullRootLayerDamageCount; bool* m_lastCallWasSetVisibility; - DebugScopedSetImplThread m_implThread; scoped_ptr<LayerImpl> m_rootLayer; RenderPassList m_renderPassesInDrawOrder; RenderPassIdHashMap m_renderPasses; diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc index fadcf04..f1555c1 100644 --- a/cc/layer_impl.cc +++ b/cc/layer_impl.cc @@ -65,13 +65,11 @@ LayerImpl::LayerImpl(int id) #endif , m_layerAnimationController(LayerAnimationController::create(this)) { - DCHECK(Proxy::isImplThread()); DCHECK(m_layerId > 0); } LayerImpl::~LayerImpl() { - DCHECK(Proxy::isImplThread()); #ifndef NDEBUG DCHECK(!m_betweenWillDrawAndDidDraw); #endif diff --git a/cc/layer_impl_unittest.cc b/cc/layer_impl_unittest.cc index 3640185..259a6ed 100644 --- a/cc/layer_impl_unittest.cc +++ b/cc/layer_impl_unittest.cc @@ -58,8 +58,6 @@ TEST(LayerImplTest, verifyLayerChangesAreTrackedProperly) // // The constructor on this will fake that we are on the correct thread. - DebugScopedSetImplThread setImplThread; - // Create a simple LayerImpl tree: scoped_ptr<LayerImpl> root = LayerImpl::create(1); root->addChild(LayerImpl::create(2)); diff --git a/cc/layer_sorter_unittest.cc b/cc/layer_sorter_unittest.cc index 941bd72..7bc70a8 100644 --- a/cc/layer_sorter_unittest.cc +++ b/cc/layer_sorter_unittest.cc @@ -189,8 +189,6 @@ TEST(LayerSorterTest, LayersUnderPathologicalPerspectiveTransform) TEST(LayerSorterTest, verifyExistingOrderingPreservedWhenNoZDiff) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - // If there is no reason to re-sort the layers (i.e. no 3d z difference), then the // existing ordering provided on input should be retained. This test covers the fix in // https://bugs.webkit.org/show_bug.cgi?id=75046. Before this fix, ordering was diff --git a/cc/layer_tree_host.cc b/cc/layer_tree_host.cc index e4341a4..50d0433 100644 --- a/cc/layer_tree_host.cc +++ b/cc/layer_tree_host.cc @@ -24,6 +24,7 @@ #include "cc/overdraw_metrics.h" #include "cc/settings.h" #include "cc/single_thread_proxy.h" +#include "cc/thread.h" #include "cc/thread_proxy.h" #include "cc/tree_synchronizer.h" @@ -83,10 +84,10 @@ bool LayerTreeHost::anyLayerTreeHostInstanceExists() return numLayerTreeInstances > 0; } -scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, const LayerTreeSettings& settings) +scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, const LayerTreeSettings& settings, scoped_ptr<Thread> implThread) { scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings)); - if (!layerTreeHost->initialize()) + if (!layerTreeHost->initialize(implThread.Pass())) return scoped_ptr<LayerTreeHost>(); return layerTreeHost.Pass(); } @@ -112,16 +113,15 @@ LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting , m_hasTransparentBackground(false) , m_partialTextureUpdateRequests(0) { - DCHECK(Proxy::isMainThread()); numLayerTreeInstances++; } -bool LayerTreeHost::initialize() +bool LayerTreeHost::initialize(scoped_ptr<Thread> implThread) { TRACE_EVENT0("cc", "LayerTreeHost::initialize"); - if (Proxy::hasImplThread()) - m_proxy = ThreadProxy::create(this); + if (implThread) + m_proxy = ThreadProxy::create(this, implThread.Pass()); else m_proxy = SingleThreadProxy::create(this); m_proxy->start(); @@ -133,11 +133,10 @@ LayerTreeHost::~LayerTreeHost() { if (m_rootLayer) m_rootLayer->setLayerTreeHost(0); - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy); + DCHECK(m_proxy->isMainThread()); TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); - DCHECK(m_proxy.get()); m_proxy->stop(); - m_proxy.reset(); numLayerTreeInstances--; RateLimiterMap::iterator it = m_rateLimiters.begin(); if (it != m_rateLimiters.end()) @@ -164,7 +163,7 @@ void LayerTreeHost::initializeRenderer() // Update m_settings based on partial update capability. m_settings.maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdates, m_proxy->maxPartialTextureUpdates()); - m_contentsTextureManager = PrioritizedTextureManager::create(0, m_proxy->rendererCapabilities().maxTextureSize, Renderer::ContentPool); + m_contentsTextureManager = PrioritizedTextureManager::create(0, m_proxy->rendererCapabilities().maxTextureSize, Renderer::ContentPool, m_proxy.get()); m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(gfx::Size(), GL_RGBA); m_rendererInitialized = true; @@ -199,7 +198,7 @@ LayerTreeHost::RecreateResult LayerTreeHost::recreateContext() // FIXME: The single thread does not self-schedule context // recreation. So force another recreation attempt to happen by requesting // another commit. - if (!Proxy::hasImplThread()) + if (!m_proxy->hasImplThread()) setNeedsCommit(); return RecreateFailedButTryAgain; } @@ -212,14 +211,14 @@ LayerTreeHost::RecreateResult LayerTreeHost::recreateContext() void LayerTreeHost::deleteContentsTexturesOnImplThread(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); if (m_rendererInitialized) m_contentsTextureManager->clearAllMemory(resourceProvider); } void LayerTreeHost::acquireLayerTextures() { - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); m_proxy->acquireLayerTextures(); } @@ -240,7 +239,7 @@ void LayerTreeHost::layout() void LayerTreeHost::beginCommitOnImplThread(LayerTreeHostImpl* hostImpl) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); TRACE_EVENT0("cc", "LayerTreeHost::commitTo"); } @@ -251,7 +250,7 @@ void LayerTreeHost::beginCommitOnImplThread(LayerTreeHostImpl* hostImpl) // after the commit, but on the main thread. void LayerTreeHost::finishCommitOnImplThread(LayerTreeHostImpl* hostImpl) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); m_contentsTextureManager->updateBackingsInDrawingImplTree(); ResourceProvider::debugNotifyEnterZone(0xA000000); @@ -318,13 +317,13 @@ scoped_ptr<InputHandler> LayerTreeHost::createInputHandler() scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHostImplClient* client) { - return LayerTreeHostImpl::create(m_settings, client); + return LayerTreeHostImpl::create(m_settings, client, m_proxy.get()); } void LayerTreeHost::didLoseContext() { TRACE_EVENT0("cc", "LayerTreeHost::didLoseContext"); - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); m_contextLost = true; m_numFailedRecreateAttempts = 0; setNeedsCommit(); @@ -367,7 +366,7 @@ const RendererCapabilities& LayerTreeHost::rendererCapabilities() const void LayerTreeHost::setNeedsAnimate() { - DCHECK(Proxy::hasImplThread()); + DCHECK(m_proxy->hasImplThread()); m_proxy->setNeedsAnimate(); } @@ -383,7 +382,7 @@ void LayerTreeHost::setNeedsCommit() void LayerTreeHost::setNeedsRedraw() { m_proxy->setNeedsRedraw(); - if (!ThreadProxy::implThread()) + if (!m_proxy->implThread()) m_client->scheduleComposite(); } @@ -394,7 +393,7 @@ bool LayerTreeHost::commitRequested() const void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) { - DCHECK(ThreadProxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime); } @@ -470,7 +469,7 @@ PrioritizedTextureManager* LayerTreeHost::contentsTextureManager() const void LayerTreeHost::composite() { - DCHECK(!ThreadProxy::implThread()); + DCHECK(!m_proxy->implThread()); static_cast<SingleThreadProxy*>(m_proxy.get())->compositeImmediately(); } @@ -745,7 +744,7 @@ void LayerTreeHost::startRateLimiter(WebKit::WebGraphicsContext3D* context) if (it != m_rateLimiters.end()) it->second->start(); else { - scoped_refptr<RateLimiter> rateLimiter = RateLimiter::create(context, this); + scoped_refptr<RateLimiter> rateLimiter = RateLimiter::create(context, this, m_proxy->mainThread()); m_rateLimiters[context] = rateLimiter; rateLimiter->start(); } diff --git a/cc/layer_tree_host.h b/cc/layer_tree_host.h index 7879d1a..a660e27 100644 --- a/cc/layer_tree_host.h +++ b/cc/layer_tree_host.h @@ -93,7 +93,7 @@ struct RendererCapabilities { class LayerTreeHost : public RateLimiterClient { public: - static scoped_ptr<LayerTreeHost> create(LayerTreeHostClient*, const LayerTreeSettings&); + static scoped_ptr<LayerTreeHost> create(LayerTreeHostClient*, const LayerTreeSettings&, scoped_ptr<Thread> implThread); virtual ~LayerTreeHost(); void setSurfaceReady(); @@ -212,9 +212,11 @@ public: HeadsUpDisplayLayer* hudLayer() const { return m_hudLayer.get(); } + Proxy* proxy() const { return m_proxy.get(); } + protected: LayerTreeHost(LayerTreeHostClient*, const LayerTreeSettings&); - bool initialize(); + bool initialize(scoped_ptr<Thread> implThread); private: typedef std::vector<scoped_refptr<Layer> > LayerList; @@ -243,11 +245,11 @@ private: base::CancelableClosure m_prepaintCallback; LayerTreeHostClient* m_client; + scoped_ptr<Proxy> m_proxy; int m_commitNumber; RenderingStats m_renderingStats; - scoped_ptr<Proxy> m_proxy; bool m_rendererInitialized; bool m_contextLost; int m_numTimesRecreateShouldFail; diff --git a/cc/layer_tree_host_common_unittest.cc b/cc/layer_tree_host_common_unittest.cc index d25bb58..b39ea1f 100644 --- a/cc/layer_tree_host_common_unittest.cc +++ b/cc/layer_tree_host_common_unittest.cc @@ -791,8 +791,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD { // This test checks for correct scroll compensation when the fixed-position container // is the direct parent of the fixed-position layer. - - DebugScopedSetImplThread scopedImplThread; scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -832,8 +830,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithT // Transforms are in general non-commutative; using something like a non-uniform scale // helps to verify that translations and non-uniform scales are applied in the correct // order. - - DebugScopedSetImplThread scopedImplThread; scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -875,8 +871,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD { // This test checks for correct scroll compensation when the fixed-position container // is NOT the direct parent of the fixed-position layer. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -919,8 +913,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithD // This test checks for correct scroll compensation when the fixed-position container // is NOT the direct parent of the fixed-position layer, and the hierarchy has various // transforms that have to be processed in the correct order. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -981,8 +973,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM // This test checks for correct scroll compensation when the fixed-position container // is NOT the direct parent of the fixed-position layer, and the hierarchy has various // transforms that have to be processed in the correct order. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1043,8 +1033,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithI // contributes to a different renderSurface than the fixed-position layer. In this // case, the surface drawTransforms also have to be accounted for when checking the // scrollDelta. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1116,8 +1104,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithM // contributes to a different renderSurface than the fixed-position layer, with // additional renderSurfaces in-between. This checks that the conversion to ancestor // surfaces is accumulated properly in the final matrix transform. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1227,8 +1213,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithC // itself has a renderSurface. In this case, the container layer should be treated // like a layer that contributes to a renderTarget, and that renderTarget // is completely irrelevant; it should not affect the scroll compensation. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1274,8 +1258,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatI // This test checks the scenario where a fixed-position layer also happens to be a // container itself for a descendant fixed position layer. In particular, the layer // should not accidentally be fixed to itself. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -1311,8 +1293,6 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatH // This test checks scroll compensation when a fixed-position layer does not find any // ancestor that is a "containerForFixedPositionLayers". In this situation, the layer should // be fixed to the viewport -- not the rootLayer, which may have transforms of its own. - DebugScopedSetImplThread scopedImplThread; - scoped_ptr<LayerImpl> root = createTreeForFixedPositionTests(); LayerImpl* child = root->children()[0]; LayerImpl* grandChild = child->children()[0]; @@ -2684,8 +2664,6 @@ TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList) { // Hit testing on an empty renderSurfaceLayerList should return a null pointer. - DebugScopedSetImplThread thisScopeIsOnImplThread; - std::vector<LayerImpl*> renderSurfaceLayerList; gfx::Point testPoint(0, 0); @@ -2699,8 +2677,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList) TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); WebTransformationMatrix identityMatrix; @@ -2741,8 +2717,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); WebTransformationMatrix uninvertibleTransform; @@ -2802,8 +2776,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform) TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); WebTransformationMatrix identityMatrix; @@ -2845,8 +2817,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); WebTransformationMatrix identityMatrix; @@ -2896,8 +2866,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(12345); WebTransformationMatrix identityMatrix; @@ -2958,8 +2926,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents) // contentsScale is ignored, then hit testing will mis-interpret the visibleContentRect // as being larger than the actual bounds of the layer. // - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(1); WebTransformationMatrix identityMatrix; @@ -3021,8 +2987,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer) { // Test that hit-testing will only work for the visible portion of a layer, and not // the entire layer bounds. Here we just test the simple axis-aligned case. - DebugScopedSetImplThread thisScopeIsOnImplThread; - WebTransformationMatrix identityMatrix; gfx::PointF anchor(0, 0); @@ -3089,8 +3053,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer) // combined create a triangle. The rotatedLeaf will only be visible where it overlaps // this triangle. // - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(123); WebTransformationMatrix identityMatrix; @@ -3189,8 +3151,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) { // This test checks that hit testing code does not accidentally clip to layer // bounds for a layer that actually does not clip. - DebugScopedSetImplThread thisScopeIsOnImplThread; - WebTransformationMatrix identityMatrix; gfx::PointF anchor(0, 0); @@ -3250,8 +3210,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer) TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers) { - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(1); WebTransformationMatrix identityMatrix; @@ -3355,8 +3313,6 @@ TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists) // The geometry is set up similarly to the previous case, but // all layers are forced to be renderSurfaces now. // - DebugScopedSetImplThread thisScopeIsOnImplThread; - scoped_ptr<LayerImpl> root = LayerImpl::create(1); WebTransformationMatrix identityMatrix; diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc index 4b1d2c6..9c60568 100644 --- a/cc/layer_tree_host_impl.cc +++ b/cc/layer_tree_host_impl.cc @@ -200,13 +200,14 @@ LayerTreeHostImpl::FrameData::~FrameData() { } -scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::create(const LayerTreeSettings& settings, LayerTreeHostImplClient* client) +scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::create(const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) { - return make_scoped_ptr(new LayerTreeHostImpl(settings, client)); + return make_scoped_ptr(new LayerTreeHostImpl(settings, client, proxy)); } -LayerTreeHostImpl::LayerTreeHostImpl(const LayerTreeSettings& settings, LayerTreeHostImplClient* client) +LayerTreeHostImpl::LayerTreeHostImpl(const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) : m_client(client) + , m_proxy(proxy) , m_sourceFrameNumber(-1) , m_rootScrollLayerImpl(0) , m_currentlyScrollingLayerImpl(0) @@ -225,18 +226,18 @@ LayerTreeHostImpl::LayerTreeHostImpl(const LayerTreeSettings& settings, LayerTre , m_hasTransparentBackground(false) , m_needsAnimateLayers(false) , m_pinchGestureActive(false) - , m_fpsCounter(FrameRateCounter::create()) + , m_fpsCounter(FrameRateCounter::create(m_proxy->hasImplThread())) , m_debugRectHistory(DebugRectHistory::create()) , m_numImplThreadScrolls(0) , m_numMainThreadScrolls(0) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); didVisibilityChange(this, m_visible); } LayerTreeHostImpl::~LayerTreeHostImpl() { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); if (m_rootLayerImpl) @@ -504,7 +505,7 @@ void LayerTreeHostImpl::setBackgroundTickingEnabled(bool enabled) { // Lazily create the timeSource adapter so that we can vary the interval for testing. if (!m_timeSourceClientAdapter) - m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(this, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), Proxy::currentThread())); + m_timeSourceClientAdapter = LayerTreeHostImplTimeSourceAdapter::create(this, DelayBasedTimeSource::create(lowFrequencyAnimationInterval(), m_proxy->currentThread())); m_timeSourceClientAdapter->setActive(enabled); } @@ -649,10 +650,20 @@ void LayerTreeHostImpl::enforceManagedMemoryPolicy(const ManagedMemoryPolicy& po m_client->sendManagedMemoryStats(); } +bool LayerTreeHostImpl::hasImplThread() const +{ + return m_proxy->hasImplThread(); +} + void LayerTreeHostImpl::setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) { if (m_managedMemoryPolicy == policy) return; + + // FIXME: In single-thread mode, this can be called on the main thread + // by GLRenderer::onMemoryAllocationChanged. + DebugScopedSetImplThread implThread(m_proxy); + m_managedMemoryPolicy = policy; enforceManagedMemoryPolicy(m_managedMemoryPolicy); // We always need to commit after changing the memory policy because the new @@ -819,7 +830,7 @@ scoped_ptr<LayerImpl> LayerTreeHostImpl::detachLayerTree() void LayerTreeHostImpl::setVisible(bool visible) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); if (m_visible == visible) return; diff --git a/cc/layer_tree_host_impl.h b/cc/layer_tree_host_impl.h index 783d042..7e4d57b 100644 --- a/cc/layer_tree_host_impl.h +++ b/cc/layer_tree_host_impl.h @@ -105,7 +105,7 @@ class LayerTreeHostImpl : public InputHandlerClient, typedef std::vector<LayerImpl*> LayerList; public: - static scoped_ptr<LayerTreeHostImpl> create(const LayerTreeSettings&, LayerTreeHostImplClient*); + static scoped_ptr<LayerTreeHostImpl> create(const LayerTreeSettings&, LayerTreeHostImplClient*, Proxy*); virtual ~LayerTreeHostImpl(); // InputHandlerClient implementation @@ -154,6 +154,7 @@ public: virtual void setFullRootLayerDamage() OVERRIDE; virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE; virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE; + virtual bool hasImplThread() const OVERRIDE; // WebCompositorOutputSurfaceClient implementation. virtual void onVSyncParametersChanged(double monotonicTimebase, double intervalInSeconds) OVERRIDE; @@ -231,6 +232,7 @@ public: FrameRateCounter* fpsCounter() const { return m_fpsCounter.get(); } DebugRectHistory* debugRectHistory() const { return m_debugRectHistory.get(); } ResourceProvider* resourceProvider() const { return m_resourceProvider.get(); } + Proxy* proxy() const { return m_proxy; } class CullRenderPassesWithCachedTextures { public: @@ -263,7 +265,7 @@ public: static void removeRenderPasses(RenderPassCuller, FrameData&); protected: - LayerTreeHostImpl(const LayerTreeSettings&, LayerTreeHostImplClient*); + LayerTreeHostImpl(const LayerTreeSettings&, LayerTreeHostImplClient*, Proxy*); void animatePageScale(base::TimeTicks monotonicTime); void animateScrollbars(base::TimeTicks monotonicTime); @@ -278,6 +280,7 @@ protected: virtual base::TimeDelta lowFrequencyAnimationInterval() const; LayerTreeHostImplClient* m_client; + Proxy* m_proxy; int m_sourceFrameNumber; private: diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc index fc4d1dd..22fbfee 100644 --- a/cc/layer_tree_host_impl_unittest.cc +++ b/cc/layer_tree_host_impl_unittest.cc @@ -23,6 +23,7 @@ #include "cc/single_thread_proxy.h" #include "cc/solid_color_draw_quad.h" #include "cc/test/animation_test_common.h" +#include "cc/test/fake_proxy.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/fake_web_scrollbar_theme_geometry.h" @@ -63,7 +64,10 @@ class LayerTreeHostImplTest : public testing::TestWithParam<bool>, public LayerTreeHostImplClient { public: LayerTreeHostImplTest() - : m_onCanDrawStateChangedCalled(false) + : m_proxy(scoped_ptr<Thread>(NULL)) + , m_alwaysImplThread(&m_proxy) + , m_alwaysMainThreadBlocked(&m_proxy) + , m_onCanDrawStateChangedCalled(false) , m_didRequestCommit(false) , m_didRequestRedraw(false) , m_reduceMemoryResult(true) @@ -77,7 +81,7 @@ public: LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - m_hostImpl = LayerTreeHostImpl::create(settings, this); + m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); m_hostImpl->initializeRenderer(createContext()); m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); } @@ -105,7 +109,7 @@ public: LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); myHostImpl->initializeRenderer(graphicsContext.Pass()); myHostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); @@ -189,6 +193,7 @@ protected: return FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3D)).PassAs<GraphicsContext>(); } + FakeProxy m_proxy; DebugScopedSetImplThread m_alwaysImplThread; DebugScopedSetMainThreadBlocked m_alwaysMainThreadBlocked; @@ -352,7 +357,7 @@ TEST_P(LayerTreeHostImplTest, scrollWithoutRootLayer) TEST_P(LayerTreeHostImplTest, scrollWithoutRenderer) { LayerTreeSettings settings; - m_hostImpl = LayerTreeHostImpl::create(settings, this); + m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Initialization will fail here. m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)).PassAs<GraphicsContext>()); @@ -1948,7 +1953,7 @@ TEST_P(LayerTreeHostImplTest, partialSwapReceivesDamageRect) // that we can force partial swap enabled. LayerTreeSettings settings; Settings::setPartialSwapEnabled(true); - scoped_ptr<LayerTreeHostImpl> layerTreeHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> layerTreeHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); layerTreeHostImpl->initializeRenderer(outputSurface.Pass()); layerTreeHostImpl->setViewportSize(gfx::Size(500, 500), gfx::Size(500, 500)); @@ -2228,14 +2233,14 @@ public: } }; -static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, LayerTreeHostImplClient* client) +static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, LayerTreeHostImplClient* client, Proxy* proxy) { Settings::setPartialSwapEnabled(partialSwap); scoped_ptr<GraphicsContext> context = FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<GraphicsContext>(); LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, client); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, client, proxy); myHostImpl->initializeRenderer(context.Pass()); myHostImpl->setViewportSize(gfx::Size(100, 100), gfx::Size(100, 100)); @@ -2298,7 +2303,7 @@ static scoped_ptr<LayerTreeHostImpl> setupLayersForOpacity(bool partialSwap, Lay TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap) { - scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(true, this, &m_proxy); { LayerTreeHostImpl::FrameData frame; @@ -2319,7 +2324,7 @@ TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorPartialSwap) TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) { - scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = setupLayersForOpacity(false, this, &m_proxy); { LayerTreeHostImpl::FrameData frame; @@ -2385,7 +2390,7 @@ TEST_P(LayerTreeHostImplTest, contextLostAndRestoredNotificationSentToAllLayers) TEST_P(LayerTreeHostImplTest, finishAllRenderingAfterContextLost) { LayerTreeSettings settings; - m_hostImpl = LayerTreeHostImpl::create(settings, this); + m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // The context initialization will fail, but we should still be able to call finishAllRendering() without any ill effects. m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)).PassAs<GraphicsContext>()); @@ -2409,7 +2414,7 @@ private: TEST_P(LayerTreeHostImplTest, contextLostDuringInitialize) { LayerTreeSettings settings; - m_hostImpl = LayerTreeHostImpl::create(settings, this); + m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Initialize into a known successful state. EXPECT_TRUE(m_hostImpl->initializeRenderer(createContext())); @@ -3020,7 +3025,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithClipping) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); LayerImpl* rootPtr; LayerImpl* surfaceLayerPtr; @@ -3117,7 +3122,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusion) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Layers are structure as follows: // @@ -3233,7 +3238,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionEarlyOut) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Layers are structure as follows: // @@ -3349,7 +3354,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionExternalOverInternal) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Layers are structured as follows: // @@ -3437,7 +3442,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionExternalNotAligned) Settings::setPartialSwapEnabled(false); LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Layers are structured as follows: // @@ -3512,7 +3517,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusionPartialSwap) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Layers are structure as follows: // @@ -3625,7 +3630,7 @@ TEST_P(LayerTreeHostImplTest, textureCachingWithScissor) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); /* Layers are created as follows: @@ -3732,7 +3737,7 @@ TEST_P(LayerTreeHostImplTest, surfaceTextureCaching) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); LayerImpl* rootPtr; LayerImpl* intermediateLayerPtr; @@ -3893,7 +3898,7 @@ TEST_P(LayerTreeHostImplTest, surfaceTextureCachingNoPartialSwap) LayerTreeSettings settings; settings.minimumOcclusionTrackingSize = gfx::Size(); - scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this); + scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); LayerImpl* rootPtr; LayerImpl* intermediateLayerPtr; @@ -4085,9 +4090,9 @@ struct RenderPassRemovalTestData : public LayerTreeHostImpl::FrameData { class TestRenderer : public GLRenderer, public RendererClient { public: - static scoped_ptr<TestRenderer> create(ResourceProvider* resourceProvider) + static scoped_ptr<TestRenderer> create(ResourceProvider* resourceProvider, Proxy* proxy) { - scoped_ptr<TestRenderer> renderer(new TestRenderer(resourceProvider)); + scoped_ptr<TestRenderer> renderer(new TestRenderer(resourceProvider, proxy)); if (!renderer->initialize()) return scoped_ptr<TestRenderer>(); @@ -4107,9 +4112,10 @@ public: virtual void setFullRootLayerDamage() OVERRIDE { } virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { } virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { } + virtual bool hasImplThread() const OVERRIDE { return false; } protected: - TestRenderer(ResourceProvider* resourceProvider) : GLRenderer(this, resourceProvider) { } + TestRenderer(ResourceProvider* resourceProvider, Proxy* proxy) : GLRenderer(this, resourceProvider) { } private: LayerTreeSettings m_settings; @@ -4393,7 +4399,7 @@ TEST_P(LayerTreeHostImplTest, testRemoveRenderPasses) ASSERT_TRUE(context->context3D()); scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(context.get())); - scoped_ptr<TestRenderer> renderer(TestRenderer::create(resourceProvider.get())); + scoped_ptr<TestRenderer> renderer(TestRenderer::create(resourceProvider.get(), &m_proxy)); int testCaseIndex = 0; while (removeRenderPassesCases[testCaseIndex].name) { diff --git a/cc/layer_tree_host_unittest.cc b/cc/layer_tree_host_unittest.cc index 166c4070..00d8d70 100644 --- a/cc/layer_tree_host_unittest.cc +++ b/cc/layer_tree_host_unittest.cc @@ -2863,7 +2863,7 @@ public: implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfterEvictTextures::evictTexturesOnImplThread, base::Unretained(this))); } else { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(proxy()); evictTexturesOnImplThread(); } } diff --git a/cc/layer_unittest.cc b/cc/layer_unittest.cc index f1a64e8..8407eb1 100644 --- a/cc/layer_unittest.cc +++ b/cc/layer_unittest.cc @@ -12,6 +12,7 @@ #include "cc/layer_tree_host.h" #include "cc/settings.h" #include "cc/single_thread_proxy.h" +#include "cc/thread.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/test_common.h" @@ -40,7 +41,7 @@ public: MockLayerImplTreeHost() : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) { - initialize(); + initialize(scoped_ptr<Thread>(NULL)); } MOCK_METHOD0(setNeedsCommit, void()); @@ -528,8 +529,6 @@ TEST_F(LayerTest, checkPropertyChangeCausesCorrectBehavior) TEST_F(LayerTest, verifyPushPropertiesAccumulatesUpdateRect) { - DebugScopedSetImplThread setImplThread; - scoped_refptr<Layer> testLayer = Layer::create(); scoped_ptr<LayerImpl> implLayer = LayerImpl::create(1); @@ -555,7 +554,7 @@ public: { scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost); // The initialize call will fail, since our client doesn't provide a valid GraphicsContext3D, but it doesn't matter in the tests that use this fake so ignore the return value. - host->initialize(); + host->initialize(scoped_ptr<Thread>(NULL)); return host.Pass(); } diff --git a/cc/occlusion_tracker_unittest.cc b/cc/occlusion_tracker_unittest.cc index e59c0ab..71dee9c 100644 --- a/cc/occlusion_tracker_unittest.cc +++ b/cc/occlusion_tracker_unittest.cc @@ -425,14 +425,12 @@ private: #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \ class ClassName##ImplThreadOpaqueLayers : public ClassName<OcclusionTrackerTestImplThreadTypes> { \ - DebugScopedSetImplThread impl; \ public: \ ClassName##ImplThreadOpaqueLayers() : ClassName<OcclusionTrackerTestImplThreadTypes>(true) { } \ }; \ TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); } #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \ class ClassName##ImplThreadOpaquePaints : public ClassName<OcclusionTrackerTestImplThreadTypes> { \ - DebugScopedSetImplThread impl; \ public: \ ClassName##ImplThreadOpaquePaints() : ClassName<OcclusionTrackerTestImplThreadTypes>(false) { } \ }; \ diff --git a/cc/prioritized_texture.cc b/cc/prioritized_texture.cc index 1c4428a..e2fee50 100644 --- a/cc/prioritized_texture.cc +++ b/cc/prioritized_texture.cc @@ -153,7 +153,7 @@ PrioritizedTexture::Backing::~Backing() void PrioritizedTexture::Backing::deleteResource(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); + DCHECK(!proxy() || proxy()->isImplThread()); DCHECK(!m_resourceHasBeenDeleted); #ifndef NDEBUG DCHECK(resourceProvider == m_resourceProvider); @@ -166,19 +166,19 @@ void PrioritizedTexture::Backing::deleteResource(ResourceProvider* resourceProvi bool PrioritizedTexture::Backing::resourceHasBeenDeleted() const { - DCHECK(Proxy::isImplThread()); + DCHECK(!proxy() || proxy()->isImplThread()); return m_resourceHasBeenDeleted; } bool PrioritizedTexture::Backing::canBeRecycled() const { - DCHECK(Proxy::isImplThread()); + DCHECK(!proxy() || proxy()->isImplThread()); return !m_wasAbovePriorityCutoffAtLastPriorityUpdate && !m_inDrawingImplTree; } void PrioritizedTexture::Backing::updatePriority() { - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(!proxy() || proxy()->isImplThread() && proxy()->isMainThreadBlocked()); if (m_owner) { m_priorityAtLastPriorityUpdate = m_owner->requestPriority(); m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityCutoff(); @@ -190,7 +190,7 @@ void PrioritizedTexture::Backing::updatePriority() void PrioritizedTexture::Backing::updateInDrawingImplTree() { - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(!proxy() || proxy()->isImplThread() && proxy()->isMainThreadBlocked()); m_inDrawingImplTree = !!owner(); if (!m_inDrawingImplTree) DCHECK(m_priorityAtLastPriorityUpdate == PriorityCalculator::lowestPriority()); @@ -203,4 +203,11 @@ void PrioritizedTexture::returnBackingTexture() m_manager->returnBackingTexture(this); } +const Proxy* PrioritizedTexture::Backing::proxy() const +{ + if (!m_owner || !m_owner->textureManager()) + return 0; + return m_owner->textureManager()->proxyForDebug(); +} + } // namespace cc diff --git a/cc/prioritized_texture.h b/cc/prioritized_texture.h index fed3470..51921c8 100644 --- a/cc/prioritized_texture.h +++ b/cc/prioritized_texture.h @@ -19,6 +19,7 @@ namespace cc { class PrioritizedTextureManager; +class Proxy; class PrioritizedTexture { public: @@ -107,6 +108,8 @@ private: bool resourceHasBeenDeleted() const; private: + const Proxy* proxy() const; + friend class PrioritizedTexture; PrioritizedTexture* m_owner; int m_priorityAtLastPriorityUpdate; @@ -119,7 +122,6 @@ private: #ifndef NDEBUG ResourceProvider* m_resourceProvider; #endif - DISALLOW_COPY_AND_ASSIGN(Backing); }; diff --git a/cc/prioritized_texture_manager.cc b/cc/prioritized_texture_manager.cc index 32944bf..07de017 100644 --- a/cc/prioritized_texture_manager.cc +++ b/cc/prioritized_texture_manager.cc @@ -17,8 +17,9 @@ using namespace std; namespace cc { -PrioritizedTextureManager::PrioritizedTextureManager(size_t maxMemoryLimitBytes, int, int pool) - : m_maxMemoryLimitBytes(maxMemoryLimitBytes) +PrioritizedTextureManager::PrioritizedTextureManager(size_t maxMemoryLimitBytes, int, int pool, const Proxy* proxy) + : m_proxy(proxy) + , m_maxMemoryLimitBytes(maxMemoryLimitBytes) , m_externalPriorityCutoff(PriorityCalculator::allowEverythingCutoff()) , m_memoryUseBytes(0) , m_memoryAboveCutoffBytes(0) @@ -46,20 +47,20 @@ PrioritizedTextureManager::~PrioritizedTextureManager() size_t PrioritizedTextureManager::memoryVisibleBytes() const { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); return m_memoryVisibleLastPushedBytes; } size_t PrioritizedTextureManager::memoryVisibleAndNearbyBytes() const { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); return m_memoryVisibleAndNearbyLastPushedBytes; } void PrioritizedTextureManager::prioritizeTextures() { TRACE_EVENT0("cc", "PrioritizedTextureManager::prioritizeTextures"); - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); // Sorting textures in this function could be replaced by a slightly // modified O(n) quick-select to partition textures rather than @@ -135,7 +136,7 @@ void PrioritizedTextureManager::prioritizeTextures() void PrioritizedTextureManager::pushTexturePrioritiesToBackings() { TRACE_EVENT0("cc", "PrioritizedTextureManager::pushTexturePrioritiesToBackings"); - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); assertInvariants(); for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) @@ -151,7 +152,7 @@ void PrioritizedTextureManager::pushTexturePrioritiesToBackings() void PrioritizedTextureManager::updateBackingsInDrawingImplTree() { TRACE_EVENT0("cc", "PrioritizedTextureManager::updateBackingsInDrawingImplTree"); - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); assertInvariants(); for (BackingList::iterator it = m_backings.begin(); it != m_backings.end(); ++it) { @@ -165,7 +166,7 @@ void PrioritizedTextureManager::updateBackingsInDrawingImplTree() void PrioritizedTextureManager::sortBackings() { TRACE_EVENT0("cc", "PrioritizedTextureManager::sortBackings"); - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); // Put backings in eviction/recycling order. m_backings.sort(compareBackings); @@ -174,7 +175,7 @@ void PrioritizedTextureManager::sortBackings() void PrioritizedTextureManager::clearPriorities() { - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); for (TextureSet::iterator it = m_textures.begin(); it != m_textures.end(); ++it) { // FIXME: We should remove this and just set all priorities to // PriorityCalculator::lowestPriority() once we have priorities @@ -186,7 +187,7 @@ void PrioritizedTextureManager::clearPriorities() bool PrioritizedTextureManager::requestLate(PrioritizedTexture* texture) { - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); // This is already above cutoff, so don't double count it's memory below. if (texture->isAbovePriorityCutoff()) @@ -211,7 +212,7 @@ bool PrioritizedTextureManager::requestLate(PrioritizedTexture* texture) void PrioritizedTextureManager::acquireBackingTextureIfNeeded(PrioritizedTexture* texture, ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); DCHECK(!texture->isSelfManaged()); DCHECK(texture->isAbovePriorityCutoff()); if (texture->backing() || !texture->isAbovePriorityCutoff()) @@ -251,7 +252,7 @@ void PrioritizedTextureManager::acquireBackingTextureIfNeeded(PrioritizedTexture bool PrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, EvictionPolicy evictionPolicy, ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); if (memoryUseBytes() <= limitBytes && PriorityCalculator::allowEverythingCutoff() == priorityCutoff) return false; @@ -271,7 +272,7 @@ bool PrioritizedTextureManager::evictBackingsToReduceMemory(size_t limitBytes, i void PrioritizedTextureManager::reduceMemory(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); // Note that it will not always be the case that memoryUseBytes() <= maxMemoryLimitBytes(), // because we are not at liberty to delete textures that are referenced by the impl tree to @@ -306,14 +307,14 @@ void PrioritizedTextureManager::reduceMemory(ResourceProvider* resourceProvider) void PrioritizedTextureManager::clearAllMemory(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); DCHECK(resourceProvider); evictBackingsToReduceMemory(0, PriorityCalculator::allowEverythingCutoff(), EvictAnything, resourceProvider); } bool PrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, int priorityCutoff, ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); DCHECK(resourceProvider); // If we are in the process of uploading a new frame then the backings at the very end of // the list are not sorted by priority. Sort them before doing the eviction. @@ -324,14 +325,14 @@ bool PrioritizedTextureManager::reduceMemoryOnImplThread(size_t limitBytes, int void PrioritizedTextureManager::getEvictedBackings(BackingList& evictedBackings) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); evictedBackings.clear(); evictedBackings.insert(evictedBackings.begin(), m_evictedBackings.begin(), m_evictedBackings.end()); } void PrioritizedTextureManager::unlinkEvictedBackings(const BackingList& evictedBackings) { - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); for (BackingList::const_iterator it = evictedBackings.begin(); it != evictedBackings.end(); ++it) { PrioritizedTexture::Backing* backing = (*it); if (backing->owner()) @@ -341,7 +342,7 @@ void PrioritizedTextureManager::unlinkEvictedBackings(const BackingList& evicted void PrioritizedTextureManager::deleteUnlinkedEvictedBackings() { - DCHECK(Proxy::isMainThread() || (Proxy::isImplThread() && Proxy::isMainThreadBlocked())); + DCHECK(m_proxy->isMainThread() || (m_proxy->isImplThread() && m_proxy->isMainThreadBlocked())); BackingList newEvictedBackings; for (BackingList::const_iterator it = m_evictedBackings.begin(); it != m_evictedBackings.end(); ++it) { PrioritizedTexture::Backing* backing = (*it); @@ -364,7 +365,7 @@ bool PrioritizedTextureManager::linkedEvictedBackingsExist() const void PrioritizedTextureManager::registerTexture(PrioritizedTexture* texture) { - DCHECK(Proxy::isMainThread()); + DCHECK(m_proxy->isMainThread()); DCHECK(texture); DCHECK(!texture->textureManager()); DCHECK(!texture->backing()); @@ -377,7 +378,7 @@ void PrioritizedTextureManager::registerTexture(PrioritizedTexture* texture) void PrioritizedTextureManager::unregisterTexture(PrioritizedTexture* texture) { - DCHECK(Proxy::isMainThread() || (Proxy::isImplThread() && Proxy::isMainThreadBlocked())); + DCHECK(m_proxy->isMainThread() || (m_proxy->isImplThread() && m_proxy->isMainThreadBlocked())); DCHECK(texture); DCHECK(ContainsKey(m_textures, texture)); @@ -389,14 +390,14 @@ void PrioritizedTextureManager::unregisterTexture(PrioritizedTexture* texture) void PrioritizedTextureManager::returnBackingTexture(PrioritizedTexture* texture) { - DCHECK(Proxy::isMainThread() || (Proxy::isImplThread() && Proxy::isMainThreadBlocked())); + DCHECK(m_proxy->isMainThread() || (m_proxy->isImplThread() && m_proxy->isMainThreadBlocked())); if (texture->backing()) texture->unlink(); } PrioritizedTexture::Backing* PrioritizedTextureManager::createBacking(gfx::Size size, GLenum format, ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); DCHECK(resourceProvider); ResourceProvider::ResourceId resourceId = resourceProvider->createResource(m_pool, size, format, ResourceProvider::TextureUsageAny); PrioritizedTexture::Backing* backing = new PrioritizedTexture::Backing(resourceId, resourceProvider, size, format); @@ -406,7 +407,7 @@ PrioritizedTexture::Backing* PrioritizedTextureManager::createBacking(gfx::Size void PrioritizedTextureManager::evictFirstBackingResource(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_proxy->isImplThread()); DCHECK(resourceProvider); DCHECK(!m_backings.empty()); PrioritizedTexture::Backing* backing = m_backings.front(); @@ -424,7 +425,7 @@ void PrioritizedTextureManager::evictFirstBackingResource(ResourceProvider* reso void PrioritizedTextureManager::assertInvariants() { #ifndef NDEBUG - DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); + DCHECK(m_proxy->isImplThread() && m_proxy->isMainThreadBlocked()); // If we hit any of these asserts, there is a bug in this class. To see // where the bug is, call this function at the beginning and end of @@ -472,4 +473,9 @@ void PrioritizedTextureManager::assertInvariants() #endif } +const Proxy* PrioritizedTextureManager::proxyForDebug() const +{ + return m_proxy; +} + } // namespace cc diff --git a/cc/prioritized_texture_manager.h b/cc/prioritized_texture_manager.h index 92d739f..b0127db 100644 --- a/cc/prioritized_texture_manager.h +++ b/cc/prioritized_texture_manager.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/hash_tables.h" #include "base/memory/scoped_ptr.h" +#include "cc/proxy.h" #include "cc/prioritized_texture.h" #include "cc/priority_calculator.h" #include "cc/texture.h" @@ -31,12 +32,13 @@ struct hash<cc::PrioritizedTexture*> { namespace cc { class PriorityCalculator; +class Proxy; class PrioritizedTextureManager { public: - static scoped_ptr<PrioritizedTextureManager> create(size_t maxMemoryLimitBytes, int maxTextureSize, int pool) + static scoped_ptr<PrioritizedTextureManager> create(size_t maxMemoryLimitBytes, int maxTextureSize, int pool, const Proxy* proxy) { - return make_scoped_ptr(new PrioritizedTextureManager(maxMemoryLimitBytes, maxTextureSize, pool)); + return make_scoped_ptr(new PrioritizedTextureManager(maxMemoryLimitBytes, maxTextureSize, pool, proxy)); } scoped_ptr<PrioritizedTexture> createTexture(gfx::Size size, GLenum format) { @@ -107,6 +109,8 @@ public: // Mark all textures' backings as being in the drawing impl tree. void updateBackingsInDrawingImplTree(); + const Proxy* proxyForDebug() const; + private: friend class PrioritizedTextureTest; @@ -141,7 +145,7 @@ private: return a < b; } - PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool); + PrioritizedTextureManager(size_t maxMemoryLimitBytes, int maxTextureSize, int pool, const Proxy* proxy); bool evictBackingsToReduceMemory(size_t limitBytes, int priorityCutoff, EvictionPolicy, ResourceProvider*); PrioritizedTexture::Backing* createBacking(gfx::Size, GLenum format, ResourceProvider*); @@ -167,6 +171,8 @@ private: typedef base::hash_set<PrioritizedTexture*> TextureSet; typedef std::vector<PrioritizedTexture*> TextureVector; + const Proxy* m_proxy; + TextureSet m_textures; // This list is always sorted in eviction order, with the exception the // newly-allocated or recycled textures at the very end of the tail that diff --git a/cc/prioritized_texture_unittest.cc b/cc/prioritized_texture_unittest.cc index 9c37395..6511dce 100644 --- a/cc/prioritized_texture_unittest.cc +++ b/cc/prioritized_texture_unittest.cc @@ -9,6 +9,7 @@ #include "cc/prioritized_texture_manager.h" #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread #include "cc/test/fake_graphics_context.h" +#include "cc/test/fake_proxy.h" #include "cc/test/tiled_layer_test_common.h" #include "cc/texture.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,17 +22,18 @@ namespace cc { class PrioritizedTextureTest : public testing::Test { public: PrioritizedTextureTest() - : m_textureSize(256, 256) + : m_proxy(scoped_ptr<Thread>(NULL)) + , m_textureSize(256, 256) , m_textureFormat(GL_RGBA) , m_context(WebKit::createFakeGraphicsContext()) { - DebugScopedSetImplThread implThread; + DebugScopedSetImplThread implThread(&m_proxy); m_resourceProvider = ResourceProvider::create(m_context.get()); } virtual ~PrioritizedTextureTest() { - DebugScopedSetImplThread implThread; + DebugScopedSetImplThread implThread(&m_proxy); m_resourceProvider.reset(); } @@ -42,7 +44,7 @@ public: scoped_ptr<PrioritizedTextureManager> createManager(size_t maxTextures) { - return PrioritizedTextureManager::create(texturesMemorySize(maxTextures), 1024, 0); + return PrioritizedTextureManager::create(texturesMemorySize(maxTextures), 1024, 0, &m_proxy); } bool validateTexture(scoped_ptr<PrioritizedTexture>& texture, bool requestLate) @@ -51,7 +53,7 @@ public: if (requestLate) texture->requestLate(); textureManagerAssertInvariants(texture->textureManager()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); bool success = texture->canAcquireBackingTexture(); if (success) texture->acquireBackingTexture(resourceProvider()); @@ -66,7 +68,7 @@ public: void textureManagerUpdateBackingsPriorities(PrioritizedTextureManager* textureManager) { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->pushTexturePrioritiesToBackings(); } @@ -78,7 +80,7 @@ public: void textureManagerAssertInvariants(PrioritizedTextureManager* textureManager) { #ifndef NDEBUG - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->assertInvariants(); #endif } @@ -89,6 +91,7 @@ public: } protected: + FakeProxy m_proxy; const IntSize m_textureSize; const GLenum m_textureFormat; scoped_ptr<GraphicsContext> m_context; @@ -135,7 +138,7 @@ TEST_F(PrioritizedTextureTest, requestTextureExceedingMaxLimit) EXPECT_EQ(texturesMemorySize(maxTextures), textureManager->memoryAboveCutoffBytes()); EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -156,7 +159,7 @@ TEST_F(PrioritizedTextureTest, changeMemoryLimits) for (size_t i = 0; i < maxTextures; ++i) validateTexture(textures[i], false); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemory(resourceProvider()); } @@ -169,7 +172,7 @@ TEST_F(PrioritizedTextureTest, changeMemoryLimits) for (size_t i = 0; i < maxTextures; ++i) EXPECT_EQ(validateTexture(textures[i], false), i < 5); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemory(resourceProvider()); } @@ -182,14 +185,14 @@ TEST_F(PrioritizedTextureTest, changeMemoryLimits) for (size_t i = 0; i < maxTextures; ++i) EXPECT_EQ(validateTexture(textures[i], false), i < 4); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemory(resourceProvider()); } EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -213,7 +216,7 @@ TEST_F(PrioritizedTextureTest, changePriorityCutoff) for (size_t i = 0; i < maxTextures; ++i) EXPECT_EQ(validateTexture(textures[i], true), i < 6); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemory(resourceProvider()); } EXPECT_EQ(texturesMemorySize(6), textureManager->memoryAboveCutoffBytes()); @@ -225,7 +228,7 @@ TEST_F(PrioritizedTextureTest, changePriorityCutoff) for (size_t i = 0; i < maxTextures; ++i) EXPECT_EQ(validateTexture(textures[i], false), i < 4); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemory(resourceProvider()); } EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); @@ -233,7 +236,7 @@ TEST_F(PrioritizedTextureTest, changePriorityCutoff) // Do a one-time eviction for one more texture based on priority cutoff PrioritizedTextureManager::BackingList evictedBackings; { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemoryOnImplThread(texturesMemorySize(8), 104, resourceProvider()); textureManager->getEvictedBackings(evictedBackings); EXPECT_EQ(0, evictedBackings.size()); @@ -249,12 +252,12 @@ TEST_F(PrioritizedTextureTest, changePriorityCutoff) for (size_t i = 0; i < maxTextures; ++i) EXPECT_EQ(validateTexture(textures[i], false), i < 4); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->reduceMemory(resourceProvider()); } EXPECT_EQ(texturesMemorySize(4), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -314,7 +317,7 @@ TEST_F(PrioritizedTextureTest, textureManagerPartialUpdateTextures) EXPECT_FALSE(textures[2]->haveBackingTexture()); EXPECT_FALSE(textures[3]->haveBackingTexture()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -354,7 +357,7 @@ TEST_F(PrioritizedTextureTest, textureManagerPrioritiesAreEqual) EXPECT_EQ(texturesMemorySize(8), textureManager->memoryAboveCutoffBytes()); EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -374,7 +377,7 @@ TEST_F(PrioritizedTextureTest, textureManagerDestroyedFirst) EXPECT_TRUE(texture->haveBackingTexture()); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } textureManager.reset(); @@ -402,7 +405,7 @@ TEST_F(PrioritizedTextureTest, textureMovedToNewManager) texture->setTextureManager(0); { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManagerOne->clearAllMemory(resourceProvider()); } textureManagerOne.reset(); @@ -418,7 +421,7 @@ TEST_F(PrioritizedTextureTest, textureMovedToNewManager) EXPECT_TRUE(texture->canAcquireBackingTexture()); EXPECT_TRUE(texture->haveBackingTexture()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManagerTwo->clearAllMemory(resourceProvider()); } @@ -464,7 +467,7 @@ TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableOutsideRootSur EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures()); EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -501,7 +504,7 @@ TEST_F(PrioritizedTextureTest, renderSurfacesReduceMemoryAvailableForRequestLate EXPECT_EQ(texturesMemorySize(4), textureManager->memoryForSelfManagedTextures()); EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -541,7 +544,7 @@ TEST_F(PrioritizedTextureTest, whenRenderSurfaceNotAvailableTexturesAlsoNotAvail EXPECT_EQ(texturesMemorySize(2), textureManager->memoryForSelfManagedTextures()); EXPECT_LE(textureManager->memoryUseBytes(), textureManager->memoryAboveCutoffBytes()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -589,7 +592,7 @@ TEST_F(PrioritizedTextureTest, requestLateBackingsSorting) for (size_t i = 1; i < maxTextures; i += 2) EXPECT_FALSE(textureBackingIsAbovePriorityCutoff(textures[i].get())); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } @@ -614,7 +617,7 @@ TEST_F(PrioritizedTextureTest, clearUploadsToEvictedResources) EXPECT_TRUE(validateTexture(textures[i], false)); ResourceUpdateQueue queue; - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); for (size_t i = 0; i < maxTextures; ++i) { const ResourceUpdate upload = ResourceUpdate::Create( textures[i].get(), NULL, gfx::Rect(), gfx::Rect(), gfx::Vector2d()); @@ -666,7 +669,7 @@ TEST_F(PrioritizedTextureTest, usageStatistics) // Validate the statistics. { - DebugScopedSetImplThread implThread; + DebugScopedSetImplThread implThread(&m_proxy); EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyBytes()); @@ -682,7 +685,7 @@ TEST_F(PrioritizedTextureTest, usageStatistics) // Verify that we still see the old values. { - DebugScopedSetImplThread implThread; + DebugScopedSetImplThread implThread(&m_proxy); EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); EXPECT_EQ(texturesMemorySize(1), textureManager->memoryVisibleBytes()); EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleAndNearbyBytes()); @@ -690,14 +693,14 @@ TEST_F(PrioritizedTextureTest, usageStatistics) // Push priorities to backings, and verify we see the new values. { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->pushTexturePrioritiesToBackings(); EXPECT_EQ(texturesMemorySize(2), textureManager->memoryUseBytes()); EXPECT_EQ(texturesMemorySize(3), textureManager->memoryVisibleBytes()); EXPECT_EQ(texturesMemorySize(4), textureManager->memoryVisibleAndNearbyBytes()); } - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(&m_proxy); textureManager->clearAllMemory(resourceProvider()); } diff --git a/cc/proxy.cc b/cc/proxy.cc index 7b738aa..46ef19f 100644 --- a/cc/proxy.cc +++ b/cc/proxy.cc @@ -7,70 +7,52 @@ #include "cc/proxy.h" #include "cc/thread.h" +#include "cc/thread_impl.h" namespace cc { -namespace { -#ifndef NDEBUG -bool implThreadIsOverridden = false; -bool s_isMainThreadBlocked = false; -#endif -Thread* s_mainThread = 0; -Thread* s_implThread = 0; -} - -void Proxy::setMainThread(Thread* thread) -{ - s_mainThread = thread; -} - -Thread* Proxy::mainThread() +Thread* Proxy::mainThread() const { - return s_mainThread; + return m_mainThread.get(); } -bool Proxy::hasImplThread() +bool Proxy::hasImplThread() const { - return s_implThread; + return m_implThread; } -void Proxy::setImplThread(Thread* thread) +Thread* Proxy::implThread() const { - s_implThread = thread; + return m_implThread.get(); } -Thread* Proxy::implThread() +Thread* Proxy::currentThread() const { - return s_implThread; -} - -Thread* Proxy::currentThread() -{ - if (s_mainThread && s_mainThread->belongsToCurrentThread()) - return s_mainThread; - if (s_implThread && s_implThread->belongsToCurrentThread()) - return s_implThread; + if (mainThread() && mainThread()->belongsToCurrentThread()) + return mainThread(); + if (implThread() && implThread()->belongsToCurrentThread()) + return implThread(); return 0; } -bool Proxy::isMainThread() +bool Proxy::isMainThread() const { #ifndef NDEBUG - DCHECK(s_mainThread); - if (implThreadIsOverridden) + DCHECK(mainThread()); + if (m_implThreadIsOverridden) return false; - return s_mainThread->belongsToCurrentThread(); + return mainThread()->belongsToCurrentThread(); #else return true; #endif } -bool Proxy::isImplThread() +bool Proxy::isImplThread() const { #ifndef NDEBUG - if (implThreadIsOverridden) + if (m_implThreadIsOverridden) return true; - return s_implThread && s_implThread->belongsToCurrentThread(); + return implThread() && implThread()->belongsToCurrentThread(); #else return true; #endif @@ -79,14 +61,14 @@ bool Proxy::isImplThread() #ifndef NDEBUG void Proxy::setCurrentThreadIsImplThread(bool isImplThread) { - implThreadIsOverridden = isImplThread; + m_implThreadIsOverridden = isImplThread; } #endif -bool Proxy::isMainThreadBlocked() +bool Proxy::isMainThreadBlocked() const { #ifndef NDEBUG - return s_isMainThreadBlocked; + return m_isMainThreadBlocked; #else return true; #endif @@ -95,13 +77,18 @@ bool Proxy::isMainThreadBlocked() #ifndef NDEBUG void Proxy::setMainThreadBlocked(bool isMainThreadBlocked) { - s_isMainThreadBlocked = isMainThreadBlocked; + m_isMainThreadBlocked = isMainThreadBlocked; } #endif -Proxy::Proxy() +Proxy::Proxy(scoped_ptr<Thread> implThread) + : m_mainThread(ThreadImpl::createForCurrentThread()) + , m_implThread(implThread.Pass()) +#ifndef NDEBUG + , m_implThreadIsOverridden(false) + , m_isMainThreadBlocked(false) +#endif { - DCHECK(isMainThread()); } Proxy::~Proxy() @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/time.h" +#include "base/memory/scoped_ptr.h" #include <public/WebCompositorOutputSurface.h> namespace gfx { @@ -25,15 +26,21 @@ struct RendererCapabilities; // the compositor over to the compositor implementation. class Proxy { public: - static void setMainThread(Thread*); - static Thread* mainThread(); - - static bool hasImplThread(); - static void setImplThread(Thread*); - static Thread* implThread(); + Thread* mainThread() const; + bool hasImplThread() const; + Thread* implThread() const; // Returns 0 if the current thread is neither the main thread nor the impl thread. - static Thread* currentThread(); + Thread* currentThread() const; + + // Debug hooks + bool isMainThread() const; + bool isImplThread() const; + bool isMainThreadBlocked() const; +#ifndef NDEBUG + void setMainThreadBlocked(bool); + void setCurrentThreadIsImplThread(bool); +#endif virtual ~Proxy(); @@ -89,46 +96,45 @@ public: virtual void acquireLayerTextures() = 0; - // Debug hooks - static bool isMainThread(); - static bool isImplThread(); - static bool isMainThreadBlocked(); -#ifndef NDEBUG - static void setMainThreadBlocked(bool); -#endif - // Testing hooks virtual void loseContext() = 0; -#ifndef NDEBUG - static void setCurrentThreadIsImplThread(bool); -#endif - protected: - Proxy(); + explicit Proxy(scoped_ptr<Thread> implThread); friend class DebugScopedSetImplThread; + friend class DebugScopedSetMainThread; friend class DebugScopedSetMainThreadBlocked; private: DISALLOW_COPY_AND_ASSIGN(Proxy); + + scoped_ptr<Thread> m_mainThread; + scoped_ptr<Thread> m_implThread; +#ifndef NDEBUG + bool m_implThreadIsOverridden; + bool m_isMainThreadBlocked; +#endif }; class DebugScopedSetMainThreadBlocked { public: - DebugScopedSetMainThreadBlocked() + explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) + : m_proxy(proxy) { #ifndef NDEBUG - DCHECK(!Proxy::isMainThreadBlocked()); - Proxy::setMainThreadBlocked(true); + DCHECK(!m_proxy->isMainThreadBlocked()); + m_proxy->setMainThreadBlocked(true); #endif } ~DebugScopedSetMainThreadBlocked() { #ifndef NDEBUG - DCHECK(Proxy::isMainThreadBlocked()); - Proxy::setMainThreadBlocked(false); + DCHECK(m_proxy->isMainThreadBlocked()); + m_proxy->setMainThreadBlocked(false); #endif } +private: + Proxy* m_proxy; }; } diff --git a/cc/quad_culler_unittest.cc b/cc/quad_culler_unittest.cc index a9f15bb..05060d4d 100644 --- a/cc/quad_culler_unittest.cc +++ b/cc/quad_culler_unittest.cc @@ -88,7 +88,6 @@ static void appendQuads(QuadList& quadList, SharedQuadStateList& sharedStateList } #define DECLARE_AND_INITIALIZE_TEST_QUADS \ - DebugScopedSetImplThread impl; \ QuadList quadList; \ SharedQuadStateList sharedStateList; \ std::vector<LayerImpl*> renderSurfaceLayerList; \ diff --git a/cc/rate_limiter.cc b/cc/rate_limiter.cc index fab541e..28254f7 100644 --- a/cc/rate_limiter.cc +++ b/cc/rate_limiter.cc @@ -7,19 +7,19 @@ #include "cc/rate_limiter.h" #include "base/debug/trace_event.h" -#include "cc/proxy.h" #include "cc/thread.h" #include <public/WebGraphicsContext3D.h> namespace cc { -scoped_refptr<RateLimiter> RateLimiter::create(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client) +scoped_refptr<RateLimiter> RateLimiter::create(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client, Thread* thread) { - return make_scoped_refptr(new RateLimiter(context, client)); + return make_scoped_refptr(new RateLimiter(context, client, thread)); } -RateLimiter::RateLimiter(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client) - : m_context(context) +RateLimiter::RateLimiter(WebKit::WebGraphicsContext3D* context, RateLimiterClient *client, Thread* thread) + : m_thread(thread) + , m_context(context) , m_active(false) , m_client(client) { @@ -37,7 +37,7 @@ void RateLimiter::start() TRACE_EVENT0("cc", "RateLimiter::start"); m_active = true; - Proxy::mainThread()->postTask(base::Bind(&RateLimiter::rateLimitContext, this)); + m_thread->postTask(base::Bind(&RateLimiter::rateLimitContext, this)); } void RateLimiter::stop() diff --git a/cc/rate_limiter.h b/cc/rate_limiter.h index 1630864..935e64b 100644 --- a/cc/rate_limiter.h +++ b/cc/rate_limiter.h @@ -13,6 +13,8 @@ class WebGraphicsContext3D; namespace cc { +class Thread; + class RateLimiterClient { public: virtual void rateLimit() = 0; @@ -24,7 +26,7 @@ public: // compositor. class RateLimiter : public base::RefCounted<RateLimiter> { public: - static scoped_refptr<RateLimiter> create(WebKit::WebGraphicsContext3D*, RateLimiterClient*); + static scoped_refptr<RateLimiter> create(WebKit::WebGraphicsContext3D*, RateLimiterClient*, Thread*); void start(); @@ -32,7 +34,7 @@ public: void stop(); private: - RateLimiter(WebKit::WebGraphicsContext3D*, RateLimiterClient*); + RateLimiter(WebKit::WebGraphicsContext3D*, RateLimiterClient*, Thread*); ~RateLimiter(); friend class base::RefCounted<RateLimiter>; @@ -43,6 +45,7 @@ private: WebKit::WebGraphicsContext3D* m_context; bool m_active; RateLimiterClient *m_client; + Thread* m_thread; }; } diff --git a/cc/render_surface_unittest.cc b/cc/render_surface_unittest.cc index 397cfc6..8e11d8e 100644 --- a/cc/render_surface_unittest.cc +++ b/cc/render_surface_unittest.cc @@ -39,9 +39,6 @@ TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) // This test checks that surfacePropertyChanged() has the correct behavior. // - // This will fake that we are on the correct thread for testing purposes. - DebugScopedSetImplThread setImplThread; - scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(1); owningLayer->createRenderSurface(); ASSERT_TRUE(owningLayer->renderSurface()); @@ -76,9 +73,6 @@ TEST(RenderSurfaceTest, verifySurfaceChangesAreTrackedProperly) TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectSharedQuadState) { - // This will fake that we are on the correct thread for testing purposes. - DebugScopedSetImplThread setImplThread; - scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); @@ -130,9 +124,6 @@ private: TEST(RenderSurfaceTest, sanityCheckSurfaceCreatesCorrectRenderPass) { - // This will fake that we are on the correct thread for testing purposes. - DebugScopedSetImplThread setImplThread; - scoped_ptr<LayerImpl> rootLayer = LayerImpl::create(1); scoped_ptr<LayerImpl> owningLayer = LayerImpl::create(2); diff --git a/cc/renderer.h b/cc/renderer.h index 11e00fc..df0c9431 100644 --- a/cc/renderer.h +++ b/cc/renderer.h @@ -24,6 +24,7 @@ public: virtual void setFullRootLayerDamage() = 0; virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) = 0; virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) = 0; + virtual bool hasImplThread() const = 0; protected: virtual ~RendererClient() { } }; diff --git a/cc/resource_provider.cc b/cc/resource_provider.cc index dab281a..973c947 100644 --- a/cc/resource_provider.cc +++ b/cc/resource_provider.cc @@ -14,7 +14,6 @@ #include "base/string_split.h" #include "base/string_util.h" #include "cc/gl_renderer.h" // For the GLC() macro. -#include "cc/proxy.h" #include "cc/texture_uploader.h" #include "third_party/khronos/GLES2/gl2.h" #include "third_party/khronos/GLES2/gl2ext.h" @@ -138,13 +137,13 @@ ResourceProvider::~ResourceProvider() WebGraphicsContext3D* ResourceProvider::graphicsContext3D() { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); return m_context->context3D(); } bool ResourceProvider::inUseByConsumer(ResourceId id) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); CHECK(it != m_resources.end()); Resource* resource = &it->second; @@ -167,7 +166,7 @@ ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const gfx::Size& size, GLenum format, TextureUsageHint hint) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); unsigned textureId = 0; WebGraphicsContext3D* context3d = m_context->context3D(); DCHECK(context3d); @@ -193,7 +192,7 @@ ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx::Size& size) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; @@ -205,7 +204,7 @@ ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture(unsigned textureId) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); DCHECK(m_context->context3D()); ResourceId id = m_nextId++; Resource resource(textureId, 0, gfx::Size(), 0); @@ -216,7 +215,7 @@ ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture void ResourceProvider::deleteResource(ResourceId id) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); CHECK(it != m_resources.end()); Resource* resource = &it->second; @@ -248,7 +247,7 @@ void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) void ResourceProvider::deleteOwnedResources(int pool) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceIdArray toDelete; for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end(); ++it) { if (it->second.pool == pool && !it->second.external && !it->second.markedForDeletion) @@ -268,7 +267,7 @@ ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) void ResourceProvider::upload(ResourceId id, const uint8_t* image, const gfx::Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); CHECK(it != m_resources.end()); Resource* resource = &it->second; @@ -331,7 +330,7 @@ double ResourceProvider::estimatedUploadsPerSecond() void ResourceProvider::flush() { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); WebGraphicsContext3D* context3d = m_context->context3D(); if (context3d) context3d->flush(); @@ -339,7 +338,7 @@ void ResourceProvider::flush() bool ResourceProvider::shallowFlushIfSupported() { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); WebGraphicsContext3D* context3d = m_context->context3D(); if (!context3d || !m_useShallowFlush) return false; @@ -350,7 +349,7 @@ bool ResourceProvider::shallowFlushIfSupported() const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); if (it == m_resources.end()) { @@ -378,7 +377,7 @@ const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) void ResourceProvider::unlockForRead(ResourceId id) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); CHECK(it != m_resources.end()); Resource* resource = &it->second; @@ -389,7 +388,7 @@ void ResourceProvider::unlockForRead(ResourceId id) const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); CHECK(it != m_resources.end()); Resource* resource = &it->second; @@ -403,7 +402,7 @@ const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) void ResourceProvider::unlockForWrite(ResourceId id) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::iterator it = m_resources.find(id); CHECK(it != m_resources.end()); Resource* resource = &it->second; @@ -486,7 +485,7 @@ ResourceProvider::ResourceProvider(GraphicsContext* context) bool ResourceProvider::initialize() { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); WebGraphicsContext3D* context3d = m_context->context3D(); if (!context3d) { m_maxTextureSize = INT_MAX / 2; @@ -522,7 +521,7 @@ bool ResourceProvider::initialize() int ResourceProvider::createChild(int pool) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); Child childInfo; childInfo.pool = pool; int child = m_nextChild++; @@ -532,7 +531,7 @@ int ResourceProvider::createChild(int pool) void ResourceProvider::destroyChild(int child) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ChildMap::iterator it = m_children.find(child); DCHECK(it != m_children.end()); deleteOwnedResources(it->second.pool); @@ -542,7 +541,7 @@ void ResourceProvider::destroyChild(int child) const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ChildMap::const_iterator it = m_children.find(child); DCHECK(it != m_children.end()); return it->second.childToParentMap; @@ -550,7 +549,7 @@ const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent(const ResourceIdArray& resources) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); TransferableResourceList list; list.syncPoint = 0; WebGraphicsContext3D* context3d = m_context->context3D(); @@ -572,7 +571,7 @@ ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& resources) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); TransferableResourceList list; list.syncPoint = 0; WebGraphicsContext3D* context3d = m_context->context3D(); @@ -599,7 +598,7 @@ ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild( void ResourceProvider::receiveFromChild(int child, const TransferableResourceList& resources) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); WebGraphicsContext3D* context3d = m_context->context3D(); if (!context3d || !context3d->makeContextCurrent()) { // FIXME: Implement this path for software compositing. @@ -631,7 +630,7 @@ void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis void ResourceProvider::receiveFromParent(const TransferableResourceList& resources) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); WebGraphicsContext3D* context3d = m_context->context3D(); if (!context3d || !context3d->makeContextCurrent()) { // FIXME: Implement this path for software compositing. @@ -655,7 +654,7 @@ void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceId id, TransferableResource* resource) { - DCHECK(Proxy::isImplThread()); + DCHECK(m_threadChecker.CalledOnValidThread()); ResourceMap::const_iterator it = m_resources.find(id); CHECK(it != m_resources.end()); const Resource* source = &it->second; diff --git a/cc/resource_provider.h b/cc/resource_provider.h index 45b99eb..f273550 100644 --- a/cc/resource_provider.h +++ b/cc/resource_provider.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/hash_tables.h" #include "base/memory/scoped_ptr.h" +#include "base/threading/thread_checker.h" #include "cc/graphics_context.h" #include "cc/texture_copier.h" #include "third_party/khronos/GLES2/gl2.h" @@ -32,8 +33,8 @@ class LayerTextureSubImage; class TextureCopier; class TextureUploader; -// Thread-safety notes: this class is not thread-safe and can only be called -// from the thread it was created on (in practice, the compositor thread). +// This class is not thread-safe and can only be called from the thread it was +// created on (in practice, the impl thread). class ResourceProvider { public: typedef unsigned ResourceId; @@ -278,6 +279,8 @@ private: scoped_ptr<AcceleratedTextureCopier> m_textureCopier; int m_maxTextureSize; + base::ThreadChecker m_threadChecker; + DISALLOW_COPY_AND_ASSIGN(ResourceProvider); }; diff --git a/cc/resource_provider_unittest.cc b/cc/resource_provider_unittest.cc index f3c852f..f116142 100644 --- a/cc/resource_provider_unittest.cc +++ b/cc/resource_provider_unittest.cc @@ -10,7 +10,7 @@ #include "cc/graphics_context.h" #include "cc/scoped_ptr_deque.h" #include "cc/scoped_ptr_hash_map.h" -#include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread +#include "cc/stubs/int_rect.h" #include "cc/test/compositor_fake_web_graphics_context_3d.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "testing/gtest/include/gtest/gtest.h" @@ -300,7 +300,6 @@ public: } protected: - DebugScopedSetImplThread implThread; scoped_ptr<ContextSharedData> m_sharedData; scoped_ptr<GraphicsContext> m_context; scoped_ptr<ResourceProvider> m_resourceProvider; diff --git a/cc/resource_update_controller.cc b/cc/resource_update_controller.cc index 55c5277..4afb987 100644 --- a/cc/resource_update_controller.cc +++ b/cc/resource_update_controller.cc @@ -8,7 +8,6 @@ #include "base/debug/trace_event.h" #include "cc/prioritized_texture.h" -#include "cc/proxy.h" #include "cc/resource_provider.h" #include "cc/texture_copier.h" #include "cc/thread.h" @@ -70,8 +69,9 @@ size_t ResourceUpdateController::maxFullUpdatesPerTick( return texturesPerTick ? texturesPerTick : 1; } -ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider) +ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider, bool hasImplThread) : m_client(client) + , m_hasImplThread(hasImplThread) , m_queue(queue.Pass()) , m_resourceProvider(resourceProvider) , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider)) @@ -131,10 +131,10 @@ void ResourceUpdateController::updateTexture(ResourceUpdate update) DCHECK(m_resourceProvider->resourceType(texture->resourceId()) == ResourceProvider::GLTexture); - WebGraphicsContext3D* paintContext = Proxy::hasImplThread() ? + WebGraphicsContext3D* paintContext = m_hasImplThread ? WebSharedGraphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThreadContext(); - GrContext* paintGrContext = Proxy::hasImplThread() ? + GrContext* paintGrContext = m_hasImplThread ? WebSharedGraphicsContext3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrContext(); diff --git a/cc/resource_update_controller.h b/cc/resource_update_controller.h index 7405149..375246c 100644 --- a/cc/resource_update_controller.h +++ b/cc/resource_update_controller.h @@ -26,9 +26,9 @@ protected: class ResourceUpdateController { public: - static scoped_ptr<ResourceUpdateController> create(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider) + static scoped_ptr<ResourceUpdateController> create(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider, bool hasImplThread) { - return make_scoped_ptr(new ResourceUpdateController(client, thread, queue.Pass(), resourceProvider)); + return make_scoped_ptr(new ResourceUpdateController(client, thread, queue.Pass(), resourceProvider, hasImplThread)); } static size_t maxPartialTextureUpdates(); @@ -47,7 +47,7 @@ public: virtual size_t updateMoreTexturesSize() const; protected: - ResourceUpdateController(ResourceUpdateControllerClient*, Thread*, scoped_ptr<ResourceUpdateQueue>, ResourceProvider*); + ResourceUpdateController(ResourceUpdateControllerClient*, Thread*, scoped_ptr<ResourceUpdateQueue>, ResourceProvider*, bool hasImplThread); private: static size_t maxFullUpdatesPerTick(ResourceProvider*); @@ -62,6 +62,7 @@ private: void onTimerFired(); ResourceUpdateControllerClient* m_client; + bool m_hasImplThread; scoped_ptr<ResourceUpdateQueue> m_queue; bool m_contentsTexturesPurged; ResourceProvider* m_resourceProvider; diff --git a/cc/resource_update_controller_unittest.cc b/cc/resource_update_controller_unittest.cc index 9c46af5..39284f7 100644 --- a/cc/resource_update_controller_unittest.cc +++ b/cc/resource_update_controller_unittest.cc @@ -7,6 +7,7 @@ #include "cc/resource_update_controller.h" #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread +#include "cc/test/fake_proxy.h" #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/scheduler_test_common.h" @@ -63,8 +64,9 @@ private: class ResourceUpdateControllerTest : public Test { public: ResourceUpdateControllerTest() - : m_queue(make_scoped_ptr(new ResourceUpdateQueue)) - , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool)) + : m_proxy(scoped_ptr<Thread>(NULL)) + , m_queue(make_scoped_ptr(new ResourceUpdateQueue)) + , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool, &m_proxy)) , m_fullUploadCountExpected(0) , m_partialCountExpected(0) , m_totalUploadCountExpected(0) @@ -79,7 +81,7 @@ public: ~ResourceUpdateControllerTest() { DebugScopedSetImplThreadAndMainThreadBlocked - implThreadAndMainThreadBlocked; + implThreadAndMainThreadBlocked(&m_proxy); m_textureManager->clearAllMemory(m_resourceProvider.get()); } @@ -122,7 +124,6 @@ protected: } m_textureManager->prioritizeTextures(); - DebugScopedSetImplThread implThread; m_resourceProvider = ResourceProvider::create(m_context.get()); } @@ -169,18 +170,20 @@ protected: void updateTextures() { DebugScopedSetImplThreadAndMainThreadBlocked - implThreadAndMainThreadBlocked; + implThreadAndMainThreadBlocked(&m_proxy); scoped_ptr<ResourceUpdateController> updateController = ResourceUpdateController::create( NULL, - Proxy::implThread(), + m_proxy.implThread(), m_queue.Pass(), - m_resourceProvider.get()); + m_resourceProvider.get(), + m_proxy.hasImplThread()); updateController->finalize(); } protected: // Classes required to interact and test the ResourceUpdateController + FakeProxy m_proxy; scoped_ptr<GraphicsContext> m_context; scoped_ptr<ResourceProvider> m_resourceProvider; scoped_ptr<ResourceUpdateQueue> m_queue; @@ -340,7 +343,7 @@ public: protected: FakeResourceUpdateController(cc::ResourceUpdateControllerClient* client, cc::Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider) - : cc::ResourceUpdateController(client, thread, queue.Pass(), resourceProvider) + : cc::ResourceUpdateController(client, thread, queue.Pass(), resourceProvider, false) , m_updateMoreTexturesSize(0) { } base::TimeTicks m_now; @@ -365,7 +368,7 @@ TEST_F(ResourceUpdateControllerTest, UpdateMoreTextures) appendPartialUploadsToUpdateQueue(0); DebugScopedSetImplThreadAndMainThreadBlocked - implThreadAndMainThreadBlocked; + implThreadAndMainThreadBlocked(&m_proxy); scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateController::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); controller->setNow( @@ -411,7 +414,7 @@ TEST_F(ResourceUpdateControllerTest, NoMoreUpdates) appendPartialUploadsToUpdateQueue(0); DebugScopedSetImplThreadAndMainThreadBlocked - implThreadAndMainThreadBlocked; + implThreadAndMainThreadBlocked(&m_proxy); scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateController::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); controller->setNow( @@ -451,7 +454,7 @@ TEST_F(ResourceUpdateControllerTest, UpdatesCompleteInFiniteTime) appendPartialUploadsToUpdateQueue(0); DebugScopedSetImplThreadAndMainThreadBlocked - implThreadAndMainThreadBlocked; + implThreadAndMainThreadBlocked(&m_proxy); scoped_ptr<FakeResourceUpdateController> controller(FakeResourceUpdateController::create(&client, &thread, m_queue.Pass(), m_resourceProvider.get())); controller->setNow( diff --git a/cc/scoped_texture_unittest.cc b/cc/scoped_texture_unittest.cc index 0be883d..fdd4e30 100644 --- a/cc/scoped_texture_unittest.cc +++ b/cc/scoped_texture_unittest.cc @@ -7,7 +7,6 @@ #include "cc/scoped_texture.h" #include "cc/renderer.h" -#include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread #include "cc/test/fake_graphics_context.h" #include "cc/test/tiled_layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -22,7 +21,6 @@ namespace { TEST(ScopedTextureTest, NewScopedTexture) { scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); - DebugScopedSetImplThread implThread; scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(context.get())); scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.get()); @@ -37,7 +35,6 @@ TEST(ScopedTextureTest, NewScopedTexture) TEST(ScopedTextureTest, CreateScopedTexture) { scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); - DebugScopedSetImplThread implThread; scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(context.get())); scoped_ptr<ScopedTexture> texture = ScopedTexture::create(resourceProvider.get()); texture->allocate(Renderer::ImplPool, IntSize(30, 30), GL_RGBA, ResourceProvider::TextureUsageAny); @@ -54,7 +51,6 @@ TEST(ScopedTextureTest, CreateScopedTexture) TEST(ScopedTextureTest, ScopedTextureIsDeleted) { scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); - DebugScopedSetImplThread implThread; scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(context.get())); { @@ -82,7 +78,6 @@ TEST(ScopedTextureTest, ScopedTextureIsDeleted) TEST(ScopedTextureTest, LeakScopedTexture) { scoped_ptr<GraphicsContext> context(createFakeGraphicsContext()); - DebugScopedSetImplThread implThread; scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(context.get())); { diff --git a/cc/scrollbar_animation_controller_linear_fade_unittest.cc b/cc/scrollbar_animation_controller_linear_fade_unittest.cc index 32537cb..bbd6882 100644 --- a/cc/scrollbar_animation_controller_linear_fade_unittest.cc +++ b/cc/scrollbar_animation_controller_linear_fade_unittest.cc @@ -30,8 +30,6 @@ protected: m_scrollbarController->setHorizontalScrollbarLayer(m_scrollbarLayer.get()); } - DebugScopedSetImplThread implThread; - scoped_ptr<ScrollbarAnimationControllerLinearFade> m_scrollbarController; scoped_ptr<LayerImpl> m_scrollLayer; LayerImpl* m_contentLayer; diff --git a/cc/scrollbar_layer_unittest.cc b/cc/scrollbar_layer_unittest.cc index fb68734..736d4b5 100644 --- a/cc/scrollbar_layer_unittest.cc +++ b/cc/scrollbar_layer_unittest.cc @@ -45,8 +45,6 @@ public: TEST(ScrollbarLayerTest, resolveScrollLayerPointer) { - DebugScopedSetImplThread impl; - WebKit::WebScrollbarThemePainter painter; { @@ -86,8 +84,6 @@ TEST(ScrollbarLayerTest, resolveScrollLayerPointer) TEST(ScrollbarLayerTest, scrollOffsetSynchronization) { - DebugScopedSetImplThread impl; - WebKit::WebScrollbarThemePainter painter; scoped_ptr<WebKit::WebScrollbar> scrollbar(FakeWebScrollbar::create()); diff --git a/cc/single_thread_proxy.cc b/cc/single_thread_proxy.cc index 7fe679f..dfc86fb 100644 --- a/cc/single_thread_proxy.cc +++ b/cc/single_thread_proxy.cc @@ -11,6 +11,7 @@ #include "cc/graphics_context.h" #include "cc/layer_tree_host.h" #include "cc/resource_update_controller.h" +#include "cc/thread.h" namespace cc { @@ -20,7 +21,8 @@ scoped_ptr<Proxy> SingleThreadProxy::create(LayerTreeHost* layerTreeHost) } SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) - : m_layerTreeHost(layerTreeHost) + : Proxy(scoped_ptr<Thread>(NULL)) + , m_layerTreeHost(layerTreeHost) , m_contextLost(false) , m_rendererInitialized(false) , m_nextFrameIsNewlyCommittedFrame(false) @@ -32,7 +34,7 @@ SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layerTreeHost) void SingleThreadProxy::start() { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(this); m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl(this); } @@ -71,7 +73,7 @@ void SingleThreadProxy::finishAllRendering() { DCHECK(Proxy::isMainThread()); { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(this); m_layerTreeHostImpl->finishAllRendering(); } } @@ -99,7 +101,7 @@ void SingleThreadProxy::setSurfaceReady() void SingleThreadProxy::setVisible(bool visible) { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(this); m_layerTreeHostImpl->setVisible(visible); } @@ -108,7 +110,7 @@ bool SingleThreadProxy::initializeRenderer() DCHECK(Proxy::isMainThread()); DCHECK(m_contextBeforeInitialization.get()); { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(this); bool ok = m_layerTreeHostImpl->initializeRenderer(m_contextBeforeInitialization.Pass()); if (ok) { m_rendererInitialized = true; @@ -131,8 +133,8 @@ bool SingleThreadProxy::recreateContext() bool initialized; { - DebugScopedSetMainThreadBlocked mainThreadBlocked; - DebugScopedSetImplThread impl; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); + DebugScopedSetImplThread impl(this); if (!m_layerTreeHostImpl->contentsTexturesPurged()) m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); initialized = m_layerTreeHostImpl->initializeRenderer(context.Pass()); @@ -179,8 +181,8 @@ void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue) DCHECK(Proxy::isMainThread()); // Commit immediately { - DebugScopedSetMainThreadBlocked mainThreadBlocked; - DebugScopedSetImplThread impl; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); + DebugScopedSetImplThread impl(this); base::TimeTicks startTime = base::TimeTicks::HighResNow(); m_layerTreeHostImpl->beginCommit(); @@ -193,7 +195,8 @@ void SingleThreadProxy::doCommit(scoped_ptr<ResourceUpdateQueue> queue) NULL, Proxy::mainThread(), queue.Pass(), - m_layerTreeHostImpl->resourceProvider()); + m_layerTreeHostImpl->resourceProvider(), + hasImplThread()); updateController->finalize(); m_layerTreeHost->finishCommitOnImplThread(m_layerTreeHostImpl.get()); @@ -254,8 +257,8 @@ void SingleThreadProxy::stop() TRACE_EVENT0("cc", "SingleThreadProxy::stop"); DCHECK(Proxy::isMainThread()); { - DebugScopedSetMainThreadBlocked mainThreadBlocked; - DebugScopedSetImplThread impl; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); + DebugScopedSetImplThread impl(this); if (!m_layerTreeHostImpl->contentsTexturesPurged()) m_layerTreeHost->deleteContentsTexturesOnImplThread(m_layerTreeHostImpl->resourceProvider()); @@ -277,7 +280,7 @@ void SingleThreadProxy::setNeedsCommitOnImplThread() void SingleThreadProxy::postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) { DCHECK(Proxy::isImplThread()); - DebugScopedSetMainThread main; + DebugScopedSetMainThread main(this); m_layerTreeHost->setAnimationEvents(events.Pass(), wallClockTime); } @@ -318,7 +321,7 @@ void SingleThreadProxy::compositeImmediately() void SingleThreadProxy::forceSerializeOnSwapBuffers() { { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(this); if (m_rendererInitialized) m_layerTreeHostImpl->renderer()->doNoOp(); } @@ -339,7 +342,7 @@ bool SingleThreadProxy::commitAndComposite() // Unlink any texture backings that were deleted PrioritizedTextureManager::BackingList evictedContentsTexturesBackings; { - DebugScopedSetImplThread implThread; + DebugScopedSetImplThread impl(this); m_layerTreeHost->contentsTextureManager()->getEvictedBackings(evictedContentsTexturesBackings); } m_layerTreeHost->contentsTextureManager()->unlinkEvictedBackings(evictedContentsTexturesBackings); @@ -361,7 +364,7 @@ bool SingleThreadProxy::doComposite() { DCHECK(!m_contextLost); { - DebugScopedSetImplThread impl; + DebugScopedSetImplThread impl(this); if (!m_layerTreeHostImpl->visible()) return false; diff --git a/cc/single_thread_proxy.h b/cc/single_thread_proxy.h index 91e0810..fa3ce013 100644 --- a/cc/single_thread_proxy.h +++ b/cc/single_thread_proxy.h @@ -91,42 +91,58 @@ private: // code is running on the impl thread to satisfy assertion checks. class DebugScopedSetImplThread { public: - DebugScopedSetImplThread() + explicit DebugScopedSetImplThread(Proxy* proxy) + : m_proxy(proxy) { #ifndef NDEBUG - Proxy::setCurrentThreadIsImplThread(true); + m_previousValue = m_proxy->m_implThreadIsOverridden; + m_proxy->setCurrentThreadIsImplThread(true); #endif } ~DebugScopedSetImplThread() { #ifndef NDEBUG - Proxy::setCurrentThreadIsImplThread(false); + m_proxy->setCurrentThreadIsImplThread(m_previousValue); #endif } +private: + bool m_previousValue; + Proxy* m_proxy; }; // For use in the single-threaded case. In debug builds, it pretends that the // code is running on the main thread to satisfy assertion checks. class DebugScopedSetMainThread { public: - DebugScopedSetMainThread() + explicit DebugScopedSetMainThread(Proxy* proxy) + : m_proxy(proxy) { #ifndef NDEBUG - Proxy::setCurrentThreadIsImplThread(false); + m_previousValue = m_proxy->m_implThreadIsOverridden; + m_proxy->setCurrentThreadIsImplThread(false); #endif } ~DebugScopedSetMainThread() { #ifndef NDEBUG - Proxy::setCurrentThreadIsImplThread(true); + m_proxy->setCurrentThreadIsImplThread(m_previousValue); #endif } +private: + bool m_previousValue; + Proxy* m_proxy; }; // For use in the single-threaded case. In debug builds, it pretends that the // code is running on the impl thread and that the main thread is blocked to // satisfy assertion checks class DebugScopedSetImplThreadAndMainThreadBlocked { +public: + explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy) + : m_implThread(proxy) + , m_mainThreadBlocked(proxy) + { + } private: DebugScopedSetImplThread m_implThread; DebugScopedSetMainThreadBlocked m_mainThreadBlocked; diff --git a/cc/software_renderer.cc b/cc/software_renderer.cc index 9592039..7439ae8 100644 --- a/cc/software_renderer.cc +++ b/cc/software_renderer.cc @@ -339,7 +339,7 @@ void SoftwareRenderer::drawUnsupportedQuad(const DrawingFrame& frame, const Draw bool SoftwareRenderer::swapBuffers() { - if (Proxy::hasImplThread()) + if (m_client->hasImplThread()) m_client->onSwapBuffersComplete(); return true; } diff --git a/cc/software_renderer_unittest.cc b/cc/software_renderer_unittest.cc index a04864a..3eb4012 100644 --- a/cc/software_renderer_unittest.cc +++ b/cc/software_renderer_unittest.cc @@ -10,7 +10,6 @@ #include "cc/render_pass.h" #include "cc/render_pass_draw_quad.h" #include "cc/settings.h" -#include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread #include "cc/solid_color_draw_quad.h" #include "cc/test/animation_test_common.h" #include "cc/test/fake_web_compositor_output_surface.h" @@ -50,10 +49,9 @@ public: virtual void setFullRootLayerDamage() OVERRIDE { } virtual void setManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { }; virtual void enforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy) OVERRIDE { }; + virtual bool hasImplThread() const OVERRIDE { return false; } protected: - DebugScopedSetImplThread m_alwaysImplThread; - scoped_ptr<FakeWebCompositorOutputSurface> m_outputSurface; scoped_ptr<ResourceProvider> m_resourceProvider; scoped_ptr<SoftwareRenderer> m_renderer; diff --git a/cc/solid_color_layer_impl_unittest.cc b/cc/solid_color_layer_impl_unittest.cc index c43ca5c..01da554 100644 --- a/cc/solid_color_layer_impl_unittest.cc +++ b/cc/solid_color_layer_impl_unittest.cc @@ -21,8 +21,6 @@ namespace { TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) { - DebugScopedSetImplThread scopedImplThread; - MockQuadCuller quadCuller; IntSize layerSize = IntSize(800, 600); IntRect visibleContentRect = IntRect(IntPoint(), layerSize); @@ -42,8 +40,6 @@ TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) { - DebugScopedSetImplThread scopedImplThread; - SkColor testColor = 0xFFA55AFF; MockQuadCuller quadCuller; @@ -67,8 +63,6 @@ TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) { - DebugScopedSetImplThread scopedImplThread; - const float opacity = 0.5f; MockQuadCuller quadCuller; diff --git a/cc/test/fake_proxy.cc b/cc/test/fake_proxy.cc new file mode 100644 index 0000000..fad6c69 --- /dev/null +++ b/cc/test/fake_proxy.cc @@ -0,0 +1,52 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" + +#include "cc/test/fake_proxy.h" + +namespace cc { + +bool FakeProxy::compositeAndReadback(void *pixels, const gfx::Rect&) +{ + return false; +} + +bool FakeProxy::isStarted() const +{ + return false; +} + +bool FakeProxy::initializeContext() +{ + return false; +} + +bool FakeProxy::initializeRenderer() +{ + return false; +} + +bool FakeProxy::recreateContext() +{ + return false; +} + +const RendererCapabilities& FakeProxy::rendererCapabilities() const +{ + return m_capabilities; +} + +bool FakeProxy::commitRequested() const +{ + return false; +} + +size_t FakeProxy::maxPartialTextureUpdates() const +{ + return 0; +} + + +} // namespace cc diff --git a/cc/test/fake_proxy.h b/cc/test/fake_proxy.h new file mode 100644 index 0000000..e432d00 --- /dev/null +++ b/cc/test/fake_proxy.h @@ -0,0 +1,50 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FakeCCProxy_h +#define FakeCCProxy_h + +#include "config.h" + +#include "cc/layer_tree_host.h" +#include "cc/proxy.h" +#include "cc/thread.h" + +namespace cc { + +class FakeProxy : public Proxy { +public: + explicit FakeProxy(scoped_ptr<Thread> implThread) : Proxy(implThread.Pass()) { } + + virtual bool compositeAndReadback(void *pixels, const gfx::Rect&) OVERRIDE; + virtual void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, base::TimeDelta duration) OVERRIDE { } + virtual void finishAllRendering() OVERRIDE { } + virtual bool isStarted() const OVERRIDE; + virtual bool initializeContext() OVERRIDE; + virtual void setSurfaceReady() OVERRIDE { } + virtual void setVisible(bool) OVERRIDE { } + virtual bool initializeRenderer() OVERRIDE; + virtual bool recreateContext() OVERRIDE; + virtual void renderingStats(RenderingStats*) OVERRIDE { } + virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE; + virtual void setNeedsAnimate() OVERRIDE { } + virtual void setNeedsCommit() OVERRIDE { } + virtual void setNeedsRedraw() OVERRIDE { } + virtual void setDeferCommits(bool) OVERRIDE { } + virtual void didAddAnimation() OVERRIDE { } + virtual bool commitRequested() const OVERRIDE; + virtual void start() OVERRIDE { } + virtual void stop() OVERRIDE { } + virtual void forceSerializeOnSwapBuffers() OVERRIDE { } + virtual size_t maxPartialTextureUpdates() const OVERRIDE; + virtual void acquireLayerTextures() OVERRIDE { } + virtual void loseContext() OVERRIDE { } + +private: + RendererCapabilities m_capabilities; +}; + +} + +#endif diff --git a/cc/test/layer_tree_test_common.cc b/cc/test/layer_tree_test_common.cc index da3f430..608d516 100644 --- a/cc/test/layer_tree_test_common.cc +++ b/cc/test/layer_tree_test_common.cc @@ -89,9 +89,9 @@ scoped_ptr<WebCompositorOutputSurface> TestHooks::createOutputSurface() return FakeWebCompositorOutputSurface::create(CompositorFakeWebGraphicsContext3DWithTextureTracking::create(WebGraphicsContext3D::Attributes()).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<WebKit::WebCompositorOutputSurface>(); } -scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client) +scoped_ptr<MockLayerTreeHostImpl> MockLayerTreeHostImpl::create(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) { - return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client)); + return make_scoped_ptr(new MockLayerTreeHostImpl(testHooks, settings, client, proxy)); } void MockLayerTreeHostImpl::beginCommit() @@ -132,8 +132,8 @@ base::TimeDelta MockLayerTreeHostImpl::lowFrequencyAnimationInterval() const return base::TimeDelta::FromMilliseconds(16); } -MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client) - : LayerTreeHostImpl(settings, client) +MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTreeSettings& settings, LayerTreeHostImplClient* client, Proxy* proxy) + : LayerTreeHostImpl(settings, client, proxy) , m_testHooks(testHooks) { } @@ -141,10 +141,10 @@ MockLayerTreeHostImpl::MockLayerTreeHostImpl(TestHooks* testHooks, const LayerTr // Adapts LayerTreeHost for test. Injects MockLayerTreeHostImpl. class MockLayerTreeHost : public cc::LayerTreeHost { public: - static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerTreeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSettings& settings) + static scoped_ptr<MockLayerTreeHost> create(TestHooks* testHooks, cc::LayerTreeHostClient* client, scoped_refptr<cc::Layer> rootLayer, const cc::LayerTreeSettings& settings, scoped_ptr<cc::Thread> implThread) { scoped_ptr<MockLayerTreeHost> layerTreeHost(new MockLayerTreeHost(testHooks, client, settings)); - bool success = layerTreeHost->initialize(); + bool success = layerTreeHost->initialize(implThread.Pass()); EXPECT_TRUE(success); layerTreeHost->setRootLayer(rootLayer); @@ -158,7 +158,7 @@ public: virtual scoped_ptr<cc::LayerTreeHostImpl> createLayerTreeHostImpl(cc::LayerTreeHostImplClient* client) { - return MockLayerTreeHostImpl::create(m_testHooks, settings(), client).PassAs<cc::LayerTreeHostImpl>(); + return MockLayerTreeHostImpl::create(m_testHooks, settings(), client, proxy()).PassAs<cc::LayerTreeHostImpl>(); } virtual void didAddAnimation() OVERRIDE @@ -275,6 +275,7 @@ ThreadedTest::ThreadedTest() , m_finished(false) , m_scheduled(false) , m_started(false) + , m_implThread(0) { } @@ -346,11 +347,13 @@ void ThreadedTest::postDidAddAnimationToMainThread() void ThreadedTest::doBeginTest() { - DCHECK(Proxy::isMainThread()); m_client = ThreadedMockLayerTreeHostClient::create(this); scoped_refptr<Layer> rootLayer = Layer::create(); - m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings); + scoped_ptr<cc::Thread> implCCThread(NULL); + if (m_implThread) + implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->message_loop_proxy()); + m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings, implCCThread.Pass()); ASSERT_TRUE(m_layerTreeHost.get()); rootLayer->setLayerTreeHost(m_layerTreeHost.get()); m_layerTreeHost->setSurfaceReady(); @@ -384,13 +387,12 @@ void ThreadedTest::scheduleComposite() void ThreadedTest::realEndTest() { - DCHECK(Proxy::isMainThread()); MessageLoop::current()->Quit(); } void ThreadedTest::dispatchSetNeedsAnimate() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -401,7 +403,7 @@ void ThreadedTest::dispatchSetNeedsAnimate() void ThreadedTest::dispatchAddInstantAnimation() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -412,7 +414,7 @@ void ThreadedTest::dispatchAddInstantAnimation() void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -423,7 +425,7 @@ void ThreadedTest::dispatchAddAnimation(Layer* layerToReceiveAnimation) void ThreadedTest::dispatchSetNeedsAnimateAndCommit() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -436,7 +438,7 @@ void ThreadedTest::dispatchSetNeedsAnimateAndCommit() void ThreadedTest::dispatchSetNeedsCommit() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -447,7 +449,7 @@ void ThreadedTest::dispatchSetNeedsCommit() void ThreadedTest::dispatchAcquireLayerTextures() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -458,7 +460,7 @@ void ThreadedTest::dispatchAcquireLayerTextures() void ThreadedTest::dispatchSetNeedsRedraw() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -469,7 +471,7 @@ void ThreadedTest::dispatchSetNeedsRedraw() void ThreadedTest::dispatchSetVisible(bool visible) { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -487,7 +489,7 @@ void ThreadedTest::dispatchComposite() void ThreadedTest::dispatchDidAddAnimation() { - DCHECK(Proxy::isMainThread()); + DCHECK(!proxy() || proxy()->isMainThread()); if (m_finished) return; @@ -505,25 +507,21 @@ void ThreadedTest::runTest(bool threaded) if (threaded) { m_implThread.reset(new base::Thread("ThreadedTest")); ASSERT_TRUE(m_implThread->Start()); - m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->message_loop_proxy()); - cc::Proxy::setImplThread(m_implCCThread.get()); } - DCHECK(Proxy::isMainThread()); - m_mainThreadProxy = ScopedThreadProxy::create(Proxy::mainThread()); + m_mainCCThread = cc::ThreadImpl::createForCurrentThread(); + m_mainThreadProxy = ScopedThreadProxy::create(m_mainCCThread.get()); initializeSettings(m_settings); - cc::Proxy::mainThread()->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unretained(this))); + m_mainCCThread->postTask(base::Bind(&ThreadedTest::doBeginTest, base::Unretained(this))); m_timeout.Reset(base::Bind(&ThreadedTest::timeout, base::Unretained(this))); - cc::Proxy::mainThread()->postDelayedTask(m_timeout.callback(), 5000); + m_mainCCThread->postDelayedTask(m_timeout.callback(), 5000); MessageLoop::current()->Run(); if (m_layerTreeHost.get() && m_layerTreeHost->rootLayer()) m_layerTreeHost->rootLayer()->setLayerTreeHost(0); m_layerTreeHost.reset(); - cc::Proxy::setImplThread(0); - m_timeout.Cancel(); ASSERT_FALSE(m_layerTreeHost.get()); diff --git a/cc/test/layer_tree_test_common.h b/cc/test/layer_tree_test_common.h index 962764a..b0f277b 100644 --- a/cc/test/layer_tree_test_common.h +++ b/cc/test/layer_tree_test_common.h @@ -114,7 +114,8 @@ protected: virtual void runTest(bool threaded); - cc::Thread* implThread() { return m_implCCThread.get(); } + cc::Thread* implThread() { return proxy() ? proxy()->implThread() : 0; } + cc::Proxy* proxy() const { return m_layerTreeHost ? m_layerTreeHost->proxy() : 0; } cc::LayerTreeSettings m_settings; scoped_ptr<MockLayerImplTreeHostClient> m_client; @@ -132,7 +133,6 @@ private: bool m_started; scoped_ptr<cc::Thread> m_mainCCThread; - scoped_ptr<cc::Thread> m_implCCThread; scoped_ptr<base::Thread> m_implThread; base::CancelableClosure m_timeout; }; @@ -148,7 +148,7 @@ public: // Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. class MockLayerTreeHostImpl : public cc::LayerTreeHostImpl { public: - static scoped_ptr<MockLayerTreeHostImpl> create(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*); + static scoped_ptr<MockLayerTreeHostImpl> create(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*, cc::Proxy*); virtual void beginCommit() OVERRIDE; virtual void commitComplete() OVERRIDE; @@ -164,7 +164,7 @@ protected: virtual base::TimeDelta lowFrequencyAnimationInterval() const OVERRIDE; private: - MockLayerTreeHostImpl(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*); + MockLayerTreeHostImpl(TestHooks*, const cc::LayerTreeSettings&, cc::LayerTreeHostImplClient*, cc::Proxy*); TestHooks* m_testHooks; }; diff --git a/cc/test/run_all_unittests.cc b/cc/test/run_all_unittests.cc index d0fddbc..4ea8697 100644 --- a/cc/test/run_all_unittests.cc +++ b/cc/test/run_all_unittests.cc @@ -4,18 +4,13 @@ #include "base/message_loop.h" #include "base/test/test_suite.h" -#include "cc/thread_impl.h" -#include "cc/proxy.h" #include "testing/gmock/include/gmock/gmock.h" int main(int argc, char** argv) { ::testing::InitGoogleMock(&argc, argv); TestSuite test_suite(argc, argv); MessageLoop message_loop; - scoped_ptr<cc::Thread> mainCCThread = cc::ThreadImpl::createForCurrentThread(); - cc::Proxy::setMainThread(mainCCThread.get()); int result = test_suite.Run(); return result; } - diff --git a/cc/texture_layer_unittest.cc b/cc/texture_layer_unittest.cc index 67ba102..e55a683 100644 --- a/cc/texture_layer_unittest.cc +++ b/cc/texture_layer_unittest.cc @@ -10,6 +10,7 @@ #include "cc/single_thread_proxy.h" #include "cc/texture_layer_impl.h" #include "cc/test/fake_layer_tree_host_client.h" +#include "cc/thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -26,7 +27,7 @@ public: MockLayerImplTreeHost() : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) { - initialize(); + initialize(scoped_ptr<Thread>(NULL)); } MOCK_METHOD0(acquireLayerTextures, void()); @@ -97,10 +98,7 @@ TEST_F(TextureLayerTest, syncImplWhenDrawing) scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); ASSERT_TRUE(testLayer); scoped_ptr<TextureLayerImpl> implLayer; - { - DebugScopedSetImplThread setImplThread; - implLayer = TextureLayerImpl::create(1); - } + implLayer = TextureLayerImpl::create(1); ASSERT_TRUE(implLayer); EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); @@ -144,11 +142,6 @@ TEST_F(TextureLayerTest, syncImplWhenDrawing) testLayer->willModifyTexture(); testLayer->setNeedsDisplayRect(dirtyRect); Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); - - { - DebugScopedSetImplThread setImplThread; - delete implLayer.release(); - } } TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree) diff --git a/cc/thread_proxy.cc b/cc/thread_proxy.cc index ac58216..4ea4220 100644 --- a/cc/thread_proxy.cc +++ b/cc/thread_proxy.cc @@ -16,6 +16,7 @@ #include "cc/layer_tree_host.h" #include "cc/scheduler.h" #include "cc/scoped_thread_proxy.h" +#include "cc/thread.h" #include <public/WebSharedGraphicsContext3D.h> using WebKit::WebSharedGraphicsContext3D; @@ -29,13 +30,14 @@ const double contextRecreationTickRate = 0.03; namespace cc { -scoped_ptr<Proxy> ThreadProxy::create(LayerTreeHost* layerTreeHost) +scoped_ptr<Proxy> ThreadProxy::create(LayerTreeHost* layerTreeHost, scoped_ptr<Thread> implThread) { - return make_scoped_ptr(new ThreadProxy(layerTreeHost)).PassAs<Proxy>(); + return make_scoped_ptr(new ThreadProxy(layerTreeHost, implThread.Pass())).PassAs<Proxy>(); } -ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost) - : m_animateRequested(false) +ThreadProxy::ThreadProxy(LayerTreeHost* layerTreeHost, scoped_ptr<Thread> implThread) + : Proxy(implThread.Pass()) + , m_animateRequested(false) , m_commitRequested(false) , m_commitRequestSentToImplThread(false) , m_forcedCommitRequested(false) @@ -81,7 +83,7 @@ bool ThreadProxy::compositeAndReadback(void *pixels, const gfx::Rect& rect) // Perform a synchronous commit. { - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent beginFrameCompletion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::forceBeginFrameOnImplThread, base::Unretained(this), &beginFrameCompletion)); beginFrameCompletion.wait(); @@ -95,7 +97,7 @@ bool ThreadProxy::compositeAndReadback(void *pixels, const gfx::Rect& rect) request.rect = rect; request.pixels = pixels; { - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); Proxy::implThread()->postTask(base::Bind(&ThreadProxy::requestReadbackOnImplThread, base::Unretained(this), &request)); request.completion.wait(); } @@ -136,7 +138,7 @@ void ThreadProxy::finishAllRendering() DCHECK(!m_deferCommits); // Make sure all GL drawing is finished on the impl thread. - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::finishAllRenderingOnImplThread, base::Unretained(this), &completion)); completion.wait(); @@ -174,7 +176,7 @@ void ThreadProxy::setSurfaceReadyOnImplThread() void ThreadProxy::setVisible(bool visible) { TRACE_EVENT0("cc", "ThreadProxy::setVisible"); - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::setVisibleOnImplThread, base::Unretained(this), &completion, visible)); completion.wait(); @@ -196,7 +198,7 @@ bool ThreadProxy::initializeRenderer() CompletionEvent completion; bool initializeSucceeded = false; RendererCapabilities capabilities; - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); Proxy::implThread()->postTask(base::Bind(&ThreadProxy::initializeRendererOnImplThread, base::Unretained(this), &completion, @@ -230,7 +232,7 @@ bool ThreadProxy::recreateContext() CompletionEvent completion; bool recreateSucceeded = false; RendererCapabilities capabilities; - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); Proxy::implThread()->postTask(base::Bind(&ThreadProxy::recreateContextOnImplThread, base::Unretained(this), &completion, @@ -248,7 +250,7 @@ void ThreadProxy::renderingStats(RenderingStats* stats) { DCHECK(isMainThread()); - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::renderingStatsOnImplThread, base::Unretained(this), &completion, stats)); @@ -428,7 +430,7 @@ void ThreadProxy::start() DCHECK(isMainThread()); DCHECK(Proxy::implThread()); // Create LayerTreeHostImpl. - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; scoped_ptr<InputHandler> handler = m_layerTreeHost->createInputHandler(); Proxy::implThread()->postTask(base::Bind(&ThreadProxy::initializeImplOnImplThread, base::Unretained(this), &completion, handler.release())); @@ -445,7 +447,7 @@ void ThreadProxy::stop() // Synchronously deletes the impl. { - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::layerTreeHostClosedOnImplThread, base::Unretained(this), &completion)); @@ -461,7 +463,7 @@ void ThreadProxy::stop() void ThreadProxy::forceSerializeOnSwapBuffers() { - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::forceSerializeOnSwapBuffersOnImplThread, base::Unretained(this), &completion)); completion.wait(); @@ -614,7 +616,7 @@ void ThreadProxy::beginFrame() { TRACE_EVENT0("cc", "commit"); - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); base::TimeTicks startTime = base::TimeTicks::HighResNow(); CompletionEvent completion; @@ -657,7 +659,7 @@ void ThreadProxy::beginFrameCompleteOnImplThread(CompletionEvent* completion, Re m_layerTreeHost->contentsTextureManager()->pushTexturePrioritiesToBackings(); - m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::create(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvider()); + m_currentResourceUpdateControllerOnImplThread = ResourceUpdateController::create(this, Proxy::implThread(), queue.Pass(), m_layerTreeHostImpl->resourceProvider(), hasImplThread()); ResourceProvider::debugNotifyEnterZone(0x2000000); m_currentResourceUpdateControllerOnImplThread->performMoreUpdates( m_schedulerOnImplThread->anticipatedDrawTime()); @@ -795,7 +797,7 @@ void ThreadProxy::acquireLayerTextures() return; TRACE_EVENT0("cc", "ThreadProxy::acquireLayerTextures"); - DebugScopedSetMainThreadBlocked mainThreadBlocked; + DebugScopedSetMainThreadBlocked mainThreadBlocked(this); CompletionEvent completion; Proxy::implThread()->postTask(base::Bind(&ThreadProxy::acquireLayerTexturesForMainThreadOnImplThread, base::Unretained(this), &completion)); completion.wait(); // Block until it is safe to write to layer textures from the main thread. diff --git a/cc/thread_proxy.h b/cc/thread_proxy.h index 1249687..5ccedc1 100644 --- a/cc/thread_proxy.h +++ b/cc/thread_proxy.h @@ -5,6 +5,7 @@ #ifndef CCThreadProxy_h #define CCThreadProxy_h +#include "base/memory/scoped_ptr.h" #include "base/time.h" #include "cc/animation_events.h" #include "cc/completion_event.h" @@ -24,7 +25,7 @@ class Thread; class ThreadProxy : public Proxy, LayerTreeHostImplClient, SchedulerClient, ResourceUpdateControllerClient { public: - static scoped_ptr<Proxy> create(LayerTreeHost*); + static scoped_ptr<Proxy> create(LayerTreeHost*, scoped_ptr<Thread> implThread); virtual ~ThreadProxy(); @@ -77,7 +78,7 @@ public: virtual void readyToFinalizeTextureUpdates() OVERRIDE; private: - explicit ThreadProxy(LayerTreeHost*); + ThreadProxy(LayerTreeHost*, scoped_ptr<Thread> implThread); // Set on impl thread, read on main thread. struct BeginFrameAndCommitState { diff --git a/cc/tiled_layer_impl_unittest.cc b/cc/tiled_layer_impl_unittest.cc index 35c4962..0db0aca 100644 --- a/cc/tiled_layer_impl_unittest.cc +++ b/cc/tiled_layer_impl_unittest.cc @@ -46,8 +46,6 @@ static scoped_ptr<TiledLayerImpl> createLayer(const gfx::Size& tileSize, const g TEST(TiledLayerImplTest, emptyQuadList) { - DebugScopedSetImplThread scopedImplThread; - const gfx::Size tileSize(90, 90); const int numTilesX = 8; const int numTilesY = 4; @@ -101,8 +99,6 @@ TEST(TiledLayerImplTest, emptyQuadList) TEST(TiledLayerImplTest, checkerboarding) { - DebugScopedSetImplThread scopedImplThread; - const gfx::Size tileSize(10, 10); const int numTilesX = 2; const int numTilesY = 2; @@ -162,8 +158,6 @@ static void getQuads(QuadList& quads, SharedQuadStateList& sharedStates, gfx::Si static void coverageVisibleRectOnTileBoundaries(LayerTilingData::BorderTexelOption borders) { - DebugScopedSetImplThread scopedImplThread; - gfx::Size layerSize(1000, 1000); QuadList quads; SharedQuadStateList sharedStates; @@ -174,8 +168,6 @@ WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectOnTileBoundaries); static void coverageVisibleRectIntersectsTiles(LayerTilingData::BorderTexelOption borders) { - DebugScopedSetImplThread scopedImplThread; - // This rect intersects the middle 3x3 of the 5x5 tiles. gfx::Point topLeft(65, 73); gfx::Point bottomRight(182, 198); @@ -191,8 +183,6 @@ WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsTiles); static void coverageVisibleRectIntersectsBounds(LayerTilingData::BorderTexelOption borders) { - DebugScopedSetImplThread scopedImplThread; - gfx::Size layerSize(220, 210); gfx::Rect visibleContentRect(gfx::Point(), layerSize); QuadList quads; @@ -204,8 +194,6 @@ WITH_AND_WITHOUT_BORDER_TEST(coverageVisibleRectIntersectsBounds); TEST(TiledLayerImplTest, textureInfoForLayerNoBorders) { - DebugScopedSetImplThread scopedImplThread; - gfx::Size tileSize(50, 50); gfx::Size layerSize(250, 250); QuadList quads; @@ -225,8 +213,6 @@ TEST(TiledLayerImplTest, textureInfoForLayerNoBorders) TEST(TiledLayerImplTest, tileOpaqueRectForLayerNoBorders) { - DebugScopedSetImplThread scopedImplThread; - gfx::Size tileSize(50, 50); gfx::Size layerSize(250, 250); QuadList quads; diff --git a/cc/tiled_layer_unittest.cc b/cc/tiled_layer_unittest.cc index 681e423..2dd253d 100644 --- a/cc/tiled_layer_unittest.cc +++ b/cc/tiled_layer_unittest.cc @@ -15,6 +15,7 @@ #include "cc/test/animation_test_common.h" #include "cc/test/fake_graphics_context.h" #include "cc/test/fake_layer_tree_host_client.h" +#include "cc/test/fake_proxy.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/tiled_layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -49,34 +50,38 @@ private: class TiledLayerTest : public testing::Test { public: TiledLayerTest() - : m_context(WebKit::createFakeGraphicsContext()) + : m_proxy(NULL) + , m_context(WebKit::createFakeGraphicsContext()) , m_queue(make_scoped_ptr(new ResourceUpdateQueue)) - , m_textureManager(PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool)) , m_occlusion(0) { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + } + + virtual void SetUp() + { + m_layerTreeHost = LayerTreeHost::create(&m_fakeLayerImplTreeHostClient, m_settings, scoped_ptr<Thread>(NULL)); + m_proxy = m_layerTreeHost->proxy(); + m_textureManager = PrioritizedTextureManager::create(60*1024*1024, 1024, Renderer::ContentPool, m_proxy); + m_layerTreeHost->initializeRendererIfNeeded(); + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); m_resourceProvider = ResourceProvider::create(m_context.get()); } virtual ~TiledLayerTest() { textureManagerClearAllMemory(m_textureManager.get(), m_resourceProvider.get()); - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); m_resourceProvider.reset(); } - // Helper classes and functions that set the current thread to be the impl thread - // before doing the action that they wrap. class ScopedFakeTiledLayerImpl { public: ScopedFakeTiledLayerImpl(int id) { - DebugScopedSetImplThread implThread; m_layerImpl = new FakeTiledLayerImpl(id); } ~ScopedFakeTiledLayerImpl() { - DebugScopedSetImplThread implThread; delete m_layerImpl; } FakeTiledLayerImpl* get() @@ -92,31 +97,32 @@ public: }; void textureManagerClearAllMemory(PrioritizedTextureManager* textureManager, ResourceProvider* resourceProvider) { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); textureManager->clearAllMemory(resourceProvider); textureManager->reduceMemory(resourceProvider); } void updateTextures() { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); DCHECK(m_queue); scoped_ptr<ResourceUpdateController> updateController = ResourceUpdateController::create( NULL, - Proxy::implThread(), + m_proxy->implThread(), m_queue.Pass(), - m_resourceProvider.get()); + m_resourceProvider.get(), + m_proxy->hasImplThread()); updateController->finalize(); m_queue = make_scoped_ptr(new ResourceUpdateQueue); } void layerPushPropertiesTo(FakeTiledLayer* layer, FakeTiledLayerImpl* layerImpl) { - DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked; + DebugScopedSetImplThreadAndMainThreadBlocked implThreadAndMainThreadBlocked(m_proxy); layer->pushPropertiesTo(layerImpl); } void layerUpdate(FakeTiledLayer* layer, TestOcclusionTracker* occluded) { - DebugScopedSetMainThread mainThread; + DebugScopedSetMainThread mainThread(m_proxy); layer->update(*m_queue.get(), occluded, m_stats); } @@ -156,11 +162,15 @@ public: } public: + Proxy* m_proxy; + LayerTreeSettings m_settings; scoped_ptr<GraphicsContext> m_context; scoped_ptr<ResourceProvider> m_resourceProvider; scoped_ptr<ResourceUpdateQueue> m_queue; RenderingStats m_stats; PriorityCalculator m_priorityCalculator; + FakeLayerImplTreeHostClient m_fakeLayerImplTreeHostClient; + scoped_ptr<LayerTreeHost> m_layerTreeHost; scoped_ptr<PrioritizedTextureManager> m_textureManager; TestOcclusionTracker* m_occlusion; }; @@ -512,7 +522,7 @@ TEST_F(TiledLayerTest, paintSmallAnimatedLayersImmediately) // Create a LayerTreeHost that has the right viewportsize, // so the layer is considered small enough. FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; - scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, LayerTreeSettings()); + scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, LayerTreeSettings(), scoped_ptr<Thread>(NULL)); bool runOutOfMemory[2] = {false, true}; for (int i = 0; i < 2; i++) { @@ -778,10 +788,6 @@ TEST_F(TiledLayerTest, verifyInvalidationWhenContentsScaleChanges) TEST_F(TiledLayerTest, skipsDrawGetsReset) { - FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; - scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, LayerTreeSettings()); - ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); - // Create two 300 x 300 tiled layers. gfx::Size contentBounds(300, 300); gfx::Rect contentRect(gfx::Point(), contentBounds); @@ -789,8 +795,8 @@ TEST_F(TiledLayerTest, skipsDrawGetsReset) // We have enough memory for only one of the two layers. int memoryLimit = 4 * 300 * 300; // 4 bytes per pixel. - scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager())); - scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager())); + scoped_refptr<FakeTiledLayer> rootLayer = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager())); + scoped_refptr<FakeTiledLayer> childLayer = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager())); rootLayer->addChild(childLayer); rootLayer->setBounds(contentBounds); @@ -802,25 +808,25 @@ TEST_F(TiledLayerTest, skipsDrawGetsReset) rootLayer->invalidateContentRect(contentRect); childLayer->invalidateContentRect(contentRect); - layerTreeHost->setRootLayer(rootLayer); - layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(300, 300)); + m_layerTreeHost->setRootLayer(rootLayer); + m_layerTreeHost->setViewportSize(gfx::Size(300, 300), gfx::Size(300, 300)); - layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); + m_layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); // We'll skip the root layer. EXPECT_TRUE(rootLayer->skipsDraw()); EXPECT_FALSE(childLayer->skipsDraw()); - layerTreeHost->commitComplete(); + m_layerTreeHost->commitComplete(); // Remove the child layer. rootLayer->removeAllChildren(); - layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); + m_layerTreeHost->updateLayers(*m_queue.get(), memoryLimit); EXPECT_FALSE(rootLayer->skipsDraw()); - textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get()); - layerTreeHost->setRootLayer(0); + textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get()); + m_layerTreeHost->setRootLayer(0); } TEST_F(TiledLayerTest, resizeToSmaller) @@ -854,115 +860,6 @@ TEST_F(TiledLayerTest, hugeLayerUpdateCrash) layer->update(*m_queue.get(), 0, m_stats); } -TEST_F(TiledLayerTest, partialUpdates) -{ - LayerTreeSettings settings; - settings.maxPartialTextureUpdates = 4; - - FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; - scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, settings); - ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); - - // Create one 300 x 200 tiled layer with 3 x 2 tiles. - gfx::Size contentBounds(300, 200); - gfx::Rect contentRect(gfx::Point(), contentBounds); - - scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager())); - layer->setBounds(contentBounds); - layer->setPosition(gfx::PointF(0, 0)); - layer->setVisibleContentRect(contentRect); - layer->invalidateContentRect(contentRect); - - layerTreeHost->setRootLayer(layer); - layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(300, 200)); - - // Full update of all 6 tiles. - layerTreeHost->updateLayers( - *m_queue.get(), std::numeric_limits<size_t>::max()); - { - ScopedFakeTiledLayerImpl layerImpl(1); - EXPECT_EQ(6, m_queue->fullUploadSize()); - EXPECT_EQ(0, m_queue->partialUploadSize()); - updateTextures(); - EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); - EXPECT_FALSE(m_queue->hasMoreUpdates()); - layer->fakeLayerUpdater()->clearUpdateCount(); - layerPushPropertiesTo(layer.get(), layerImpl.get()); - } - layerTreeHost->commitComplete(); - - // Full update of 3 tiles and partial update of 3 tiles. - layer->invalidateContentRect(gfx::Rect(0, 0, 300, 150)); - layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); - { - ScopedFakeTiledLayerImpl layerImpl(1); - EXPECT_EQ(3, m_queue->fullUploadSize()); - EXPECT_EQ(3, m_queue->partialUploadSize()); - updateTextures(); - EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); - EXPECT_FALSE(m_queue->hasMoreUpdates()); - layer->fakeLayerUpdater()->clearUpdateCount(); - layerPushPropertiesTo(layer.get(), layerImpl.get()); - } - layerTreeHost->commitComplete(); - - // Partial update of 6 tiles. - layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); - { - ScopedFakeTiledLayerImpl layerImpl(1); - layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); - EXPECT_EQ(2, m_queue->fullUploadSize()); - EXPECT_EQ(4, m_queue->partialUploadSize()); - updateTextures(); - EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); - EXPECT_FALSE(m_queue->hasMoreUpdates()); - layer->fakeLayerUpdater()->clearUpdateCount(); - layerPushPropertiesTo(layer.get(), layerImpl.get()); - } - layerTreeHost->commitComplete(); - - // Checkerboard all tiles. - layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200)); - { - ScopedFakeTiledLayerImpl layerImpl(1); - layerPushPropertiesTo(layer.get(), layerImpl.get()); - } - layerTreeHost->commitComplete(); - - // Partial update of 6 checkerboard tiles. - layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); - { - ScopedFakeTiledLayerImpl layerImpl(1); - layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); - EXPECT_EQ(6, m_queue->fullUploadSize()); - EXPECT_EQ(0, m_queue->partialUploadSize()); - updateTextures(); - EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); - EXPECT_FALSE(m_queue->hasMoreUpdates()); - layer->fakeLayerUpdater()->clearUpdateCount(); - layerPushPropertiesTo(layer.get(), layerImpl.get()); - } - layerTreeHost->commitComplete(); - - // Partial update of 4 tiles. - layer->invalidateContentRect(gfx::Rect(50, 50, 100, 100)); - { - ScopedFakeTiledLayerImpl layerImpl(1); - layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); - EXPECT_EQ(0, m_queue->fullUploadSize()); - EXPECT_EQ(4, m_queue->partialUploadSize()); - updateTextures(); - EXPECT_EQ(4, layer->fakeLayerUpdater()->updateCount()); - EXPECT_FALSE(m_queue->hasMoreUpdates()); - layer->fakeLayerUpdater()->clearUpdateCount(); - layerPushPropertiesTo(layer.get(), layerImpl.get()); - } - layerTreeHost->commitComplete(); - - textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get()); - layerTreeHost->setRootLayer(0); -} - TEST_F(TiledLayerTest, tilesPaintedWithoutOcclusion) { scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_textureManager.get())); @@ -1381,15 +1278,10 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) gfx::Rect childRect(0, 0, 300, 100); gfx::Rect child2Rect(0, 100, 300, 100); - LayerTreeSettings settings; - FakeLayerImplTreeHostClient fakeLayerImplTreeHostClient; - scoped_ptr<LayerTreeHost> layerTreeHost = LayerTreeHost::create(&fakeLayerImplTreeHostClient, settings); - ASSERT_TRUE(layerTreeHost->initializeRendererIfNeeded()); - - scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager())); + scoped_refptr<FakeTiledLayer> root = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager())); scoped_refptr<Layer> surface = Layer::create(); - scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager())); - scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer(layerTreeHost->contentsTextureManager())); + scoped_refptr<FakeTiledLayer> child = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager())); + scoped_refptr<FakeTiledLayer> child2 = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager())); root->setBounds(rootRect.size()); root->setAnchorPoint(gfx::PointF()); @@ -1415,14 +1307,14 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) child2->setVisibleContentRect(child2Rect); child2->setDrawableContentRect(rootRect); - layerTreeHost->setRootLayer(root); - layerTreeHost->setViewportSize(rootRect.size(), rootRect.size()); + m_layerTreeHost->setRootLayer(root); + m_layerTreeHost->setViewportSize(rootRect.size(), rootRect.size()); // With a huge memory limit, all layers should update and push their textures. root->invalidateContentRect(rootRect); child->invalidateContentRect(childRect); child2->invalidateContentRect(child2Rect); - layerTreeHost->updateLayers( + m_layerTreeHost->updateLayers( *m_queue.get(), std::numeric_limits<size_t>::max()); { updateTextures(); @@ -1449,7 +1341,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) EXPECT_TRUE(child2Impl->hasResourceIdForTileAt(i, 0)); } } - layerTreeHost->commitComplete(); + m_layerTreeHost->commitComplete(); // With a memory limit that includes only the root layer (3x2 tiles) and half the surface that // the child layers draw into, the child layers will not be allocated. If the surface isn't @@ -1457,7 +1349,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) root->invalidateContentRect(rootRect); child->invalidateContentRect(childRect); child2->invalidateContentRect(child2Rect); - layerTreeHost->updateLayers( + m_layerTreeHost->updateLayers( *m_queue.get(), (3 * 2 + 3 * 1) * (100 * 100) * 4); { updateTextures(); @@ -1484,7 +1376,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0)); } } - layerTreeHost->commitComplete(); + m_layerTreeHost->commitComplete(); // With a memory limit that includes only half the root layer, no contents will be // allocated. If render surface memory wasn't accounted for, there is enough space @@ -1493,7 +1385,7 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) root->invalidateContentRect(rootRect); child->invalidateContentRect(childRect); child2->invalidateContentRect(child2Rect); - layerTreeHost->updateLayers( + m_layerTreeHost->updateLayers( *m_queue.get(), (3 * 1) * (100 * 100) * 4); { updateTextures(); @@ -1520,10 +1412,10 @@ TEST_F(TiledLayerTest, dontAllocateContentsWhenTargetSurfaceCantBeAllocated) EXPECT_FALSE(child2Impl->hasResourceIdForTileAt(i, 0)); } } - layerTreeHost->commitComplete(); + m_layerTreeHost->commitComplete(); - textureManagerClearAllMemory(layerTreeHost->contentsTextureManager(), m_resourceProvider.get()); - layerTreeHost->setRootLayer(0); + textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get()); + m_layerTreeHost->setRootLayer(0); } class TrackingLayerPainter : public LayerPainter { @@ -1627,4 +1519,114 @@ TEST_F(TiledLayerTest, nonIntegerContentsScaleIsNotDistortedDuringInvalidation) EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); } +class TiledLayerPartialUpdateTest : public TiledLayerTest { +public: + TiledLayerPartialUpdateTest() + { + m_settings.maxPartialTextureUpdates = 4; + } +}; + +TEST_F(TiledLayerPartialUpdateTest, partialUpdates) +{ + // Create one 300 x 200 tiled layer with 3 x 2 tiles. + gfx::Size contentBounds(300, 200); + gfx::Rect contentRect(gfx::Point(), contentBounds); + + scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(m_layerTreeHost->contentsTextureManager())); + layer->setBounds(contentBounds); + layer->setPosition(gfx::PointF(0, 0)); + layer->setVisibleContentRect(contentRect); + layer->invalidateContentRect(contentRect); + + m_layerTreeHost->setRootLayer(layer); + m_layerTreeHost->setViewportSize(gfx::Size(300, 200), gfx::Size(300, 200)); + + // Full update of all 6 tiles. + m_layerTreeHost->updateLayers( + *m_queue.get(), std::numeric_limits<size_t>::max()); + { + ScopedFakeTiledLayerImpl layerImpl(1); + EXPECT_EQ(6, m_queue->fullUploadSize()); + EXPECT_EQ(0, m_queue->partialUploadSize()); + updateTextures(); + EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); + EXPECT_FALSE(m_queue->hasMoreUpdates()); + layer->fakeLayerUpdater()->clearUpdateCount(); + layerPushPropertiesTo(layer.get(), layerImpl.get()); + } + m_layerTreeHost->commitComplete(); + + // Full update of 3 tiles and partial update of 3 tiles. + layer->invalidateContentRect(gfx::Rect(0, 0, 300, 150)); + m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); + { + ScopedFakeTiledLayerImpl layerImpl(1); + EXPECT_EQ(3, m_queue->fullUploadSize()); + EXPECT_EQ(3, m_queue->partialUploadSize()); + updateTextures(); + EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); + EXPECT_FALSE(m_queue->hasMoreUpdates()); + layer->fakeLayerUpdater()->clearUpdateCount(); + layerPushPropertiesTo(layer.get(), layerImpl.get()); + } + m_layerTreeHost->commitComplete(); + + // Partial update of 6 tiles. + layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); + { + ScopedFakeTiledLayerImpl layerImpl(1); + m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); + EXPECT_EQ(2, m_queue->fullUploadSize()); + EXPECT_EQ(4, m_queue->partialUploadSize()); + updateTextures(); + EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); + EXPECT_FALSE(m_queue->hasMoreUpdates()); + layer->fakeLayerUpdater()->clearUpdateCount(); + layerPushPropertiesTo(layer.get(), layerImpl.get()); + } + m_layerTreeHost->commitComplete(); + + // Checkerboard all tiles. + layer->invalidateContentRect(gfx::Rect(0, 0, 300, 200)); + { + ScopedFakeTiledLayerImpl layerImpl(1); + layerPushPropertiesTo(layer.get(), layerImpl.get()); + } + m_layerTreeHost->commitComplete(); + + // Partial update of 6 checkerboard tiles. + layer->invalidateContentRect(gfx::Rect(50, 50, 200, 100)); + { + ScopedFakeTiledLayerImpl layerImpl(1); + m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); + EXPECT_EQ(6, m_queue->fullUploadSize()); + EXPECT_EQ(0, m_queue->partialUploadSize()); + updateTextures(); + EXPECT_EQ(6, layer->fakeLayerUpdater()->updateCount()); + EXPECT_FALSE(m_queue->hasMoreUpdates()); + layer->fakeLayerUpdater()->clearUpdateCount(); + layerPushPropertiesTo(layer.get(), layerImpl.get()); + } + m_layerTreeHost->commitComplete(); + + // Partial update of 4 tiles. + layer->invalidateContentRect(gfx::Rect(50, 50, 100, 100)); + { + ScopedFakeTiledLayerImpl layerImpl(1); + m_layerTreeHost->updateLayers(*m_queue.get(), std::numeric_limits<size_t>::max()); + EXPECT_EQ(0, m_queue->fullUploadSize()); + EXPECT_EQ(4, m_queue->partialUploadSize()); + updateTextures(); + EXPECT_EQ(4, layer->fakeLayerUpdater()->updateCount()); + EXPECT_FALSE(m_queue->hasMoreUpdates()); + layer->fakeLayerUpdater()->clearUpdateCount(); + layerPushPropertiesTo(layer.get(), layerImpl.get()); + } + m_layerTreeHost->commitComplete(); + + textureManagerClearAllMemory(m_layerTreeHost->contentsTextureManager(), m_resourceProvider.get()); + m_layerTreeHost->setRootLayer(0); +} + } // namespace diff --git a/cc/tree_synchronizer_unittest.cc b/cc/tree_synchronizer_unittest.cc index 88654df..a061dff 100644 --- a/cc/tree_synchronizer_unittest.cc +++ b/cc/tree_synchronizer_unittest.cc @@ -13,6 +13,7 @@ #include "cc/proxy.h" #include "cc/single_thread_proxy.h" #include "cc/test/animation_test_common.h" +#include "cc/test/fake_proxy.h" #include "testing/gtest/include/gtest/gtest.h" using namespace cc; @@ -131,8 +132,6 @@ void expectTreesAreIdentical(Layer* layer, LayerImpl* layerImpl, LayerTreeHostIm // return a null tree. TEST(TreeSynchronizerTest, syncNullTree) { - DebugScopedSetImplThread impl; - scoped_ptr<LayerImpl> layerImplTreeRoot = TreeSynchronizer::synchronizeTrees(0, scoped_ptr<LayerImpl>(), 0); EXPECT_TRUE(!layerImplTreeRoot.get()); @@ -141,10 +140,10 @@ TEST(TreeSynchronizerTest, syncNullTree) // Constructs a very simple tree and synchronizes it without trying to reuse any preexisting layers. TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty) { - DebugScopedSetImplThread impl; - LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); scoped_refptr<Layer> layerTreeRoot = Layer::create(); layerTreeRoot->addChild(Layer::create()); @@ -158,11 +157,12 @@ TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty) // Constructs a very simple tree and synchronizes it attempting to reuse some layers TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers) { - DebugScopedSetImplThread impl; std::vector<int> layerImplDestructionList; LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); scoped_refptr<Layer> layerTreeRoot = MockLayer::create(&layerImplDestructionList); layerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); @@ -188,11 +188,12 @@ TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers) // Constructs a very simple tree and checks that a stacking-order change is tracked properly. TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) { - DebugScopedSetImplThread impl; std::vector<int> layerImplDestructionList; LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); // Set up the tree and sync once. child2 needs to be synced here, too, even though we // remove it to set up the intended scenario. @@ -218,10 +219,10 @@ TEST(TreeSynchronizerTest, syncSimpleTreeAndTrackStackingOrderChange) TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties) { - DebugScopedSetImplThread impl; - LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); scoped_refptr<Layer> layerTreeRoot = Layer::create(); layerTreeRoot->addChild(Layer::create()); @@ -254,11 +255,12 @@ TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties) TEST(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange) { - DebugScopedSetImplThread impl; std::vector<int> layerImplDestructionList; LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); // Set up a tree with this sort of structure: // root --- A --- B ---+--- C @@ -304,11 +306,12 @@ TEST(TreeSynchronizerTest, reuseLayerImplsAfterStructuralChange) // Constructs a very simple tree, synchronizes it, then synchronizes to a totally new tree. All layers from the old tree should be deleted. TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy) { - DebugScopedSetImplThread impl; std::vector<int> layerImplDestructionList; LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); scoped_refptr<Layer> oldLayerTreeRoot = MockLayer::create(&layerImplDestructionList); oldLayerTreeRoot->addChild(MockLayer::create(&layerImplDestructionList)); @@ -339,10 +342,10 @@ TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy) // Constructs+syncs a tree with mask, replica, and replica mask layers. TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) { - DebugScopedSetImplThread impl; - LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); scoped_refptr<Layer> layerTreeRoot = Layer::create(); layerTreeRoot->addChild(Layer::create()); @@ -385,10 +388,10 @@ TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers) TEST(TreeSynchronizerTest, synchronizeAnimations) { - DebugScopedSetImplThread impl; - LayerTreeSettings settings; - scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0); + FakeProxy proxy(scoped_ptr<Thread>(NULL)); + DebugScopedSetImplThread impl(&proxy); + scoped_ptr<LayerTreeHostImpl> hostImpl = LayerTreeHostImpl::create(settings, 0, &proxy); scoped_refptr<Layer> layerTreeRoot = Layer::create(); diff --git a/cc/video_layer_impl.cc b/cc/video_layer_impl.cc index 45f6ed6..f958ccf 100644 --- a/cc/video_layer_impl.cc +++ b/cc/video_layer_impl.cc @@ -9,7 +9,6 @@ #include "base/logging.h" #include "cc/io_surface_draw_quad.h" #include "cc/layer_tree_host_impl.h" -#include "cc/proxy.h" #include "cc/quad_sink.h" #include "cc/resource_provider.h" #include "cc/stream_video_draw_quad.h" @@ -43,14 +42,12 @@ VideoLayerImpl::VideoLayerImpl(int id, WebKit::WebVideoFrameProvider* provider, // thread is blocked. That makes this a thread-safe call to set the video // frame provider client that does not require a lock. The same is true of // the call in the destructor. - DCHECK(Proxy::isMainThreadBlocked()); m_provider->setVideoFrameProviderClient(this); } VideoLayerImpl::~VideoLayerImpl() { // See comment in constructor for why this doesn't need a lock. - DCHECK(Proxy::isMainThreadBlocked()); if (m_provider) { m_provider->setVideoFrameProviderClient(0); m_provider = 0; @@ -119,7 +116,6 @@ size_t VideoLayerImpl::numPlanes() const void VideoLayerImpl::willDraw(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); LayerImpl::willDraw(resourceProvider); // Explicitly acquire and release the provider mutex so it can be held from @@ -140,7 +136,6 @@ void VideoLayerImpl::willDraw(ResourceProvider* resourceProvider) void VideoLayerImpl::willDrawInternal(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); DCHECK(!m_externalTextureResource); if (!m_provider) { @@ -191,8 +186,6 @@ void VideoLayerImpl::willDrawInternal(ResourceProvider* resourceProvider) void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData) { - DCHECK(Proxy::isImplThread()); - if (!m_frame) return; @@ -253,7 +246,6 @@ void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad void VideoLayerImpl::didDraw(ResourceProvider* resourceProvider) { - DCHECK(Proxy::isImplThread()); LayerImpl::didDraw(resourceProvider); if (!m_frame) diff --git a/webkit/compositor_bindings/compositor_bindings.gyp b/webkit/compositor_bindings/compositor_bindings.gyp index 309a984..a60e749 100644 --- a/webkit/compositor_bindings/compositor_bindings.gyp +++ b/webkit/compositor_bindings/compositor_bindings.gyp @@ -9,8 +9,6 @@ 'web_animation_curve_common.h', 'web_animation_impl.cc', 'web_animation_impl.h', - 'web_compositor_impl.cc', - 'web_compositor_impl.h', 'web_content_layer_impl.cc', 'web_content_layer_impl.h', 'web_delegated_renderer_layer_impl.cc', diff --git a/webkit/compositor_bindings/test/run_all_unittests.cc b/webkit/compositor_bindings/test/run_all_unittests.cc index 818c008..1478894 100644 --- a/webkit/compositor_bindings/test/run_all_unittests.cc +++ b/webkit/compositor_bindings/test/run_all_unittests.cc @@ -12,10 +12,7 @@ int main(int argc, char** argv) { ::testing::InitGoogleMock(&argc, argv); TestSuite testSuite(argc, argv); MessageLoop message_loop; - scoped_ptr<cc::Thread> mainCCThread = cc::ThreadImpl::createForCurrentThread(); - cc::Proxy::setMainThread(mainCCThread.get()); int result = testSuite.Run(); return result; } - diff --git a/webkit/compositor_bindings/web_compositor_impl.cc b/webkit/compositor_bindings/web_compositor_impl.cc deleted file mode 100644 index dcf5ec3..0000000 --- a/webkit/compositor_bindings/web_compositor_impl.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "config.h" - -#include "web_compositor_impl.h" - -#ifdef LOG -#undef LOG -#endif -#include "base/message_loop_proxy.h" -#include "cc/layer_tree_host.h" -#include "cc/proxy.h" -#include "cc/settings.h" -#include "cc/thread_impl.h" -#include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" -#include "webkit/glue/webthread_impl.h" - -using namespace cc; - -namespace WebKit { - -bool WebCompositorImpl::s_initialized = false; -Thread* WebCompositorImpl::s_mainThread = 0; -Thread* WebCompositorImpl::s_implThread = 0; - -void WebCompositor::initialize(WebThread* implThread) -{ - WebCompositorImpl::initialize(implThread); -} - -bool WebCompositor::isThreadingEnabled() -{ - return WebCompositorImpl::isThreadingEnabled(); -} - -void WebCompositor::shutdown() -{ - WebCompositorImpl::shutdown(); -} - -void WebCompositorImpl::initialize(WebThread* implThread) -{ - ASSERT(!s_initialized); - s_initialized = true; - - s_mainThread = cc::ThreadImpl::createForCurrentThread().release(); - Proxy::setMainThread(s_mainThread); - if (implThread) { - webkit_glue::WebThreadImpl* webThreadImpl = static_cast<webkit_glue::WebThreadImpl*>(implThread); - MessageLoop* implMessageLoop = webThreadImpl->message_loop(); - s_implThread = cc::ThreadImpl::createForDifferentThread(implMessageLoop->message_loop_proxy()).release(); - Proxy::setImplThread(s_implThread); - } else - Proxy::setImplThread(0); -} - -bool WebCompositorImpl::isThreadingEnabled() -{ - return s_implThread; -} - -bool WebCompositorImpl::initialized() -{ - return s_initialized; -} - -void WebCompositorImpl::shutdown() -{ - ASSERT(s_initialized); - ASSERT(!LayerTreeHost::anyLayerTreeHostInstanceExists()); - - if (s_implThread) { - delete s_implThread; - s_implThread = 0; - } - delete s_mainThread; - s_mainThread = 0; - Proxy::setImplThread(0); - Proxy::setMainThread(0); - s_initialized = false; -} - -} diff --git a/webkit/compositor_bindings/web_compositor_impl.h b/webkit/compositor_bindings/web_compositor_impl.h deleted file mode 100644 index fe63b27..0000000 --- a/webkit/compositor_bindings/web_compositor_impl.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WebCompositorImpl_h -#define WebCompositorImpl_h - -#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositor.h" - -namespace cc { -class Thread; -} - -namespace WebKit { - -class WebThread; - -class WebCompositorImpl : public WebCompositor { -public: - static bool initialized(); - - static void initialize(WebThread* implThread); - static bool isThreadingEnabled(); - static void shutdown(); - -private: - static bool s_initialized; - static cc::Thread* s_mainThread; - static cc::Thread* s_implThread; -}; - -} - -#endif // WebCompositorImpl_h diff --git a/webkit/compositor_bindings/web_compositor_support_impl.cc b/webkit/compositor_bindings/web_compositor_support_impl.cc index 32a1840..1a96975 100644 --- a/webkit/compositor_bindings/web_compositor_support_impl.cc +++ b/webkit/compositor_bindings/web_compositor_support_impl.cc @@ -5,10 +5,11 @@ #include "config.h" #include "webkit/compositor_bindings/web_compositor_support_impl.h" +#include "base/message_loop_proxy.h" #include "base/memory/scoped_ptr.h" #include "cc/settings.h" +#include "cc/thread_impl.h" #include "webkit/compositor_bindings/web_animation_impl.h" -#include "webkit/compositor_bindings/web_compositor_impl.h" #include "webkit/compositor_bindings/web_content_layer_impl.h" #include "webkit/compositor_bindings/web_delegated_renderer_layer_impl.h" #include "webkit/compositor_bindings/web_external_texture_layer_impl.h" @@ -21,6 +22,7 @@ #include "webkit/compositor_bindings/web_solid_color_layer_impl.h" #include "webkit/compositor_bindings/web_transform_animation_curve_impl.h" #include "webkit/compositor_bindings/web_video_layer_impl.h" +#include "webkit/glue/webthread_impl.h" using WebKit::WebAnimation; using WebKit::WebAnimationCurve; @@ -45,8 +47,6 @@ using WebKit::WebTransformAnimationCurve; using WebKit::WebVideoFrameProvider; using WebKit::WebVideoLayer; -using WebKit::WebCompositorImpl; - namespace webkit { WebCompositorSupportImpl::WebCompositorSupportImpl() { @@ -55,16 +55,18 @@ WebCompositorSupportImpl::WebCompositorSupportImpl() { WebCompositorSupportImpl::~WebCompositorSupportImpl() { } -void WebCompositorSupportImpl::initialize(WebKit::WebThread* thread) { - WebCompositorImpl::initialize(thread); +void WebCompositorSupportImpl::initialize(WebKit::WebThread* impl_thread) { + if (impl_thread) + impl_thread_message_loop_proxy_ = + static_cast<webkit_glue::WebThreadImpl*>(impl_thread)-> + message_loop()->message_loop_proxy(); } bool WebCompositorSupportImpl::isThreadingEnabled() { - return WebCompositorImpl::isThreadingEnabled(); + return impl_thread_message_loop_proxy_; } void WebCompositorSupportImpl::shutdown() { - WebCompositorImpl::shutdown(); } void WebCompositorSupportImpl::setPerTilePaintingEnabled(bool enabled) { @@ -88,7 +90,11 @@ WebLayerTreeView* WebCompositorSupportImpl::createLayerTreeView( const WebLayerTreeView::Settings& settings) { scoped_ptr<WebKit::WebLayerTreeViewImpl> layerTreeViewImpl( new WebKit::WebLayerTreeViewImpl(client)); - if (!layerTreeViewImpl->initialize(settings)) + scoped_ptr<cc::Thread> impl_thread(NULL); + if (impl_thread_message_loop_proxy_) + impl_thread = cc::ThreadImpl::createForDifferentThread( + impl_thread_message_loop_proxy_); + if (!layerTreeViewImpl->initialize(settings, impl_thread.Pass())) return NULL; layerTreeViewImpl->setRootLayer(root); return layerTreeViewImpl.release(); diff --git a/webkit/compositor_bindings/web_compositor_support_impl.h b/webkit/compositor_bindings/web_compositor_support_impl.h index ac7e276..6ea3eb1 100644 --- a/webkit/compositor_bindings/web_compositor_support_impl.h +++ b/webkit/compositor_bindings/web_compositor_support_impl.h @@ -5,9 +5,14 @@ #ifndef WEBKIT_COMPOSITOR_BINDINGS_WEB_COMPOSITOR_SUPPORT_IMPL_H_ #define WEBKIT_COMPOSITOR_BINDINGS_WEB_COMPOSITOR_SUPPORT_IMPL_H_ +#include "base/memory/ref_counted.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSupport.h" +namespace base { +class MessageLoopProxy; +} + namespace webkit { class WebCompositorSupportImpl : public WebKit::WebCompositorSupport { @@ -15,7 +20,7 @@ class WebCompositorSupportImpl : public WebKit::WebCompositorSupport { WebCompositorSupportImpl(); virtual ~WebCompositorSupportImpl(); - virtual void initialize(WebKit::WebThread* thread); + virtual void initialize(WebKit::WebThread* implThread); virtual bool isThreadingEnabled(); virtual void shutdown(); virtual void setPerTilePaintingEnabled(bool enabled); @@ -50,6 +55,9 @@ class WebCompositorSupportImpl : public WebKit::WebCompositorSupport { createFloatAnimationCurve(); virtual WebKit::WebTransformAnimationCurve* createTransformAnimationCurve(); + + private: + scoped_refptr<base::MessageLoopProxy> impl_thread_message_loop_proxy_; }; } // namespace webkit diff --git a/webkit/compositor_bindings/web_layer_tree_view_impl.cc b/webkit/compositor_bindings/web_layer_tree_view_impl.cc index c40802db..2c30a79 100644 --- a/webkit/compositor_bindings/web_layer_tree_view_impl.cc +++ b/webkit/compositor_bindings/web_layer_tree_view_impl.cc @@ -9,6 +9,7 @@ #include "cc/input_handler.h" #include "cc/layer.h" #include "cc/layer_tree_host.h" +#include "cc/thread.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebInputHandler.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" @@ -27,7 +28,7 @@ namespace WebKit { WebLayerTreeView* WebLayerTreeView::create(WebLayerTreeViewClient* client, const WebLayer& root, const WebLayerTreeView::Settings& settings) { scoped_ptr<WebLayerTreeViewImpl> layerTreeViewImpl(new WebLayerTreeViewImpl(client)); - if (!layerTreeViewImpl->initialize(settings)) + if (!layerTreeViewImpl->initialize(settings, scoped_ptr<Thread>(NULL))) return 0; layerTreeViewImpl->setRootLayer(root); return layerTreeViewImpl.release(); @@ -35,6 +36,7 @@ WebLayerTreeView* WebLayerTreeView::create(WebLayerTreeViewClient* client, const WebLayerTreeViewImpl::WebLayerTreeViewImpl(WebLayerTreeViewClient* client) : m_client(client) + , m_hasImplThread(false) { } @@ -42,7 +44,7 @@ WebLayerTreeViewImpl::~WebLayerTreeViewImpl() { } -bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSettings) +bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSettings, scoped_ptr<Thread> implThread) { LayerTreeSettings settings; settings.acceleratePainting = webSettings.acceleratePainting; @@ -53,7 +55,9 @@ bool WebLayerTreeViewImpl::initialize(const WebLayerTreeView::Settings& webSetti settings.refreshRate = webSettings.refreshRate; settings.defaultTileSize = webSettings.defaultTileSize; settings.maxUntiledLayerSize = webSettings.maxUntiledLayerSize; - m_layerTreeHost = LayerTreeHost::create(this, settings); + m_layerTreeHost = LayerTreeHost::create(this, settings, implThread.Pass()); + if (implThread) + m_hasImplThread = true; if (!m_layerTreeHost.get()) return false; return true; @@ -150,7 +154,7 @@ bool WebLayerTreeViewImpl::commitRequested() const void WebLayerTreeViewImpl::composite() { - if (Proxy::hasImplThread()) + if (m_hasImplThread) m_layerTreeHost->setNeedsCommit(); else m_layerTreeHost->composite(); diff --git a/webkit/compositor_bindings/web_layer_tree_view_impl.h b/webkit/compositor_bindings/web_layer_tree_view_impl.h index ae2e45d..36a20e3 100644 --- a/webkit/compositor_bindings/web_layer_tree_view_impl.h +++ b/webkit/compositor_bindings/web_layer_tree_view_impl.h @@ -11,6 +11,7 @@ namespace cc { class LayerTreeHost; +class Thread; } namespace WebKit { @@ -23,7 +24,7 @@ public: explicit WebLayerTreeViewImpl(WebLayerTreeViewClient*); virtual ~WebLayerTreeViewImpl(); - bool initialize(const Settings&); + bool initialize(const Settings&, scoped_ptr<cc::Thread> implThread); // WebLayerTreeView implementation. virtual void setSurfaceReady() OVERRIDE; @@ -70,6 +71,7 @@ public: private: WebLayerTreeViewClient* m_client; scoped_ptr<cc::LayerTreeHost> m_layerTreeHost; + bool m_hasImplThread; }; } // namespace WebKit diff --git a/webkit/compositor_bindings/web_layer_tree_view_unittest.cc b/webkit/compositor_bindings/web_layer_tree_view_unittest.cc index 3d40bde..06b6499 100644 --- a/webkit/compositor_bindings/web_layer_tree_view_unittest.cc +++ b/webkit/compositor_bindings/web_layer_tree_view_unittest.cc @@ -46,7 +46,12 @@ public: initializeCompositor(); m_rootLayer.reset(new WebLayerImpl); m_view.reset(new WebLayerTreeViewImpl(client())); - ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings())); + scoped_ptr<cc::Thread> implCCThread(NULL); + if (m_implThread) + implCCThread = cc::ThreadImpl::createForDifferentThread( + m_implThread->message_loop_proxy()); + ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings(), + implCCThread.Pass())); m_view->setRootLayer(*m_rootLayer); m_view->setSurfaceReady(); } @@ -62,6 +67,7 @@ public: protected: scoped_ptr<WebLayer> m_rootLayer; scoped_ptr<WebLayerTreeViewImpl> m_view; + scoped_ptr<base::Thread> m_implThread; }; class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { @@ -87,7 +93,6 @@ class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { protected: virtual ~WebLayerTreeViewThreadedTest() { - cc::Proxy::setImplThread(0); } void composite() @@ -105,8 +110,6 @@ protected: { m_implThread.reset(new base::Thread("ThreadedTest")); ASSERT_TRUE(m_implThread->Start()); - m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->message_loop_proxy()); - cc::Proxy::setImplThread(m_implCCThread.get()); } virtual WebLayerTreeViewClient* client() OVERRIDE @@ -115,8 +118,6 @@ protected: } MockWebLayerTreeViewClientForThreadedTests m_client; - scoped_ptr<base::Thread> m_implThread; - scoped_ptr<cc::Thread> m_implCCThread; base::CancelableClosure m_timeout; }; |