Chromium Code Reviews| Index: components/pdf_viewer/pdf_viewer.cc |
| diff --git a/components/pdf_viewer/pdf_viewer.cc b/components/pdf_viewer/pdf_viewer.cc |
| index aba1f63cf49ff26491addaec2c0c377f41ff9ab5..78db223e43fac25d6f11130cde47fa3ba53beba4 100644 |
| --- a/components/pdf_viewer/pdf_viewer.cc |
| +++ b/components/pdf_viewer/pdf_viewer.cc |
| @@ -72,18 +72,7 @@ class BitmapUploader : public mojo::ResourceReturner { |
| } |
| void Init(mojo::Shell* shell) { |
| - mojo::ServiceProviderPtr surfaces_service_provider; |
| - mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| - request->url = mojo::String::From("mojo:view_manager"); |
| - shell->ConnectToApplication(request.Pass(), |
| - mojo::GetProxy(&surfaces_service_provider), |
| - nullptr, nullptr); |
| - ConnectToService(surfaces_service_provider.get(), &surface_); |
| - surface_->GetIdNamespace( |
| - base::Bind(&BitmapUploader::SetIdNamespace, base::Unretained(this))); |
| - mojo::ResourceReturnerPtr returner_ptr; |
| - returner_binding_.Bind(GetProxy(&returner_ptr)); |
| - surface_->SetResourceReturner(returner_ptr.Pass()); |
| + view_->RequestCompositorFrameReceiver(GetProxy(&cc_frame_receiver_)); |
| mojo::ServiceProviderPtr gpu_service_provider; |
| mojo::URLRequestPtr request2(mojo::URLRequest::New()); |
| @@ -106,7 +95,7 @@ class BitmapUploader : public mojo::ResourceReturner { |
| if (color_ == color) |
| return; |
| color_ = color; |
| - if (surface_) |
| + if (cc_frame_receiver_) |
| Upload(); |
| } |
| @@ -124,44 +113,20 @@ class BitmapUploader : public mojo::ResourceReturner { |
| height_ = height; |
| bitmap_ = data.Pass(); |
| format_ = format; |
| - if (surface_) |
| + if (cc_frame_receiver_) |
| Upload(); |
| } |
| private: |
| void Upload() { |
| - mojo::Size size; |
| - size.width = view_->bounds().width; |
| - size.height = view_->bounds().height; |
| - if (!size.width || !size.height) { |
| - view_->SetSurfaceId(mojo::SurfaceId::New()); |
| - return; |
| - } |
| - |
| - if (id_namespace_ == 0u) // Can't generate a qualified ID yet. |
| - return; |
| - |
| - if (size != surface_size_) { |
| - if (local_id_ != 0u) { |
| - surface_->DestroySurface(local_id_); |
| - } |
| - local_id_++; |
| - surface_->CreateSurface(local_id_); |
| - surface_size_ = size; |
| - auto qualified_id = mojo::SurfaceId::New(); |
| - qualified_id->id_namespace = id_namespace_; |
| - qualified_id->local = local_id_; |
| - view_->SetSurfaceId(qualified_id.Pass()); |
| - } |
| - |
| - gfx::Rect bounds(size.width, size.height); |
| + gfx::Rect bounds(view_->bounds().To<gfx::Rect>()); |
| mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); |
| mojo::CompositorFramePtr frame = mojo::CompositorFrame::New(); |
| frame->resources.resize(0u); |
| pass->quads.resize(0u); |
| pass->shared_quad_states.push_back( |
| - mojo::CreateDefaultSQS(size.To<gfx::Size>())); |
| + mojo::CreateDefaultSQS(bounds.size())); |
| MojoGLES2MakeCurrent(gles2_context_); |
| if (bitmap_.get()) { |
| @@ -205,19 +170,19 @@ class BitmapUploader : public mojo::ResourceReturner { |
| quad->material = mojo::MATERIAL_TEXTURE_CONTENT; |
| mojo::RectPtr rect = mojo::Rect::New(); |
| - if (width_ <= size.width && height_ <= size.height) { |
| + if (width_ <= bounds.width() && height_ <= bounds.height()) { |
| rect->width = width_; |
| rect->height = height_; |
| } else { |
| // The source bitmap is larger than the viewport. Resize it while |
| // maintaining the aspect ratio. |
| - float width_ratio = static_cast<float>(width_) / size.width; |
| - float height_ratio = static_cast<float>(height_) / size.height; |
| + float width_ratio = static_cast<float>(width_) / bounds.width(); |
|
rjkroege
2015/08/21 18:54:45
you have tested this in high DIP mode?
Fady Samuel
2015/08/21 21:31:10
This code worked in the past on android, and this
rjkroege
2015/08/21 22:58:00
you are making a presumption that bounds and size
Fady Samuel
2015/08/21 23:15:26
There is no unit conversion above.
|
| + float height_ratio = static_cast<float>(height_) / bounds.height(); |
| if (width_ratio > height_ratio) { |
| - rect->width = size.width; |
| + rect->width = bounds.width(); |
| rect->height = height_ / width_ratio; |
| } else { |
| - rect->height = size.height; |
| + rect->height = bounds.height(); |
| rect->width = width_ / height_ratio; |
| } |
| } |
| @@ -266,7 +231,7 @@ class BitmapUploader : public mojo::ResourceReturner { |
| frame->passes.push_back(pass.Pass()); |
| - surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure()); |
| + cc_frame_receiver_->SubmitCompositorFrame(frame.Pass(), mojo::Closure()); |
|
rjkroege
2015/08/19 23:45:44
replacing this mojo::Closure() here with a real ca
Fady Samuel
2015/08/20 16:22:44
Added TODO.
|
| } |
| uint32_t BindTextureForSize(const mojo::Size size) { |
| @@ -315,6 +280,7 @@ class BitmapUploader : public mojo::ResourceReturner { |
| mojo::View* view_; |
| mojo::GpuPtr gpu_service_; |
| + mojo::CompositorFrameReceiverPtr cc_frame_receiver_; |
| MojoGLES2Context gles2_context_; |
| mojo::Size size_; |
| @@ -323,8 +289,6 @@ class BitmapUploader : public mojo::ResourceReturner { |
| int height_; |
| Format format_; |
| scoped_ptr<std::vector<unsigned char>> bitmap_; |
| - mojo::SurfacePtr surface_; |
| - mojo::Size surface_size_; |
| uint32_t next_resource_id_; |
| uint32_t id_namespace_; |
| uint32_t local_id_; |