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..220dcf9e4700763ae4aab24be0fb333998c8c5e4 100644 |
--- a/components/pdf_viewer/pdf_viewer.cc |
+++ b/components/pdf_viewer/pdf_viewer.cc |
@@ -13,9 +13,9 @@ |
#include "components/view_manager/public/cpp/view_manager_client_factory.h" |
#include "components/view_manager/public/cpp/view_manager_delegate.h" |
#include "components/view_manager/public/cpp/view_observer.h" |
+#include "components/view_manager/public/interfaces/compositor_frame.mojom.h" |
#include "components/view_manager/public/interfaces/gpu.mojom.h" |
#include "components/view_manager/public/interfaces/surface_id.mojom.h" |
-#include "components/view_manager/public/interfaces/surfaces.mojom.h" |
#include "gpu/GLES2/gl2chromium.h" |
#include "gpu/GLES2/gl2extchromium.h" |
#include "mojo/application/public/cpp/application_connection.h" |
@@ -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(); |
+ 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,8 @@ class BitmapUploader : public mojo::ResourceReturner { |
frame->passes.push_back(pass.Pass()); |
- surface_->SubmitFrame(local_id_, frame.Pass(), mojo::Closure()); |
+ // TODO(rjkroege, fsamuel): We should throttle frames. |
+ cc_frame_receiver_->SubmitCompositorFrame(frame.Pass(), mojo::Closure()); |
} |
uint32_t BindTextureForSize(const mojo::Size size) { |
@@ -315,6 +281,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 +290,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_; |