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

Side by Side Diff: content/renderer/pepper/pepper_graphics_2d_host.cc

Issue 61813003: Allow PPB_ImageData_Impl to be created in a way that is compatible with unittests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 "content/renderer/pepper/pepper_graphics_2d_host.h" 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 int scroll_dx, scroll_dy; 159 int scroll_dx, scroll_dy;
160 160
161 // Valid when type == REPLACE. 161 // Valid when type == REPLACE.
162 scoped_refptr<PPB_ImageData_Impl> replace_image; 162 scoped_refptr<PPB_ImageData_Impl> replace_image;
163 163
164 // Valid when type == SET_OFFSET. 164 // Valid when type == SET_OFFSET.
165 gfx::Point offset; 165 gfx::Point offset;
166 }; 166 };
167 167
168 // static 168 // static
169 PepperGraphics2DHost* PepperGraphics2DHost::Create(RendererPpapiHost* host, 169 PepperGraphics2DHost* PepperGraphics2DHost::Create(
170 PP_Instance instance, 170 RendererPpapiHost* host,
171 PP_Resource resource, 171 PP_Instance instance,
172 const PP_Size& size, 172 PP_Resource resource,
173 PP_Bool is_always_opaque) { 173 const PP_Size& size,
174 PP_Bool is_always_opaque,
175 scoped_refptr<PPB_ImageData_Impl> backing_store) {
174 PepperGraphics2DHost* resource_host = 176 PepperGraphics2DHost* resource_host =
175 new PepperGraphics2DHost(host, instance, resource); 177 new PepperGraphics2DHost(host, instance, resource);
176 if (!resource_host->Init(size.width, size.height, 178 if (!resource_host->Init(size.width, size.height,
177 PP_ToBool(is_always_opaque))) { 179 PP_ToBool(is_always_opaque),
180 backing_store)) {
178 delete resource_host; 181 delete resource_host;
179 return NULL; 182 return NULL;
180 } 183 }
181 return resource_host; 184 return resource_host;
182 } 185 }
183 186
184 PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host, 187 PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host,
185 PP_Instance instance, 188 PP_Instance instance,
186 PP_Resource resource) 189 PP_Resource resource)
187 : ResourceHost(host->GetPpapiHost(), instance, resource), 190 : ResourceHost(host->GetPpapiHost(), instance, resource),
188 renderer_ppapi_host_(host), 191 renderer_ppapi_host_(host),
189 bound_instance_(NULL), 192 bound_instance_(NULL),
190 need_flush_ack_(false), 193 need_flush_ack_(false),
191 offscreen_flush_pending_(false), 194 offscreen_flush_pending_(false),
192 is_always_opaque_(false), 195 is_always_opaque_(false),
193 scale_(1.0f), 196 scale_(1.0f),
194 is_running_in_process_(host->IsRunningInProcess()), 197 is_running_in_process_(host->IsRunningInProcess()),
195 texture_mailbox_modified_(true) {} 198 texture_mailbox_modified_(true) {}
196 199
197 PepperGraphics2DHost::~PepperGraphics2DHost() { 200 PepperGraphics2DHost::~PepperGraphics2DHost() {
198 // Unbind from the instance when destroyed if we're still bound. 201 // Unbind from the instance when destroyed if we're still bound.
199 if (bound_instance_) 202 if (bound_instance_)
200 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0); 203 bound_instance_->BindGraphics(bound_instance_->pp_instance(), 0);
201 } 204 }
202 205
203 bool PepperGraphics2DHost::Init(int width, int height, bool is_always_opaque) { 206 bool PepperGraphics2DHost::Init(
207 int width,
208 int height,
209 bool is_always_opaque,
210 scoped_refptr<PPB_ImageData_Impl> backing_store) {
204 // The underlying PPB_ImageData_Impl will validate the dimensions. 211 // The underlying PPB_ImageData_Impl will validate the dimensions.
205 image_data_ = new PPB_ImageData_Impl(pp_instance(), 212 image_data_ = backing_store;
206 PPB_ImageData_Impl::PLATFORM);
207 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), 213 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(),
208 width, height, true) || 214 width, height, true) ||
209 !image_data_->Map()) { 215 !image_data_->Map()) {
210 image_data_ = NULL; 216 image_data_ = NULL;
211 return false; 217 return false;
212 } 218 }
213 is_always_opaque_ = is_always_opaque; 219 is_always_opaque_ = is_always_opaque;
214 scale_ = 1.0f; 220 scale_ = 1.0f;
215 return true; 221 return true;
216 } 222 }
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 gfx::Point inverse_scaled_point = 840 gfx::Point inverse_scaled_point =
835 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale)); 841 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale));
836 if (original_delta != inverse_scaled_point) 842 if (original_delta != inverse_scaled_point)
837 return false; 843 return false;
838 } 844 }
839 845
840 return true; 846 return true;
841 } 847 }
842 848
843 } // namespace content 849 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698