Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc

Issue 10544168: Implement HiDPI support in Pepper dev interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" 5 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 // Valid when type == REPLACE. 153 // Valid when type == REPLACE.
154 scoped_refptr<PPB_ImageData_Impl> replace_image; 154 scoped_refptr<PPB_ImageData_Impl> replace_image;
155 }; 155 };
156 156
157 PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PP_Instance instance) 157 PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PP_Instance instance)
158 : Resource(::ppapi::OBJECT_IS_IMPL, instance), 158 : Resource(::ppapi::OBJECT_IS_IMPL, instance),
159 bound_instance_(NULL), 159 bound_instance_(NULL),
160 offscreen_flush_pending_(false), 160 offscreen_flush_pending_(false),
161 is_always_opaque_(false), 161 is_always_opaque_(false),
162 scale_(1.0f),
162 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 163 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
163 } 164 }
164 165
165 PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() { 166 PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() {
166 // LastPluginRefWasDeleted should have aborted all pending callbacks. 167 // LastPluginRefWasDeleted should have aborted all pending callbacks.
167 DCHECK(painted_flush_callback_.is_null()); 168 DCHECK(painted_flush_callback_.is_null());
168 DCHECK(unpainted_flush_callback_.is_null()); 169 DCHECK(unpainted_flush_callback_.is_null());
169 } 170 }
170 171
171 // static 172 // static
172 PP_Resource PPB_Graphics2D_Impl::Create(PP_Instance instance, 173 PP_Resource PPB_Graphics2D_Impl::Create(PP_Instance instance,
173 const PP_Size& size, 174 const PP_Size& size,
174 PP_Bool is_always_opaque) { 175 PP_Bool is_always_opaque,
176 float scale) {
175 scoped_refptr<PPB_Graphics2D_Impl> graphics_2d( 177 scoped_refptr<PPB_Graphics2D_Impl> graphics_2d(
176 new PPB_Graphics2D_Impl(instance)); 178 new PPB_Graphics2D_Impl(instance));
177 if (!graphics_2d->Init(size.width, size.height, 179 if (!graphics_2d->Init(size.width, size.height,
178 PPBoolToBool(is_always_opaque))) { 180 PPBoolToBool(is_always_opaque), scale)) {
179 return 0; 181 return 0;
180 } 182 }
181 return graphics_2d->GetReference(); 183 return graphics_2d->GetReference();
182 } 184 }
183 185
184 bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { 186 bool PPB_Graphics2D_Impl::Init(int width,
187 int height,
188 bool is_always_opaque,
189 float scale) {
185 // The underlying PPB_ImageData_Impl will validate the dimensions. 190 // The underlying PPB_ImageData_Impl will validate the dimensions.
186 image_data_ = new PPB_ImageData_Impl(pp_instance()); 191 image_data_ = new PPB_ImageData_Impl(pp_instance());
187 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), 192 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(),
188 width, height, true) || 193 width, height, true) ||
189 !image_data_->Map()) { 194 !image_data_->Map()) {
190 image_data_ = NULL; 195 image_data_ = NULL;
191 return false; 196 return false;
192 } 197 }
193 is_always_opaque_ = is_always_opaque; 198 is_always_opaque_ = is_always_opaque;
199 scale_ = scale;
194 return true; 200 return true;
195 } 201 }
196 202
197 ::ppapi::thunk::PPB_Graphics2D_API* 203 ::ppapi::thunk::PPB_Graphics2D_API*
198 PPB_Graphics2D_Impl::AsPPB_Graphics2D_API() { 204 PPB_Graphics2D_Impl::AsPPB_Graphics2D_API() {
199 return this; 205 return this;
200 } 206 }
201 207
202 void PPB_Graphics2D_Impl::LastPluginRefWasDeleted() { 208 void PPB_Graphics2D_Impl::LastPluginRefWasDeleted() {
203 Resource::LastPluginRefWasDeleted(); 209 Resource::LastPluginRefWasDeleted();
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 backing_bitmap.copyTo(&image, SkBitmap::kARGB_8888_Config); 566 backing_bitmap.copyTo(&image, SkBitmap::kARGB_8888_Config);
561 else 567 else
562 image = backing_bitmap; 568 image = backing_bitmap;
563 569
564 SkPaint paint; 570 SkPaint paint;
565 if (is_always_opaque_) { 571 if (is_always_opaque_) {
566 // When we know the device is opaque, we can disable blending for slightly 572 // When we know the device is opaque, we can disable blending for slightly
567 // more optimized painting. 573 // more optimized painting.
568 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 574 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
569 } 575 }
570 canvas->drawBitmap(image, 576
571 SkIntToScalar(plugin_rect.x()), 577 SkPoint origin;
572 SkIntToScalar(plugin_rect.y()), 578 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y()));
573 &paint); 579 if (scale_ != 1.0f && scale_ > 0.0f) {
580 float inverse_scale = 1.0f / scale_;
581 origin.scale(scale_);
582 canvas->scale(inverse_scale, inverse_scale);
583 }
584 canvas->drawBitmap(image, origin.x(), origin.y(), &paint);
574 canvas->restore(); 585 canvas->restore();
575 #endif 586 #endif
576 } 587 }
577 588
578 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() { 589 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() {
579 // Move any "unpainted" callback to the painted state. See 590 // Move any "unpainted" callback to the painted state. See
580 // |unpainted_flush_callback_| in the header for more. 591 // |unpainted_flush_callback_| in the header for more.
581 if (!unpainted_flush_callback_.is_null()) { 592 if (!unpainted_flush_callback_.is_null()) {
582 DCHECK(painted_flush_callback_.is_null()); 593 DCHECK(painted_flush_callback_.is_null());
583 std::swap(painted_flush_callback_, unpainted_flush_callback_); 594 std::swap(painted_flush_callback_, unpainted_flush_callback_);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 696 }
686 697
687 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 698 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
688 return !unpainted_flush_callback_.is_null() || 699 return !unpainted_flush_callback_.is_null() ||
689 !painted_flush_callback_.is_null() || 700 !painted_flush_callback_.is_null() ||
690 offscreen_flush_pending_; 701 offscreen_flush_pending_;
691 } 702 }
692 703
693 } // namespace ppapi 704 } // namespace ppapi
694 } // namespace webkit 705 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698