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

Side by Side Diff: athena/content/content_proxy.h

Issue 591693002: Creating PNG images from web content to be used by OverviewMode navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef ATHENA_CONTENT_CONTENT_PROXY_H_ 5 #ifndef ATHENA_CONTENT_CONTENT_PROXY_H_
6 #define ATHENA_CONTENT_CONTENT_PROXY_H_ 6 #define ATHENA_CONTENT_CONTENT_PROXY_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted_memory.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/image/image_skia.h" 11 #include "base/memory/weak_ptr.h"
11 12 #include "ui/gfx/image/image.h"
12 namespace aura {
13 class Window;
14 }
15 13
16 namespace views { 14 namespace views {
17 class View;
18 class WebView; 15 class WebView;
19 } 16 }
20 17
21 typedef unsigned int SkColor;
22
23 namespace athena { 18 namespace athena {
24 19
25 class Activity; 20 class Activity;
26 class AppActivity; 21 class ProxyImageData;
27 class AppActivityProxy;
28 class WebActivity;
29 22
30 // This object creates and holds proxy content which gets shown instead of the 23 // This object creates and holds proxy content which gets shown instead of the
31 // actual web content, generated from the passed |web_view|. 24 // actual web content, generated from the passed |web_view|.
32 // The created |proxy_content_| will be destroyed with the destruction of this 25 // The created |proxy_content_| will be destroyed with the destruction of this
33 // object. 26 // object.
34 // Calling EvictContent() will release the rendered content and replaces it with 27 // Calling EvictContent() will release the rendered content.
35 // a solid color to save memory. 28 // When ContentGetsDestroyed() gets called, the old view will be made visible
36 // Calling Reparent() will transfer the |proxy_content_| to an ActivityProxy, 29 // and then the link to the |web_view_| will get severed.
37 // allowing the destruction of the original activity / content.
38 class ContentProxy { 30 class ContentProxy {
39 public: 31 public:
40 // Creates the object by creating a sized down |web_view| layer and making it 32 // Creates the object by creating a sized down |web_view| layer and making it
41 // visible inside |activity|'s window. 33 // visible inside |activity|'s window.
42 ContentProxy(views::WebView* web_view, Activity* activity); 34 ContentProxy(views::WebView* web_view, Activity* activity);
43 // TODO(skuhne): Add a function to create this object from a passed PNG, so 35 // TODO(skuhne): Add a function to create this object from a passed PNG, so
44 // that we can create it from a session restore. 36 // that we can create it from a session restore.
45 37
46 // With the destruction of the object, the layer should get destroyed and the 38 // With the destruction of the object, the layer should get destroyed and the
47 // content should become visible again. 39 // content should become visible again.
48 virtual ~ContentProxy(); 40 virtual ~ContentProxy();
49 41
50 // Called when the content will get unloaded. 42 // Called when the content will get unloaded.
51 void ContentWillUnload(); 43 void ContentWillUnload();
52 44
53 // Can be called to save resources by creating a layer with a solid color 45 // Can be called to save resources by creating a layer with a solid color
54 // instead of creating a content image layer. 46 // instead of creating a content image layer.
55 // Note: Currently the GPU does create a full size texture and fills it with 47 // Note: Currently the GPU does create a full size texture and fills it with
56 // the given color - so there isn't really memory savings yet. 48 // the given color - so there isn't really memory savings yet.
57 void EvictContent(); 49 void EvictContent();
58 50
59 // Get the image of the content. If there is no image known, an empty image 51 // Get the image of the content. If there is no image known, an empty image
60 // will be returned. 52 // will be returned.
61 gfx::ImageSkia GetContentImage(); 53 scoped_ptr<gfx::Image> GetContentImage();
oshima 2014/09/22 16:10:28 ditto
Mr4D (OOO till 08-26) 2014/09/23 19:07:34 Done.
62 54
63 // Transfer the owned |proxy_content_| to the |new_parent_window|. 55 // The content is about to get destroyed by its creator.
oshima 2014/09/22 16:10:28 Called when the content is about to ... If this i
Mr4D (OOO till 08-26) 2014/09/23 19:07:34 As mentioned in another parallel CL: I always cons
64 // Once called, the |web_view_| will be made visible again and the connection
65 // to it will be removed since the old activity might go away.
66 // Note: This function should only be used by AppActivity. 56 // Note: This function should only be used by AppActivity.
67 void Reparent(aura::Window* new_parent_window); 57 void ContentGetsDestroyed();
68 58
69 private: 59 private:
70 // Make the original (web)content visible. This call should only be paired 60 // Make the original (web)content visible. This call should only be paired
71 // with HideOriginalContent. 61 // with HideOriginalContent.
72 void ShowOriginalContent(); 62 void ShowOriginalContent();
73 63
74 // Make the content invisible. This call should only be paired with 64 // Make the content invisible. This call should only be paired with
75 // MakeVisible. 65 // MakeVisible.
76 void HideOriginalContent(); 66 void HideOriginalContent();
77 67
78 // Creates proxy content from |web_view_|. If there is no |web_view_|, 68 // Creates proxy content from |web_view_|.
79 // a solid |proxy_content_| with |background_color_| will be created.
80 void CreateProxyContent(); 69 void CreateProxyContent();
81 70
82 // Creates a solid |proxy_content_| with |background_color_|. 71 // Creates an image from the current content.
83 void CreateSolidProxyContent(); 72 bool GetContentAsImage();
oshima 2014/09/22 16:10:28 CreateContentImage ?
Mr4D (OOO till 08-26) 2014/09/23 19:07:34 Done.
84 73
85 // Show the |proxy_content_| in the current |window_|. 74 // Called once the content was read back.
86 void ShowProxyContent(); 75 void ContentReadBackAsImage(bool success, const SkBitmap& bitmap);
oshima 2014/09/22 16:10:28 OnContentImage{Read/Created/..}?
Mr4D (OOO till 08-26) 2014/09/23 19:07:34 Done.
87 76
88 // Removes the |proxy_content_| from the window again. 77 // Called once the image content has been converted to PNG.
89 void HideProxyContent(); 78 void OnContentImageEncodeComplete(scoped_refptr<ProxyImageData> image);
90 79
91 // The web view which is associated with this object. It will be NULL after 80 // The web view which is associated with this object. It will be shown when
92 // the object got called with Reparent(), since the Activity which owns it 81 // ContentGetsDestroyed() gets called and then set to NULL.
oshima 2014/09/22 16:10:28 can you document ownership?
Mr4D (OOO till 08-26) 2014/09/23 19:07:34 Done.
93 // will be destroyed shortly after.
94 views::WebView* web_view_; 82 views::WebView* web_view_;
95 83
96 // The window which shows our |proxy_content_|, 84 // While we are doing our PNG encode, we keep the read back image to have
97 aura::Window* window_; 85 // something which we can pass back to the overview mode. (It would make no
86 // sense to the user to see that more recent windows get painted later than
87 // older ones).
88 gfx::Image image_;
98 89
99 // The background color to use when evicted. 90 // True if the content is visible.
100 SkColor background_color_; 91 bool content_visible_;
101 92
102 // If we have an image (e.g. from session restore) it is stored here. 93 // True if the content is loaded and needs a re-layout when it gets shown
103 gfx::ImageSkia image_; 94 // again.
104
105 // True if the content is loaded.
106 bool content_loaded_; 95 bool content_loaded_;
107 96
108 // The content representation which which will be presented to the user. It 97 // The PNG image data.
109 // will either contain a shrunken down image of the |web_view| content or a 98 scoped_refptr<base::RefCountedBytes> png_data_;
110 // solid |background_color_|. 99
111 scoped_ptr<views::View> proxy_content_; 100 // Creating an encoded image from the content will be asynchronous. Use a
101 // weakptr for the callback to make sure that the read back / encoding image
102 // completion callback does not trigger on a destroyed ContentProxy.
103 base::WeakPtrFactory<ContentProxy> proxy_content_to_image_factory_;
112 104
113 DISALLOW_COPY_AND_ASSIGN(ContentProxy); 105 DISALLOW_COPY_AND_ASSIGN(ContentProxy);
114 }; 106 };
115 107
116 } // namespace athena 108 } // namespace athena
117 109
118 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_ 110 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698