Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 ExternalBeginFrameSource(CompositorImpl* compositor) | 162 ExternalBeginFrameSource(CompositorImpl* compositor) |
| 163 : compositor_(compositor) { | 163 : compositor_(compositor) { |
| 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 AddObserver(cc::BeginFrameObserver* obs) override { | |
|
enne (OOO)
2016/04/22 19:58:14
I do think that maybe we should just put this in t
no sievers
2016/04/22 19:59:43
Yea, I'll let Sunny consolidate this in his patch
| |
| 173 cc::BeginFrameSourceBase::AddObserver(obs); | |
| 174 DCHECK(needs_begin_frames()); | |
| 175 if (!last_begin_frame_args_.IsValid()) | |
| 176 return; | |
| 177 | |
| 178 // Send a MISSED begin frame if necessary. | |
| 179 cc::BeginFrameArgs last_args = obs->LastUsedBeginFrameArgs(); | |
| 180 if (!last_args.IsValid() || | |
| 181 (last_begin_frame_args_.frame_time > last_args.frame_time)) { | |
| 182 last_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | |
| 183 // TODO(crbug.com/602485): A deadline doesn't make too much sense | |
| 184 // for a missed BeginFrame (the intention rather is 'immediately'), | |
| 185 // but currently the retro frame logic is very strict in discarding | |
| 186 // BeginFrames. | |
| 187 last_begin_frame_args_.deadline = | |
| 188 base::TimeTicks::Now() + last_begin_frame_args_.interval; | |
| 189 obs->OnBeginFrame(last_begin_frame_args_); | |
| 190 } | |
| 191 } | |
| 192 | |
| 172 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override { | 193 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override { |
| 194 TRACE_EVENT1("compositor", "OnNeedsBeginFramesChanged", | |
| 195 "needs_begin_frames", needs_begin_frames); | |
| 173 compositor_->OnNeedsBeginFramesChange(needs_begin_frames); | 196 compositor_->OnNeedsBeginFramesChange(needs_begin_frames); |
| 174 } | 197 } |
| 175 | 198 |
| 176 // CompositorImpl::VSyncObserver implementation: | 199 // CompositorImpl::VSyncObserver implementation: |
| 177 void OnVSync(base::TimeTicks frame_time, | 200 void OnVSync(base::TimeTicks frame_time, |
| 178 base::TimeDelta vsync_period) override { | 201 base::TimeDelta vsync_period) override { |
| 179 CallOnBeginFrame(cc::BeginFrameArgs::Create( | 202 base::TimeTicks deadline = std::max(base::TimeTicks::Now(), frame_time); |
| 180 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks::Now(), vsync_period, | 203 last_begin_frame_args_ = |
| 181 cc::BeginFrameArgs::NORMAL)); | 204 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, |
| 205 vsync_period, cc::BeginFrameArgs::NORMAL); | |
| 206 CallOnBeginFrame(last_begin_frame_args_); | |
| 182 } | 207 } |
| 183 | 208 |
| 184 private: | 209 private: |
| 185 CompositorImpl* compositor_; | 210 CompositorImpl* compositor_; |
| 211 cc::BeginFrameArgs last_begin_frame_args_; | |
| 186 }; | 212 }; |
| 187 | 213 |
| 188 static bool g_initialized = false; | 214 static bool g_initialized = false; |
| 189 | 215 |
| 190 base::LazyInstance<cc::SurfaceManager> g_surface_manager = | 216 base::LazyInstance<cc::SurfaceManager> g_surface_manager = |
| 191 LAZY_INSTANCE_INITIALIZER; | 217 LAZY_INSTANCE_INITIALIZER; |
| 192 | 218 |
| 193 int g_surface_id_namespace = 0; | 219 int g_surface_id_namespace = 0; |
| 194 | 220 |
| 195 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { | 221 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 | 425 |
| 400 void CompositorImpl::SetHasTransparentBackground(bool flag) { | 426 void CompositorImpl::SetHasTransparentBackground(bool flag) { |
| 401 has_transparent_background_ = flag; | 427 has_transparent_background_ = flag; |
| 402 if (host_) | 428 if (host_) |
| 403 host_->set_has_transparent_background(flag); | 429 host_->set_has_transparent_background(flag); |
| 404 } | 430 } |
| 405 | 431 |
| 406 void CompositorImpl::SetNeedsComposite() { | 432 void CompositorImpl::SetNeedsComposite() { |
| 407 if (!host_->visible()) | 433 if (!host_->visible()) |
| 408 return; | 434 return; |
| 435 TRACE_EVENT0("compositor", "Compositor::SetNeedsComposite"); | |
| 409 host_->SetNeedsAnimate(); | 436 host_->SetNeedsAnimate(); |
| 410 } | 437 } |
| 411 | 438 |
| 412 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> | 439 static scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
| 413 CreateGpuProcessViewContext( | 440 CreateGpuProcessViewContext( |
| 414 const scoped_refptr<gpu::GpuChannelHost>& gpu_channel_host, | 441 const scoped_refptr<gpu::GpuChannelHost>& gpu_channel_host, |
| 415 const gpu::gles2::ContextCreationAttribHelper& attributes, | 442 const gpu::gles2::ContextCreationAttribHelper& attributes, |
| 416 int surface_id) { | 443 int surface_id) { |
| 417 GURL url("chrome://gpu/Compositor::createContext3D"); | 444 GURL url("chrome://gpu/Compositor::createContext3D"); |
| 418 static const size_t kBytesPerPixel = 4; | 445 static const size_t kBytesPerPixel = 4; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 void CompositorImpl::AddObserver(VSyncObserver* observer) { | 605 void CompositorImpl::AddObserver(VSyncObserver* observer) { |
| 579 observer_list_.AddObserver(observer); | 606 observer_list_.AddObserver(observer); |
| 580 } | 607 } |
| 581 | 608 |
| 582 void CompositorImpl::RemoveObserver(VSyncObserver* observer) { | 609 void CompositorImpl::RemoveObserver(VSyncObserver* observer) { |
| 583 observer_list_.RemoveObserver(observer); | 610 observer_list_.RemoveObserver(observer); |
| 584 } | 611 } |
| 585 | 612 |
| 586 cc::UIResourceId CompositorImpl::CreateUIResource( | 613 cc::UIResourceId CompositorImpl::CreateUIResource( |
| 587 cc::UIResourceClient* client) { | 614 cc::UIResourceClient* client) { |
| 615 TRACE_EVENT0("compositor", "CompositorImpl::CreateUIResource"); | |
| 588 return host_->CreateUIResource(client); | 616 return host_->CreateUIResource(client); |
| 589 } | 617 } |
| 590 | 618 |
| 591 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | 619 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
| 620 TRACE_EVENT0("compositor", "CompositorImpl::DeleteUIResource"); | |
| 592 host_->DeleteUIResource(resource_id); | 621 host_->DeleteUIResource(resource_id); |
| 593 } | 622 } |
| 594 | 623 |
| 595 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const { | 624 bool CompositorImpl::SupportsETC1NonPowerOfTwo() const { |
| 596 return gpu_capabilities_.texture_format_etc1_npot; | 625 return gpu_capabilities_.texture_format_etc1_npot; |
| 597 } | 626 } |
| 598 | 627 |
| 599 void CompositorImpl::DidPostSwapBuffers() { | 628 void CompositorImpl::DidPostSwapBuffers() { |
| 600 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); | 629 TRACE_EVENT0("compositor", "CompositorImpl::DidPostSwapBuffers"); |
| 601 pending_swapbuffers_++; | 630 pending_swapbuffers_++; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 needs_begin_frames_ = needs_begin_frames; | 671 needs_begin_frames_ = needs_begin_frames; |
| 643 if (needs_begin_frames_) | 672 if (needs_begin_frames_) |
| 644 root_window_->RequestVSyncUpdate(); | 673 root_window_->RequestVSyncUpdate(); |
| 645 } | 674 } |
| 646 | 675 |
| 647 void CompositorImpl::SetNeedsAnimate() { | 676 void CompositorImpl::SetNeedsAnimate() { |
| 648 needs_animate_ = true; | 677 needs_animate_ = true; |
| 649 if (!host_->visible()) | 678 if (!host_->visible()) |
| 650 return; | 679 return; |
| 651 | 680 |
| 681 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | |
| 652 host_->SetNeedsAnimate(); | 682 host_->SetNeedsAnimate(); |
| 653 } | 683 } |
| 654 | 684 |
| 655 } // namespace content | 685 } // namespace content |
| OLD | NEW |