| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "pdf/paint_manager.h" | 5 #include "pdf/paint_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 14 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
| 15 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 16 | 16 |
| 17 PaintManager::ReadyRect::ReadyRect() = default; |
| 18 |
| 19 PaintManager::ReadyRect::ReadyRect(const pp::Rect& r, |
| 20 const pp::ImageData& i, |
| 21 bool f) |
| 22 : rect(r), image_data(i), flush_now(f) {} |
| 23 |
| 24 PaintManager::ReadyRect::ReadyRect(const ReadyRect& that) = default; |
| 25 |
| 17 PaintManager::PaintManager(pp::Instance* instance, | 26 PaintManager::PaintManager(pp::Instance* instance, |
| 18 Client* client, | 27 Client* client, |
| 19 bool is_always_opaque) | 28 bool is_always_opaque) |
| 20 : instance_(instance), | 29 : instance_(instance), |
| 21 client_(client), | 30 client_(client), |
| 22 is_always_opaque_(is_always_opaque), | 31 is_always_opaque_(is_always_opaque), |
| 23 callback_factory_(NULL), | 32 callback_factory_(nullptr), |
| 24 manual_callback_pending_(false), | 33 manual_callback_pending_(false), |
| 25 flush_pending_(false), | 34 flush_pending_(false), |
| 26 has_pending_resize_(false), | 35 has_pending_resize_(false), |
| 27 graphics_need_to_be_bound_(false), | 36 graphics_need_to_be_bound_(false), |
| 28 pending_device_scale_(1.0), | 37 pending_device_scale_(1.0), |
| 29 device_scale_(1.0), | 38 device_scale_(1.0), |
| 30 in_paint_(false), | 39 in_paint_(false), |
| 31 first_paint_(true), | 40 first_paint_(true), |
| 32 view_size_changed_waiting_for_paint_(false) { | 41 view_size_changed_waiting_for_paint_(false) { |
| 33 // Set the callback object outside of the initializer list to avoid a | 42 // Set the callback object outside of the initializer list to avoid a |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 pp::Module::Get()->core()->CallOnMainThread( | 166 pp::Module::Get()->core()->CallOnMainThread( |
| 158 0, | 167 0, |
| 159 callback_factory_.NewCallback(&PaintManager::OnManualCallbackComplete), | 168 callback_factory_.NewCallback(&PaintManager::OnManualCallbackComplete), |
| 160 0); | 169 0); |
| 161 manual_callback_pending_ = true; | 170 manual_callback_pending_ = true; |
| 162 } | 171 } |
| 163 | 172 |
| 164 void PaintManager::DoPaint() { | 173 void PaintManager::DoPaint() { |
| 165 in_paint_ = true; | 174 in_paint_ = true; |
| 166 | 175 |
| 167 std::vector<ReadyRect> ready; | 176 std::vector<ReadyRect> ready_rects; |
| 168 std::vector<pp::Rect> pending; | 177 std::vector<pp::Rect> pending_rects; |
| 169 | 178 |
| 170 DCHECK(aggregator_.HasPendingUpdate()); | 179 DCHECK(aggregator_.HasPendingUpdate()); |
| 171 | 180 |
| 172 // Apply any pending resize. Setting the graphics to this class must happen | 181 // Apply any pending resize. Setting the graphics to this class must happen |
| 173 // before asking the plugin to paint in case it requests invalides or resizes. | 182 // before asking the plugin to paint in case it requests invalides or resizes. |
| 174 // However, the bind must not happen until afterward since we don't want to | 183 // However, the bind must not happen until afterward since we don't want to |
| 175 // have an unpainted device bound. The needs_binding flag tells us whether to | 184 // have an unpainted device bound. The needs_binding flag tells us whether to |
| 176 // do this later. | 185 // do this later. |
| 177 if (has_pending_resize_) { | 186 if (has_pending_resize_) { |
| 178 plugin_size_ = pending_size_; | 187 plugin_size_ = pending_size_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 194 graphics_.SetScale(1.0 / pending_device_scale_); | 203 graphics_.SetScale(1.0 / pending_device_scale_); |
| 195 device_scale_ = pending_device_scale_; | 204 device_scale_ = pending_device_scale_; |
| 196 | 205 |
| 197 // This must be cleared before calling into the plugin since it may do | 206 // This must be cleared before calling into the plugin since it may do |
| 198 // additional invalidation or sizing operations. | 207 // additional invalidation or sizing operations. |
| 199 has_pending_resize_ = false; | 208 has_pending_resize_ = false; |
| 200 pending_size_ = pp::Size(); | 209 pending_size_ = pp::Size(); |
| 201 } | 210 } |
| 202 | 211 |
| 203 PaintAggregator::PaintUpdate update = aggregator_.GetPendingUpdate(); | 212 PaintAggregator::PaintUpdate update = aggregator_.GetPendingUpdate(); |
| 204 client_->OnPaint(update.paint_rects, &ready, &pending); | 213 client_->OnPaint(update.paint_rects, &ready_rects, &pending_rects); |
| 205 | 214 |
| 206 if (ready.empty() && pending.empty()) { | 215 if (ready_rects.empty() && pending_rects.empty()) { |
| 207 in_paint_ = false; | 216 in_paint_ = false; |
| 208 return; // Nothing was painted, don't schedule a flush. | 217 return; // Nothing was painted, don't schedule a flush. |
| 209 } | 218 } |
| 210 | 219 |
| 211 std::vector<PaintAggregator::ReadyRect> ready_now; | 220 std::vector<PaintAggregator::ReadyRect> ready_now; |
| 212 if (pending.empty()) { | 221 if (pending_rects.empty()) { |
| 213 std::vector<PaintAggregator::ReadyRect> temp_ready; | 222 std::vector<PaintAggregator::ReadyRect> temp_ready; |
| 214 temp_ready.insert(temp_ready.end(), ready.begin(), ready.end()); | 223 temp_ready.insert(temp_ready.end(), ready_rects.begin(), ready_rects.end()); |
| 215 aggregator_.SetIntermediateResults(temp_ready, pending); | 224 aggregator_.SetIntermediateResults(temp_ready, pending_rects); |
| 216 ready_now = aggregator_.GetReadyRects(); | 225 ready_now = aggregator_.GetReadyRects(); |
| 217 aggregator_.ClearPendingUpdate(); | 226 aggregator_.ClearPendingUpdate(); |
| 218 | 227 |
| 219 // Apply any scroll first. | 228 // Apply any scroll first. |
| 220 if (update.has_scroll) | 229 if (update.has_scroll) |
| 221 graphics_.Scroll(update.scroll_rect, update.scroll_delta); | 230 graphics_.Scroll(update.scroll_rect, update.scroll_delta); |
| 222 | 231 |
| 223 view_size_changed_waiting_for_paint_ = false; | 232 view_size_changed_waiting_for_paint_ = false; |
| 224 } else { | 233 } else { |
| 225 std::vector<PaintAggregator::ReadyRect> ready_later; | 234 std::vector<PaintAggregator::ReadyRect> ready_later; |
| 226 for (const auto& ready_rect : ready) { | 235 for (const auto& ready_rect : ready_rects) { |
| 227 // Don't flush any part (i.e. scrollbars) if we're resizing the browser, | 236 // Don't flush any part (i.e. scrollbars) if we're resizing the browser, |
| 228 // as that'll lead to flashes. Until we flush, the browser will use the | 237 // as that'll lead to flashes. Until we flush, the browser will use the |
| 229 // previous image, but if we flush, it'll revert to using the blank image. | 238 // previous image, but if we flush, it'll revert to using the blank image. |
| 230 // We make an exception for the first paint since we want to show the | 239 // We make an exception for the first paint since we want to show the |
| 231 // default background color instead of the pepper default of black. | 240 // default background color instead of the pepper default of black. |
| 232 if (ready_rect.flush_now && | 241 if (ready_rect.flush_now && |
| 233 (!view_size_changed_waiting_for_paint_ || first_paint_)) { | 242 (!view_size_changed_waiting_for_paint_ || first_paint_)) { |
| 234 ready_now.push_back(ready_rect); | 243 ready_now.push_back(ready_rect); |
| 235 } else { | 244 } else { |
| 236 ready_later.push_back(ready_rect); | 245 ready_later.push_back(ready_rect); |
| 237 } | 246 } |
| 238 } | 247 } |
| 239 // Take the rectangles, except the ones that need to be flushed right away, | 248 // Take the rectangles, except the ones that need to be flushed right away, |
| 240 // and save them so that everything is flushed at once. | 249 // and save them so that everything is flushed at once. |
| 241 aggregator_.SetIntermediateResults(ready_later, pending); | 250 aggregator_.SetIntermediateResults(ready_later, pending_rects); |
| 242 | 251 |
| 243 if (ready_now.empty()) { | 252 if (ready_now.empty()) { |
| 244 in_paint_ = false; | 253 in_paint_ = false; |
| 245 EnsureCallbackPending(); | 254 EnsureCallbackPending(); |
| 246 return; | 255 return; |
| 247 } | 256 } |
| 248 } | 257 } |
| 249 | 258 |
| 250 for (const auto& ready_rect : ready_now) { | 259 for (const auto& ready_rect : ready_now) { |
| 251 graphics_.PaintImageData( | 260 graphics_.PaintImageData( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 DCHECK(manual_callback_pending_); | 304 DCHECK(manual_callback_pending_); |
| 296 manual_callback_pending_ = false; | 305 manual_callback_pending_ = false; |
| 297 | 306 |
| 298 // Just because we have a manual callback doesn't mean there are actually any | 307 // Just because we have a manual callback doesn't mean there are actually any |
| 299 // invalid regions. Even though we only schedule this callback when something | 308 // invalid regions. Even though we only schedule this callback when something |
| 300 // is pending, a Flush callback could have come in before this callback was | 309 // is pending, a Flush callback could have come in before this callback was |
| 301 // executed and that could have cleared the queue. | 310 // executed and that could have cleared the queue. |
| 302 if (aggregator_.HasPendingUpdate()) | 311 if (aggregator_.HasPendingUpdate()) |
| 303 DoPaint(); | 312 DoPaint(); |
| 304 } | 313 } |
| OLD | NEW |