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

Side by Side Diff: ppapi/tests/test_graphics_2d.cc

Issue 10823378: Cache image data objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try Created 8 years, 4 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
« no previous file with comments | « ppapi/tests/test_graphics_2d.h ('k') | ppapi/thunk/ppb_graphics_2d_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ppapi/tests/test_graphics_2d.h" 5 #include "ppapi/tests/test_graphics_2d.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <set>
11
10 #include "ppapi/c/dev/ppb_testing_dev.h" 12 #include "ppapi/c/dev/ppb_testing_dev.h"
11 #include "ppapi/c/pp_errors.h" 13 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/c/ppb_graphics_2d.h" 14 #include "ppapi/c/ppb_graphics_2d.h"
13 #include "ppapi/cpp/completion_callback.h" 15 #include "ppapi/cpp/completion_callback.h"
14 #include "ppapi/cpp/dev/graphics_2d_dev.h" 16 #include "ppapi/cpp/dev/graphics_2d_dev.h"
15 #include "ppapi/cpp/graphics_2d.h" 17 #include "ppapi/cpp/graphics_2d.h"
16 #include "ppapi/cpp/image_data.h" 18 #include "ppapi/cpp/image_data.h"
17 #include "ppapi/cpp/instance.h" 19 #include "ppapi/cpp/instance.h"
18 #include "ppapi/cpp/module.h" 20 #include "ppapi/cpp/module.h"
19 #include "ppapi/cpp/rect.h" 21 #include "ppapi/cpp/rect.h"
(...skipping 26 matching lines...) Expand all
46 RUN_TEST(InvalidResource, filter); 48 RUN_TEST(InvalidResource, filter);
47 RUN_TEST(InvalidSize, filter); 49 RUN_TEST(InvalidSize, filter);
48 RUN_TEST(Humongous, filter); 50 RUN_TEST(Humongous, filter);
49 RUN_TEST(InitToZero, filter); 51 RUN_TEST(InitToZero, filter);
50 RUN_TEST(Describe, filter); 52 RUN_TEST(Describe, filter);
51 RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter); 53 RUN_TEST_FORCEASYNC_AND_NOT(Paint, filter);
52 RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter); 54 RUN_TEST_FORCEASYNC_AND_NOT(Scroll, filter);
53 RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter); 55 RUN_TEST_FORCEASYNC_AND_NOT(Replace, filter);
54 RUN_TEST_FORCEASYNC_AND_NOT(Flush, filter); 56 RUN_TEST_FORCEASYNC_AND_NOT(Flush, filter);
55 RUN_TEST(Dev, filter); 57 RUN_TEST(Dev, filter);
58 RUN_TEST(ReplaceContentsCaching, filter);
56 } 59 }
57 60
58 void TestGraphics2D::QuitMessageLoop() { 61 void TestGraphics2D::QuitMessageLoop() {
59 testing_interface_->QuitMessageLoop(instance_->pp_instance()); 62 testing_interface_->QuitMessageLoop(instance_->pp_instance());
60 } 63 }
61 64
62 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc, 65 bool TestGraphics2D::ReadImageData(const pp::Graphics2D& dc,
63 pp::ImageData* image, 66 pp::ImageData* image,
64 const pp::Point& top_left) const { 67 const pp::Point& top_left) const {
65 return PP_ToBool(testing_interface_->ReadImageData( 68 return PP_ToBool(testing_interface_->ReadImageData(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 uint32_t square_color) const { 167 uint32_t square_color) const {
165 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 168 pp::ImageData readback(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
166 dc.size(), false); 169 dc.size(), false);
167 if (readback.is_null()) 170 if (readback.is_null())
168 return false; 171 return false;
169 if (!ReadImageData(dc, &readback, pp::Point(0, 0))) 172 if (!ReadImageData(dc, &readback, pp::Point(0, 0)))
170 return false; 173 return false;
171 return IsSquareInImage(readback, background_color, square, square_color); 174 return IsSquareInImage(readback, background_color, square, square_color);
172 } 175 }
173 176
177
178 PP_Resource TestGraphics2D::ReplaceContentsAndReturnID(
179 pp::Graphics2D* dc,
180 const pp::Size& size) {
181 pp::ImageData image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true);
182
183 PP_Resource id = image.pp_resource();
184
185 dc->ReplaceContents(&image);
186 if (!FlushAndWaitForDone(dc))
187 return 0;
188
189 return id;
190 }
191
174 // Test all the functions with an invalid handle. Most of these just check for 192 // Test all the functions with an invalid handle. Most of these just check for
175 // a crash since the browser don't return a value. 193 // a crash since the browser don't return a value.
176 std::string TestGraphics2D::TestInvalidResource() { 194 std::string TestGraphics2D::TestInvalidResource() {
177 pp::Graphics2D null_context; 195 pp::Graphics2D null_context;
178 pp::ImageData image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 196 pp::ImageData image(instance_, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
179 pp::Size(16, 16), true); 197 pp::Size(16, 16), true);
180 198
181 // Describe. 199 // Describe.
182 PP_Size size; 200 PP_Size size;
183 PP_Bool opaque; 201 PP_Bool opaque;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 PP_Bool is_always_opaque = PP_FALSE; 680 PP_Bool is_always_opaque = PP_FALSE;
663 if (!graphics_2d_interface_->Describe(dc_dev.pp_resource(), &size, 681 if (!graphics_2d_interface_->Describe(dc_dev.pp_resource(), &size,
664 &is_always_opaque)) 682 &is_always_opaque))
665 return "Describe failed"; 683 return "Describe failed";
666 if (size.width != w || size.height != h || 684 if (size.width != w || size.height != h ||
667 is_always_opaque != PP_FromBool(false)) 685 is_always_opaque != PP_FromBool(false))
668 return "Mismatch of data."; 686 return "Mismatch of data.";
669 687
670 PASS(); 688 PASS();
671 } 689 }
690
691 // This test makes sure that the out-of-process image data caching works as
692 // expected. Doing ReplaceContents quickly should re-use the image data from
693 // older ones.
694 std::string TestGraphics2D::TestReplaceContentsCaching() {
695 // The cache is only active when running in the proxy, so skip it otherwise.
696 if (!testing_interface_->IsOutOfProcess())
697 PASS();
698
699 // Here we test resource IDs as a way to determine if the resource is being
700 // cached and re-used. This is non-optimal since it's entirely possible
701 // (and maybe better) for the proxy to return new resource IDs for the
702 // re-used objects. Howevever, our current implementation does this so it is
703 // an easy thing to check for.
704 //
705 // You could check for the shared memory pointers getting re-used, but the
706 // OS is very likely to use the same memory location for a newly-mapped image
707 // if one was deleted, meaning that it could pass even if the cache is broken.
708 // This would then require that we add some address-re-use-preventing code
709 // which would be tricky.
710 std::set<PP_Resource> resources;
711
712 pp::Size size(16, 16);
713 pp::Graphics2D dc(instance_, size, false);
714
715 // Do two replace contentses, adding the old resource IDs to our map.
716 PP_Resource imageres = ReplaceContentsAndReturnID(&dc, size);
717 ASSERT_TRUE(imageres);
718 resources.insert(imageres);
719 imageres = ReplaceContentsAndReturnID(&dc, size);
720 ASSERT_TRUE(imageres);
721 resources.insert(imageres);
722
723 // Now doing more replace contents should re-use older IDs if the cache is
724 // working.
725 imageres = ReplaceContentsAndReturnID(&dc, size);
726 ASSERT_TRUE(resources.find(imageres) != resources.end());
727 imageres = ReplaceContentsAndReturnID(&dc, size);
728 ASSERT_TRUE(resources.find(imageres) != resources.end());
729
730 PASS();
731 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_graphics_2d.h ('k') | ppapi/thunk/ppb_graphics_2d_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698