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

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 1879833002: Android: Browser-side scheduling latency tweaks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/compositor/CompositorViewHolder.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/compositor_impl_android.h" 5 #include "content/browser/renderer_host/compositor_impl_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <utility> 10 #include <utility>
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&, 153 base::CancelableCallback<void(const std::vector<ui::LatencyInfo>&,
154 gfx::SwapResult)> 154 gfx::SwapResult)>
155 swap_buffers_completion_callback_; 155 swap_buffers_completion_callback_;
156 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; 156 scoped_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_;
157 }; 157 };
158 158
159 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase, 159 class ExternalBeginFrameSource : public cc::BeginFrameSourceBase,
160 public CompositorImpl::VSyncObserver { 160 public CompositorImpl::VSyncObserver {
161 public: 161 public:
162 ExternalBeginFrameSource(CompositorImpl* compositor) 162 ExternalBeginFrameSource(CompositorImpl* compositor)
163 : compositor_(compositor) { 163 : compositor_(compositor), needs_begin_frames_(false) {
164 compositor_->AddObserver(this); 164 compositor_->AddObserver(this);
165 } 165 }
166 166
167 ~ExternalBeginFrameSource() override { 167 ~ExternalBeginFrameSource() override {
168 compositor_->RemoveObserver(this); 168 compositor_->RemoveObserver(this);
169 } 169 }
170 170
171 // cc::BeginFrameSourceBase implementation: 171 // cc::BeginFrameSourceBase implementation:
172 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override { 172 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override {
173 TRACE_EVENT1("compositor", "OnNeedsBeginFramesChanged",
174 "needs_begin_frames", needs_begin_frames);
173 compositor_->OnNeedsBeginFramesChange(needs_begin_frames); 175 compositor_->OnNeedsBeginFramesChange(needs_begin_frames);
176 needs_begin_frames_ = needs_begin_frames;
177 if (needs_begin_frames) {
no sievers 2016/04/11 23:10:10 Oh I was going to ask: Should I also remember the
178 base::TimeTicks now = base::TimeTicks::Now();
179 // Since |needs_begin_frames_| turned on, the scheduler wants to draw,
180 // so the dealine doesn't matter much. But pass something large enough
181 // to make sure we don't get discarded in BeginRetroFrame(), see
182 // crbug.com/602485.
183 base::TimeTicks deadline = now + base::TimeDelta::FromMilliseconds(16);
184 cc::BeginFrameArgs args(cc::BeginFrameArgs::Create(
185 BEGINFRAME_FROM_HERE, now, deadline,
186 base::TimeDelta::FromMilliseconds(16), cc::BeginFrameArgs::NORMAL));
187 base::Closure tick =
188 base::Bind(&ExternalBeginFrameSource::CallOnBeginFrame,
189 base::Unretained(this), args);
190 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, tick);
191 }
174 } 192 }
175 193
176 // CompositorImpl::VSyncObserver implementation: 194 // CompositorImpl::VSyncObserver implementation:
177 void OnVSync(base::TimeTicks frame_time, 195 void OnVSync(base::TimeTicks frame_time,
178 base::TimeDelta vsync_period) override { 196 base::TimeDelta vsync_period) override {
179 CallOnBeginFrame(cc::BeginFrameArgs::Create( 197 base::TimeTicks deadline = frame_time + 2 * vsync_period / 3;
180 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks::Now(), vsync_period, 198 if (needs_begin_frames_) {
181 cc::BeginFrameArgs::NORMAL)); 199 CallOnBeginFrame(
200 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline,
201 vsync_period, cc::BeginFrameArgs::NORMAL));
202 }
182 } 203 }
183 204
184 private: 205 private:
185 CompositorImpl* compositor_; 206 CompositorImpl* compositor_;
207 bool needs_begin_frames_;
186 }; 208 };
187 209
188 static bool g_initialized = false; 210 static bool g_initialized = false;
189 211
190 base::LazyInstance<cc::SurfaceManager> g_surface_manager = 212 base::LazyInstance<cc::SurfaceManager> g_surface_manager =
191 LAZY_INSTANCE_INITIALIZER; 213 LAZY_INSTANCE_INITIALIZER;
192 214
193 int g_surface_id_namespace = 0; 215 int g_surface_id_namespace = 0;
194 216
195 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { 217 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 421
400 void CompositorImpl::SetHasTransparentBackground(bool flag) { 422 void CompositorImpl::SetHasTransparentBackground(bool flag) {
401 has_transparent_background_ = flag; 423 has_transparent_background_ = flag;
402 if (host_) 424 if (host_)
403 host_->set_has_transparent_background(flag); 425 host_->set_has_transparent_background(flag);
404 } 426 }
405 427
406 void CompositorImpl::SetNeedsComposite() { 428 void CompositorImpl::SetNeedsComposite() {
407 if (!host_->visible()) 429 if (!host_->visible())
408 return; 430 return;
431 TRACE_EVENT0("compositor", "Compositor::SetNeedsComposite");
409 host_->SetNeedsAnimate(); 432 host_->SetNeedsAnimate();
410 } 433 }
411 434
412 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> 435 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
413 CreateGpuProcessViewContext( 436 CreateGpuProcessViewContext(
414 const scoped_refptr<gpu::GpuChannelHost>& gpu_channel_host, 437 const scoped_refptr<gpu::GpuChannelHost>& gpu_channel_host,
415 const gpu::gles2::ContextCreationAttribHelper& attributes, 438 const gpu::gles2::ContextCreationAttribHelper& attributes,
416 int surface_id) { 439 int surface_id) {
417 GURL url("chrome://gpu/Compositor::createContext3D"); 440 GURL url("chrome://gpu/Compositor::createContext3D");
418 static const size_t kBytesPerPixel = 4; 441 static const size_t kBytesPerPixel = 4;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 void CompositorImpl::AddObserver(VSyncObserver* observer) { 601 void CompositorImpl::AddObserver(VSyncObserver* observer) {
579 observer_list_.AddObserver(observer); 602 observer_list_.AddObserver(observer);
580 } 603 }
581 604
582 void CompositorImpl::RemoveObserver(VSyncObserver* observer) { 605 void CompositorImpl::RemoveObserver(VSyncObserver* observer) {
583 observer_list_.RemoveObserver(observer); 606 observer_list_.RemoveObserver(observer);
584 } 607 }
585 608
586 cc::UIResourceId CompositorImpl::CreateUIResource( 609 cc::UIResourceId CompositorImpl::CreateUIResource(
587 cc::UIResourceClient* client) { 610 cc::UIResourceClient* client) {
611 TRACE_EVENT0("compositor", "CompositorImpl::CreateUIResource");
588 return host_->CreateUIResource(client); 612 return host_->CreateUIResource(client);
589 } 613 }
590 614
591 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { 615 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) {
616 TRACE_EVENT0("compositor", "CompositorImpl::DeleteUIResource");
592 host_->DeleteUIResource(resource_id); 617 host_->DeleteUIResource(resource_id);
593 } 618 }
594 619
595 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const { 620 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const {
596 return gpu_capabilities_.texture_format_etc1_npot; 621 return gpu_capabilities_.texture_format_etc1_npot;
597 } 622 }
598 623
599 void CompositorImpl::DidPostSwapBuffers() { 624 void CompositorImpl::DidPostSwapBuffers() {
600 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); 625 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers");
601 pending_swapbuffers_++; 626 pending_swapbuffers_++;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 needs_begin_frames_ = needs_begin_frames; 667 needs_begin_frames_ = needs_begin_frames;
643 if (needs_begin_frames_) 668 if (needs_begin_frames_)
644 root_window_->RequestVSyncUpdate(); 669 root_window_->RequestVSyncUpdate();
645 } 670 }
646 671
647 void CompositorImpl::SetNeedsAnimate() { 672 void CompositorImpl::SetNeedsAnimate() {
648 needs_animate_ = true; 673 needs_animate_ = true;
649 if (!host_->visible()) 674 if (!host_->visible())
650 return; 675 return;
651 676
677 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate");
652 host_->SetNeedsAnimate(); 678 host_->SetNeedsAnimate();
653 } 679 }
654 680
655 } // namespace content 681 } // namespace content
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/compositor/CompositorViewHolder.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698