Chromium Code Reviews| Index: ppapi/example/example.cc |
| diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc |
| index 34b39f2fda14edc9aa713934144d5cd7d82f7cd7..71e9a4549aa0b467a4271d391eba7322d3e033cb 100644 |
| --- a/ppapi/example/example.cc |
| +++ b/ppapi/example/example.cc |
| @@ -31,6 +31,7 @@ |
| #include "ppapi/cpp/url_loader.h" |
| #include "ppapi/cpp/url_request_info.h" |
| #include "ppapi/cpp/var.h" |
| +#include "ppapi/cpp/view.h" |
| static const int kStepsPerCircle = 800; |
| @@ -166,8 +167,6 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { |
| : pp::InstancePrivate(instance), |
| time_at_last_check_(0.0), |
| fetcher_(NULL), |
| - width_(0), |
| - height_(0), |
| animation_counter_(0), |
| print_settings_valid_(false), |
| showing_custom_cursor_(false), |
| @@ -220,11 +219,10 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { |
| return pp::VarPrivate(this, new MyScriptableObject(this)); |
| } |
| - pp::ImageData PaintImage(int width, int height) { |
| - pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
| - pp::Size(width, height), false); |
| + pp::ImageData PaintImage(const pp::Size& size) { |
| + pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false); |
| if (image.is_null()) { |
| - printf("Couldn't allocate the image data: %d, %d\n", width, height); |
| + printf("Couldn't allocate the image data."); |
| return image; |
| } |
| @@ -243,7 +241,8 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { |
| float radians = static_cast<float>(animation_counter_) / kStepsPerCircle * |
| 2 * 3.14159265358979F; |
| - float radius = static_cast<float>(std::min(width, height)) / 2.0f - 3.0f; |
| + float radius = |
| + static_cast<float>(std::min(size.width(), size.height())) / 2.0f - 3.0f; |
| int x = static_cast<int>(cos(radians) * radius + radius + 2); |
| int y = static_cast<int>(sin(radians) * radius + radius + 2); |
| @@ -253,27 +252,24 @@ class MyInstance : public pp::InstancePrivate, public MyFetcherClient { |
| } |
| void Paint() { |
| - pp::ImageData image = PaintImage(width_, height_); |
| + pp::ImageData image = PaintImage(device_context_.size()); |
| if (!image.is_null()) { |
| device_context_.ReplaceContents(&image); |
| device_context_.Flush(pp::CompletionCallback(&FlushCallback, this)); |
| } else { |
| - printf("NullImage: %d, %d\n", width_, height_); |
| + printf("NullImage\n"); |
| } |
| } |
| - virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) { |
| + virtual void DidChangeView(const pp::View& view) { |
| Log(PP_LOGLEVEL_LOG, "DidChangeView"); |
| - if (position.size().width() == width_ && |
| - position.size().height() == height_) |
| + if (view.GetViewportRect().size() != current_view_.GetViewportRect().size()) |
|
dmichael (off chromium)
2011/12/16 04:14:31
That's not bad, though it doesn't handle the initi
brettw
2011/12/19 22:53:40
It does since the current_view_ is intitialized to
|
| return; // We don't care about the position, only the size. |
| - width_ = position.size().width(); |
| - height_ = position.size().height(); |
| printf("DidChangeView relevant change: width=%d height:%d\n", |
| - width_, height_); |
| + view.GetViewportRect().width(), view.GetViewportRect().height()); |
| - device_context_ = pp::Graphics2D(this, pp::Size(width_, height_), false); |
| + device_context_ = pp::Graphics2D(this, view.GetViewportRect.size(), false); |
| if (!BindGraphics(device_context_)) { |
| printf("Couldn't bind the device context\n"); |
| return; |
| @@ -358,14 +354,13 @@ int gettimeofday(struct timeval *tv, struct timezone*) { |
| return pp::Resource(); |
| } |
| - int width = static_cast<int>( |
| - (print_settings_.printable_area.size.width / 72.0) * |
| - print_settings_.dpi); |
| - int height = static_cast<int>( |
| - (print_settings_.printable_area.size.height / 72.0) * |
| - print_settings_.dpi); |
| - |
| - return PaintImage(width, height); |
| + pp::Size size(static_cast<int>( |
| + (print_settings_.printable_area.size.width / 72.0) * |
| + print_settings_.dpi), |
| + static_cast<int>( |
| + (print_settings_.printable_area.size.height / 72.0) * |
| + print_settings_.dpi)); |
| + return PaintImage(size); |
| } |
| virtual void PrintEnd() { |
| @@ -469,10 +464,9 @@ int gettimeofday(struct timeval *tv, struct timezone*) { |
| double time_at_last_check_; |
| - MyFetcher* fetcher_; |
| + pp::View current_view_; |
| - int width_; |
| - int height_; |
| + MyFetcher* fetcher_; |
| // Incremented for each flush we get. |
| int animation_counter_; |