diff options
author | dsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-01 23:36:31 +0000 |
---|---|---|
committer | dsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-01 23:36:31 +0000 |
commit | c883e8bd8ca75d36f2574f5772f3f09fc733711e (patch) | |
tree | 5dfd90f899a409b5128f319a9b51e8d5187a1beb /cc/resources | |
parent | 82d55f49ccb3d9b61834c2ad2640307b2824060b (diff) | |
download | chromium_src-c883e8bd8ca75d36f2574f5772f3f09fc733711e.zip chromium_src-c883e8bd8ca75d36f2574f5772f3f09fc733711e.tar.gz chromium_src-c883e8bd8ca75d36f2574f5772f3f09fc733711e.tar.bz2 |
Add ability to retrieve the width and height from a SKP file.
In trace-viewer we want to allow users to load up .skp files in the
skia_debugger.html. In order to do that we need access to the width and
height of the skp in order to get the op timings.
To that end, this CL adds a getInfo method to chrome.skiaBenchmarking to return
the width and height.
BUG=
Review URL: https://chromiumcodereview.appspot.com/23572018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources')
-rw-r--r-- | cc/resources/picture.cc | 21 | ||||
-rw-r--r-- | cc/resources/picture.h | 1 | ||||
-rw-r--r-- | cc/resources/picture_unittest.cc | 53 |
3 files changed, 75 insertions, 0 deletions
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc index 8c5d851..4927623 100644 --- a/cc/resources/picture.cc +++ b/cc/resources/picture.cc @@ -93,6 +93,27 @@ Picture::Picture(gfx::Rect layer_rect) // the picture to be recorded in Picture::Record. } +scoped_refptr<Picture> Picture::CreateFromSkpValue(const base::Value* value) { + // Decode the picture from base64. + std::string encoded; + if (!value->GetAsString(&encoded)) + return NULL; + + std::string decoded; + base::Base64Decode(encoded, &decoded); + SkMemoryStream stream(decoded.data(), decoded.size()); + + // Read the picture. This creates an empty picture on failure. + SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap); + if (skpicture == NULL) + return NULL; + + gfx::Rect layer_rect(skpicture->width(), skpicture->height()); + gfx::Rect opaque_rect(skpicture->width(), skpicture->height()); + + return make_scoped_refptr(new Picture(skpicture, layer_rect, opaque_rect)); +} + scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) { const base::DictionaryValue* value = NULL; if (!raw_value->GetAsDictionary(&value)) diff --git a/cc/resources/picture.h b/cc/resources/picture.h index 15a6c9d..90df190 100644 --- a/cc/resources/picture.h +++ b/cc/resources/picture.h @@ -45,6 +45,7 @@ class CC_EXPORT Picture static scoped_refptr<Picture> Create(gfx::Rect layer_rect); static scoped_refptr<Picture> CreateFromValue(const base::Value* value); + static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); gfx::Rect LayerRect() const { return layer_rect_; } gfx::Rect OpaqueRect() const { return opaque_rect_; } diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc index ee5e07d..aa20ebb 100644 --- a/cc/resources/picture_unittest.cc +++ b/cc/resources/picture_unittest.cc @@ -377,5 +377,58 @@ TEST(PictureTest, PixelRefIteratorOnePixelQuery) { } } } + +TEST(PictureTest, CreateFromSkpValue) { + SkGraphics::Init(); + + gfx::Rect layer_rect(100, 200); + + SkTileGridPicture::TileGridInfo tile_grid_info; + tile_grid_info.fTileInterval = SkISize::Make(100, 200); + tile_grid_info.fMargin.setEmpty(); + tile_grid_info.fOffset.setZero(); + + FakeContentLayerClient content_layer_client; + FakeRenderingStatsInstrumentation stats_instrumentation; + + scoped_ptr<base::Value> tmp; + + SkPaint red_paint; + red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); + SkPaint green_paint; + green_paint.setColor(SkColorSetARGB(255, 0, 255, 0)); + + // Invalid picture (not a dict). + tmp.reset(new base::StringValue("abc!@#$%")); + scoped_refptr<Picture> invalid_picture = + Picture::CreateFromSkpValue(tmp.get()); + EXPECT_TRUE(!invalid_picture.get()); + + // Single full-size rect picture. + content_layer_client.add_draw_rect(layer_rect, red_paint); + scoped_refptr<Picture> one_rect_picture = Picture::Create(layer_rect); + one_rect_picture->Record(&content_layer_client, + tile_grid_info, + &stats_instrumentation); + scoped_ptr<base::Value> serialized_one_rect( + one_rect_picture->AsValue()); + + const base::DictionaryValue* value = NULL; + EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); + + // Decode the picture from base64. + const base::Value* skp_value; + EXPECT_TRUE(value->Get("skp64", &skp_value)); + + // Reconstruct the picture. + scoped_refptr<Picture> one_rect_picture_check = + Picture::CreateFromSkpValue(skp_value); + EXPECT_TRUE(!!one_rect_picture_check.get()); + + EXPECT_EQ(100, one_rect_picture_check->LayerRect().width()); + EXPECT_EQ(200, one_rect_picture_check->LayerRect().height()); + EXPECT_EQ(100, one_rect_picture_check->OpaqueRect().width()); + EXPECT_EQ(200, one_rect_picture_check->OpaqueRect().height()); +} } // namespace } // namespace cc |